/* ==========================================
   IRONHAVEN - STYLE.CSS OTTIMIZZATO
   Versione pulita e organizzata
   ========================================== */

/* === RESET & BASE === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* CRITICAL FIX: Assicura che non ci siano overlay fantasma */
body::before,
body::after {
    content: none !important;
}

/* Nascondi tutti i modal backdrop per default */
.modal:not(.active),
.modal-backdrop:not(.active),
.ih-modal-backdrop:not(.active) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

main {
    max-width: calc(100vw - 20px);
    margin: 0 auto;
    padding: 10px;
    position: relative;
    z-index: 1;
    background: var(--background-color);
    min-height: calc(100vh - 200px);
}

/* === HEADER === */
header {
    background-color: var(--primary-color);
    color: white;
    padding: var(--spacing-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.logo {
    display: flex;
    align-items: center;
}

.logo a {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: all var(--transition-normal);
}

.logo a:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.logo img {
    height: 50px;
    width: auto;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
    transition: all var(--transition-normal);
}

.logo a:hover img {
    filter: drop-shadow(3px 3px 6px rgba(0, 0, 0, 0.4));
    transform: scale(1.05);
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* === NAVIGATION === */
nav ul {
    display: flex;
    list-style: none;
}

nav ul li {
    margin-left: var(--spacing-lg);
}

nav ul li a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-normal);
}

nav ul li a:hover {
    color: var(--primary-light);
}

nav a.active {
    background-color: rgba(255, 255, 255, 0.1);
    border-bottom: 2px solid #4CAF50;
}

/* Icone navigazione */
nav ul li a img {
    height: 90px;
    width: auto;
    vertical-align: middle;
    margin-right: 5px;
}

/* Vecchio stile rimosso - ora usa .user-welcome nel logo */
.user-info {
    display: none;
}

/* Benvenuto utente accanto al logo */
.user-welcome {
    margin-left: 20px;
    padding-left: 20px;
    border-left: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 400;
    white-space: nowrap;
}

/* === FOOTER === */
footer {
    background-color: var(--primary-dark);
    color: white;
    text-align: center;
    padding: var(--spacing-md);
    margin-top: var(--spacing-xl);
}

/* === BUTTONS === */
.btn {
    display: inline-block;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--secondary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    transition: background-color var(--transition-normal);
}

.btn:hover {
    background-color: var(--secondary-dark);
}

.btn.primary {
    background-color: var(--primary-color);
}

.btn.primary:hover {
    background-color: var(--primary-dark);
}

.btn:disabled {
    background-color: #999;
    cursor: not-allowed;
}

/* === FORMS === */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: var(--spacing-sm);
    border: 1px solid #ccc;
    border-radius: var(--radius-sm);
    font-size: 1rem;
}

.error-message {
    color: var(--error-color);
    margin-top: var(--spacing-sm);
    display: none;
}

/* === MODALS === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    max-width: 550px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: var(--spacing-md);
    font-size: 1.4rem;
    color: var(--primary-color);
}

.close-modal {
    float: right;
    font-size: 1.3rem;
    cursor: pointer;
    color: #777;
    margin: calc(var(--spacing-sm) * -1) calc(var(--spacing-sm) * -1) 0 0;
}

.close-modal:hover {
    color: var(--primary-color);
}

/* === NOTIFICATIONS === */
.notifications-container {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 300px;
    z-index: 1000;
}

.notification {
    background-color: white;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    animation: fadeIn var(--transition-normal);
}

.notification.error {
    border-left: 4px solid var(--error-color);
}

.notification.success {
    border-left: 4px solid var(--success-color);
}

.notification.info {
    border-left: 4px solid var(--info-color);
}

.notification.warning {
    border-left: 4px solid var(--warning-color);
}

.notification.fade-out {
    animation: fadeOut 0.5s;
}

/* === AUTHENTICATION === */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.auth-box {
    background-color: white;
    padding: var(--spacing-xl);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    width: 400px;
}

.tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: var(--spacing-lg);
}

.tab {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-normal);
}

.tab.active {
    border-bottom: 2px solid var(--primary-color);
    color: var(--primary-color);
    font-weight: bold;
}

.tab-content.hidden {
    display: none;
}

.auth-form h2 {
    margin-bottom: var(--spacing-lg);
    text-align: center;
    color: var(--primary-color);
}

/* === GAME CONTAINER === */
.game-container {
    background-color: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-lg);
    min-height: 100vh;
    overflow: visible;
}

/* === RESOURCE BAR === */
.resource-bar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: linear-gradient(135deg, #d4af37 0%, #f4e4bc 50%, #d4af37 100%);
    color: #8b4513;
    padding: 8px 20px;
    border-radius: 25px;
    margin-bottom: var(--spacing-lg);
    width: 50%;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
    border: 2px solid rgba(139, 69, 19, 0.2);
    position: relative;
    overflow: visible;
    z-index: 100;
}

.resource-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

.resource {
    display: flex;
    align-items: center;
    margin-right: 25px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 15px;
    border: 1px solid rgba(139, 69, 19, 0.1);
    font-weight: 600;
    font-size: 14px;
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: visible;
}

