/**
 * EXULO Mobile - Header CSS V5
 * Layout: Logo (links) | Ressourcen (mitte) | WT/KT + Stats + Glocke (rechts)
 */

/* ============================================
   MOBILE HEADER V5
   ============================================ */
.mobile-header-v2 {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height, 56px);
    min-height: 56px;
    max-height: 56px;
    padding-top: var(--safe-area-top, 0);
    /* Blue Theme Background */
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(30, 41, 59, 0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), 0 0 20px rgba(59, 130, 246, 0.1);
    z-index: var(--z-header, 1000);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-sm, 8px);
    gap: 8px;
    overflow: visible; /* Allow tooltips to extend beyond header */
    box-sizing: border-box;
}

/* ============================================
   LOGO (Links)
   ============================================ */
.header-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    max-height: 100%;
    overflow: hidden;
}

.header-logo .logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.header-logo .logo-img {
    height: 40px;
    max-height: 40px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.4));
    display: block;
}

/* ============================================
   RESSOURCEN - 2x2 Grid mit Mini-Cards (linksbündig)
   Responsive: DARF schrumpfen damit rechts Platz bleibt
   ============================================ */
.header-resources-center {
    flex: 1 1 auto;           /* grow, shrink, basis */
    min-width: 0;             /* Erlaubt Schrumpfen unter Content-Size */
    max-width: 200px;         /* Begrenzt maximale Breite */
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 2px 4px;
    justify-content: start;
    margin: 0;
    margin-left: 6px;
    overflow: visible;        /* Tooltip muss sichtbar bleiben */
}

/* Mini-Card Styling (wie Desktop minimal-resource-card) */
.res-card {
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    justify-content: flex-start;
    /* Blue Mini-Card Frame */
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 5px;
    padding: 1px 4px;
    transition: all 0.2s ease;
    cursor: pointer;
    min-width: 0;             /* Responsive: Kann schrumpfen */
    position: relative;
    overflow: visible;        /* WICHTIG: Tooltip muss sichtbar sein! */
}

.res-card:hover,
.res-card:active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
}

.res-card.showing-rate {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(96, 165, 250, 0.6);
}

.res-icon {
    font-size: 10px;
    line-height: 1;
    flex-shrink: 0;
}