.resource:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.resource:last-child {
    margin-right: 0;
}

.resource img {
    width: 28px;
    height: 28px;
    margin-right: 8px;
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.2));
}

.resource-value {
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.3);
    min-width: 60px;
}

/* === EFFETTO LAMPEGGIANTE RISORSE AL LIMITE === */
@keyframes resourcePulse {
    0%, 100% {
        box-shadow: 0 0 5px rgba(255, 68, 68, 0.4);
        border-color: rgba(255, 68, 68, 0.5);
    }
    50% {
        box-shadow: 0 0 15px rgba(255, 68, 68, 0.8), 0 0 25px rgba(255, 68, 68, 0.4);
        border-color: rgba(255, 68, 68, 0.9);
    }
}

@keyframes resourceWarning {
    0%, 100% {
        box-shadow: 0 0 5px rgba(255, 152, 0, 0.3);
        border-color: rgba(255, 152, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 12px rgba(255, 152, 0, 0.6), 0 0 20px rgba(255, 152, 0, 0.3);
        border-color: rgba(255, 152, 0, 0.8);
    }
}

/* Risorsa al limite massimo (>=95%) - lampeggio rosso intenso */
.resource.at-capacity {
    animation: resourcePulse 1s ease-in-out infinite;
    background: rgba(255, 68, 68, 0.25) !important;
    border: 2px solid rgba(255, 68, 68, 0.6) !important;
}

.resource.at-capacity .resource-value {
    color: #ff4444 !important;
    font-weight: bold;
}

.resource.at-capacity img {
    filter: drop-shadow(0 0 4px rgba(255, 68, 68, 0.8));
}

/* Risorsa quasi al limite (>=80%) - avviso arancione */
.resource.near-capacity {
    animation: resourceWarning 1.5s ease-in-out infinite;
    background: rgba(255, 152, 0, 0.2) !important;
    border: 2px solid rgba(255, 152, 0, 0.5) !important;
}

.resource.near-capacity .resource-value {
    color: #ff9800 !important;
    font-weight: bold;
}

.resource.near-capacity img {
    filter: drop-shadow(0 0 3px rgba(255, 152, 0, 0.6));
}

/* Indicatori freccia per trend risorse */
.resource-indicator {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    font-size: 14px;
    font-weight: bold;
    position: relative;
}

.resource-indicator.positive {
    color: #2e7d32;
}

.resource-indicator.negative {
    color: #c62828;
}

.resource-indicator.neutral {
    color: #666;
}

.resource-indicator::before {
    content: '';
    width: 0;
    height: 0;
    margin-right: 4px;
    transition: all 0.3s ease;
}

.resource-indicator.positive::before {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #2e7d32;
}

.resource-indicator.negative::before {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #c62828;
}

.resource-indicator.neutral::before {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 3px solid #666;
    border-bottom: 3px solid #666;
}

/* Tooltip risorse - SFONDO OPACO SOLIDO */
.resource-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1510 !important;
    background-color: #1a1510 !important;
    color: white;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
    z-index: 10000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    border: 2px solid #5a4a3a;
    min-width: 200px;
    max-width: 280px;
    white-space: normal;
    pointer-events: none;
    backdrop-filter: none !important;
}

.resource:hover .resource-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-3px);
}

.resource-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: #5a4a3a;
}

.tooltip-header {
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 3px;
    font-size: 13px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin: 3px 0;
    font-size: 11px;
}

.tooltip-row.production {
    color: #4caf50;
}

.tooltip-row.consumption {
    color: #f44336;
}

.tooltip-row.net {
    font-weight: bold;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 3px;
    margin-top: 4px;
}

.tooltip-row.net.positive {
    color: #4caf50;
}

.tooltip-row.net.negative {
    color: #f44336;
}

.tooltip-row.net.neutral {
    color: #ffd700;
}

.tooltip-current {
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    text-align: center;
    margin-bottom: 5px;
}

/* === SETTLEMENT INFO === */
.settlement-info {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
    gap: 8px;
}

.settlement-header-row {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

/* Colonna sinistra: Nome + Widgets */
.settlement-left-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 0 0 auto;
}

/* Link cliccabile per mappa mondo */
.settlement-title-link {
    text-decoration: none;
    color: inherit;
    transition: all 0.3s ease;
}

.settlement-title-link:hover {
    transform: translateX(3px);
}

.settlement-title-link:hover .settlement-title-block {
    background: rgba(139, 89, 39, 0.1);
    border-radius: 8px;
}

.settlement-title-block {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    padding: 5px 10px 5px 0;
    transition: all 0.3s ease;
}

/* Icona mappa accanto al nome villaggio */
.settlement-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2));
}

.settlement-info h2 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.3rem;
}

/* Coordinate accanto al nome */
.settlement-coords {
    font-size: 14px;
    font-weight: 600;
    color: #667;
    background: rgba(102, 126, 234, 0.15);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.settlement-title-link:hover .settlement-coords {
    background: rgba(102, 126, 234, 0.25);
    color: #445;
}

/* Riga con i due widget affiancati */
.settlement-widgets-row {
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: stretch;
}

/* Widget bonus e popolazione con stessa altezza */
.settlement-widgets-row .player-bonuses-widget,
.settlement-widgets-row .population-compact-widget {
    flex: 0 0 auto;
}

.settlement-location {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.coordinates {
    background-color: rgba(139, 89, 39, 0.1);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(139, 89, 39, 0.2);
    font-size: 0.9rem;
    color: var(--primary-dark);
    font-weight: 500;
}
/* Stats popolazione e soddisfazione - NASCOSTO (già nel widget compatto) */
.settlement-stats {
    display: none; /* Rimosso - info già nel widget popolazione */
}

.stat {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
}

.stat img {
    width: 24px;
    height: 24px;
    margin-right: var(--spacing-sm);
    object-fit: contain;
}

/* === POPULATION WIDGET === */
.population-compact-widget {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    min-width: 320px;
    backdrop-filter: blur(10px);
}

.pop-compact-header {
    display: none; /* Nascosto - coordinate ora nel titolo */
}

.pop-compact-coordinates {
    display: none;
}

.pop-compact-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.pop-compact-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pop-icon {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.pop-compact-data {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pop-compact-label {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pop-compact-value {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.pop-compact-divider {
    width: 1px;
    height: 35px;
    background: rgba(255, 255, 255, 0.2);
}

.pop-compact-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.pop-compact-consumption {
    display: flex;
    gap: 12px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
}

/* === GAME CONTENT LAYOUT === */
.game-content {
    display: flex;
    gap: var(--spacing-lg);
    align-items: stretch;
    min-height: 700px;
}

.settlement-view {
    flex: 3;
    height: 700px;
    min-height: 700px;
}

.settlement-view .isometric-map-embedded {
    width: 100%;
    height: 100%;
}

.game-sidebar {
    flex: 1;
}

/* === BUILDINGS === */
.buildings-list {
    margin-bottom: var(--spacing-xl);
}

.buildings-list h3 {
    margin-bottom: var(--spacing-md);
    color: var(--primary-color);
    font-size: 1.1rem;
}

.buildings-container {
    max-height: 400px;
    overflow-y: auto;
    background-color: #f5f5f5;
    border-radius: var(--radius-sm);
}

.building-item {
    display: flex;
    padding: 0.6rem;
    border-bottom: 1px solid #ddd;
    background-color: white;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.building-item:hover {
    background-color: #f9f9f9;
}

.building-item:last-child {
    border-bottom: none;
}

.building-item .building-icon {
    width: var(--building-icon-medium);
    height: var(--building-icon-medium);
    margin: 0 calc(var(--spacing-sm) + 0.25rem) 0 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.building-item .building-info {
    flex: 1;
}

.building-item h4 {
    margin: 0 0 0.1rem 0;
    color: var(--primary-dark);
    font-size: 1rem;
}

.building-item p {
    font-size: 0.85rem;
    color: #666;
    margin: 0;
    line-height: 1.3;
}

/* === QUICK ACTIONS === */
.quick-actions {
    background-color: #f5f5f5;
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
}

.quick-actions h3 {
    margin-bottom: var(--spacing-md);
    color: var(--primary-color);
    font-size: 1.1rem;
}

.quick-actions button {
    width: 100%;
    margin-bottom: var(--spacing-sm);
}

.quick-actions .btn-map {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    font-weight: bold;
    transition: all 0.3s ease;
    border: none;
}

.quick-actions .btn-map:hover {
    background: linear-gradient(135deg, #5dade2 0%, #3498db 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

/* === UTILITIES === */
.hidden {
    display: none !important;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .resource-bar {
        width: 100%;
        padding: 6px 15px;
        justify-content: space-between;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .resource {
        margin-right: 15px;
        padding: 3px 8px;
        min-width: fit-content;
    }
    
    .resource img {
        width: 24px;
        height: 24px;
    }
    
    .resource-indicator {
        margin-left: 6px;
        font-size: 12px;
    }
    
    .game-content {
        flex-direction: column;
        min-height: auto;
    }
    
    .settlement-view {
        width: 100%;
        order: 1;
    }
    
    .game-sidebar {
        width: 100%;
        order: 2;
    }
    
    .settlement-header-row {
        flex-direction: column;
    }
    
    .population-compact-widget {
        min-width: 100%;
        width: 100%;
    }
    
    .pop-compact-row {
        flex-wrap: wrap;
    }
    
    nav ul {
        flex-direction: column;
        align-items: center;
    }
    
    nav ul li {
        margin: var(--spacing-sm) 0;
    }
}

@media (max-width: 480px) {
    main {
        padding: var(--spacing-md);
    }
    
    .auth-box {
        width: 95%;
    }
    
    header {
        flex-direction: column;
        text-align: center;
    }
    
    .resource-bar {
        padding: 4px 10px;
    }
    
    .resource {
        margin-right: 10px;
        padding: 2px 6px;
    }
    
    .resource img {
        width: 22px;
        height: 22px;
        margin-right: 6px;
    }
    
    .resource-value {
        font-size: 12px;
        min-width: 40px;
    }
}