.res-value {
    font-family: 'Courier New', monospace;
    font-size: clamp(8px, 2.5vw, 10px);  /* Responsive: Skaliert mit Viewport */
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    text-align: left;
    min-width: 0;             /* Responsive: Kann schrumpfen */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Rate Tooltip (appears on tap) - opens DOWNWARD */
.res-rate {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(96, 165, 250, 0.5);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 10px;
    color: #93c5fd;
    white-space: nowrap;
    z-index: 1001;
    margin-top: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.res-rate::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: rgba(96, 165, 250, 0.5);
}

.res-card.showing-rate .res-rate {
    display: block;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Ressourcen-Farben */
.res-card.metal .res-value { color: var(--color-metal, #b0b0b0); }
.res-card.crystal .res-value { color: var(--color-crystal, #4fc3f7); }
.res-card.uran .res-value { color: var(--color-uranium, #66bb6a); }
.res-card.sternenstaub .res-value { color: var(--color-stardust, #ffd54f); }

/* Legacy Support */
.res-cell {
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    justify-content: center;
}
.res-cell.metal .res-value { color: var(--color-metal, #b0b0b0); }
.res-cell.crystal .res-value { color: var(--color-crystal, #4fc3f7); }
.res-cell.uran .res-value { color: var(--color-uranium, #66bb6a); }
.res-cell.sternenstaub .res-value { color: var(--color-stardust, #ffd54f); }

/* ============================================
   RECHTE SEITE (WT/KT + Stats + Glocke)
   ============================================ */
.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ============================================
   WT/KT UHREN - Mini-Card Style
   ============================================ */
.header-tick-clocks {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.tick-display {
    display: flex;
    align-items: center;
    gap: 4px;
    /* Blue Mini-Card Frame (wie Ressourcen) */
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 5px;
    padding: 2px 6px;
    transition: all 0.2s ease;
}

.tick-display:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
}

.tick-label {
    font-family: 'Courier New', monospace;
    font-size: 9px;
    font-weight: var(--font-weight-bold);
    color: var(--text-secondary);
    width: 16px;
}

.tick-display.wt .tick-label {
    color: var(--color-primary, #00ffff);
}

.tick-display.kt .tick-label {
    color: #ff6b6b;
}

.tick-time {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    min-width: 55px;
}

/* ============================================
   HEADER BUTTONS (Stats + Notifications)
   ============================================ */
.header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.header-btn {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md, 8px);
    color: var(--text-secondary, rgba(255,255,255,0.7));
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.95);
}

.header-btn .badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 14px;
    height: 14px;
    font-size: 9px;
    padding: 0 3px;
    background: #f44336;
    color: white;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   BADGE PULSE ANIMATION
   ============================================ */
@keyframes badge-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(244, 67, 54, 0);
    }
}

.header-btn .badge.pulse {
    animation: badge-pulse 2s infinite;
}

/* ============================================
   STATS POPUP
   ============================================ */
.stats-popup-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.stats-popup-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.stats-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: calc(100% - 32px);
    max-width: 360px;
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

.stats-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.stats-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
}

.stats-popup-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.stats-popup-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted, rgba(255,255,255,0.5));
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.stats-popup-close:active {
    background: rgba(255, 255, 255, 0.1);
}

.stats-popup-content {
    padding: 16px 20px 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

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

.stat-value {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.stat-value.highlight {
    color: var(--color-primary, #00d4ff);
}

.stat-value.positive {
    color: #4caf50;
}

.stat-value.negative {
    color: #f44336;
}

.stat-value.credits {
    color: #ffd700;
}

/* ============================================
   LEGACY MOBILE HEADER (für Rückwärtskompatibilität)
   ============================================ */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    padding-top: var(--safe-area-top);
    background: var(--bg-header);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: var(--z-header);
    display: flex;
    align-items: center;
}

.mobile-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 0 var(--spacing-sm);
}

/* ============================================
   SCROLL BEHAVIOR
   ============================================ */
.mobile-header.scrolled,
.mobile-header-v2.scrolled {
    box-shadow: var(--shadow-md);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   Priority: Glocke > Stats > WT/KT > Ressourcen > Logo
   ============================================ */

/* Sehr kleine Bildschirme (< 360px, z.B. iPhone SE) */
@media (max-width: 359px) {
    .header-resources-center {
        gap: 1px 2px;
        max-width: 140px;
    }

    .res-icon {
        font-size: 9px;
    }

    .res-value {
        font-size: 8px;
    }

    .tick-time {
        font-size: 8px;
        min-width: 44px;
    }

    .tick-label {
        font-size: 8px;
        width: 14px;
    }

    .header-logo .logo-img {
        height: 28px;
        max-height: 28px;
    }

    .header-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .tick-display {
        padding: 1px 4px;
    }
}

/* Kleine Bildschirme (360px - 412px, z.B. S25 Ultra, Pixel) */
@media (min-width: 360px) and (max-width: 412px) {
    .mobile-header-v2 {
        padding: 0 4px;
        gap: 4px;
    }

    .header-logo .logo-img {
        height: 30px;
        max-height: 30px;
        max-width: 50px;
    }

    .header-resources-center {
        gap: 1px 2px;
        max-width: 120px;  /* Aggressiv kleiner! */
    }

    .res-card {
        padding: 1px 2px;
    }

    .res-icon {
        font-size: 8px;
    }

    .res-value {
        font-size: 8px;
        max-width: 50px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tick-time {
        font-size: 8px;
        min-width: 44px;
    }

    .tick-label {
        font-size: 7px;
        width: 14px;
    }

    .tick-display {
        padding: 1px 3px;
    }

    .header-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* Normale Bildschirme (> 412px) */
@media (min-width: 413px) {
    .header-resources-center {
        gap: 2px 8px;
        max-width: 200px;
    }

    .res-value {
        font-size: 10px;
    }

    .tick-time {
        font-size: 10px;
        min-width: 55px;
    }

    .header-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
}

/* Große Bildschirme (> 480px, z.B. Tablets) */
@media (min-width: 481px) {
    .header-resources-center {
        gap: 2px 12px;
        max-width: 220px;
    }

    .res-value {
        font-size: 11px;
    }

    .tick-time {
        font-size: 11px;
        min-width: 60px;
    }

    .header-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

/* ============================================
   ATTACK WARNING ANIMATION
   Header pulsiert subtil rot bei eingehendem Angriff
   ============================================ */
@keyframes header-attack-pulse {
    0%, 100% {
        background: var(--bg-header, rgba(26, 26, 46, 0.95));
    }
    50% {
        background: rgba(60, 20, 25, 0.95); /* Subtiles Dunkelrot */
    }
}

.mobile-header-v2.under-attack {
    animation: header-attack-pulse 4s ease-in-out infinite;
}

/* ============================================
   GAME FREEZE/VICTORY BANNER
   Zeigt Spielpause oder Rundenende (1:1 wie Desktop)
   ============================================ */
.mobile-freeze-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10001;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    padding: 10px 16px;
    text-align: center;
    font-weight: bold;
    font-size: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    line-height: 1.4;
}

.mobile-freeze-banner.victory {
    background: linear-gradient(135deg, #ffd700, #ff8c00, #ffd700);
    background-size: 200% 200%;
    animation: victory-shimmer 3s ease infinite;
    color: #1a1a1a;
    font-size: 13px;
    text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

@keyframes victory-shimmer {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.mobile-freeze-banner .winner-name {
    font-size: 15px;
    font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.mobile-freeze-banner .winner-sector {
    font-size: 11px;
    opacity: 0.9;
    margin-left: 4px;
}

.mobile-freeze-banner .victory-type {
    display: inline-block;
    background: rgba(0,0,0,0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    margin-left: 8px;
}

.mobile-freeze-banner small {
    display: block;
    font-size: 11px;
    font-weight: normal;
    margin-top: 2px;
    opacity: 0.95;
}

/* Header nach unten verschieben wenn Banner aktiv */
body.has-frozen-banner .mobile-header-v2 {
    top: 44px !important;
}

/* Content auch nach unten verschieben */
body.has-frozen-banner .overview-viewport,
body.has-frozen-banner .mobile-content,
body.has-frozen-banner .page-content {
    padding-top: 44px;
}

/* Safe Area Adjustment für Banner */
body.has-frozen-banner {
    --header-offset: calc(var(--header-height, 56px) + 44px);
}

/* Frozen Clock Styling - für WT/KT Uhren im Freeze-Zustand */
.frozen {
    color: #FFA500 !important;
    animation: frozen-pulse 2s ease-in-out infinite;
}

@keyframes frozen-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ========================================
   UNIFIED PAGE TABS - Konsistente Sub-Header
   ======================================== */

/* Tab Container - unter dem Header */
.mobile-page-tabs {
    display: flex;
    background: var(--bg-card, rgba(30, 41, 59, 0.95));
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    position: sticky;
    top: 0;
    z-index: 100;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.mobile-page-tabs::-webkit-scrollbar {
    display: none;
}

/* Tab Button */
.mobile-page-tab {
    flex: 1;
    min-width: max-content;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary, #94a3b8);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.mobile-page-tab:hover {
    color: var(--text-primary, #fff);
    background: rgba(255, 255, 255, 0.05);
}

.mobile-page-tab.active {
    color: var(--color-primary, #00d4ff);
    border-bottom-color: var(--color-primary, #00d4ff);
    background: rgba(0, 212, 255, 0.1);
}

.mobile-page-tab .tab-icon {
    font-size: 16px;
}

.mobile-page-tab .tab-label {
    font-size: 12px;
}

/* Tab Badge */
.mobile-page-tab .tab-badge {
    background: var(--color-primary, #00d4ff);
    color: #000;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Content Container unter Tabs */
.mobile-page-content {
    padding: var(--spacing-md, 16px);
    padding-bottom: calc(var(--bottom-nav-height, 60px) + var(--safe-area-bottom, 0px) + 20px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.mobile-page-content::-webkit-scrollbar {
    display: none;
}

/* Tab Panel Visibility */
.mobile-page-content .tab-panel {
    display: none;
}

.mobile-page-content .tab-panel.active {
    display: block;
}
