:root {
    /* Modern Palette */
    --bg-app: #09090b; /* Very dark slate */
    --bg-surface: #18181b; /* Card background */
    --bg-surface-2: #27272a; /* Secondary background */
    
    --accent-buy: #10b981; /* Emerald Green */
    --accent-sell: #ef4444; /* Red */
    --accent-primary: #3b82f6; /* Blue */
    
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    padding-bottom: 100px; /* Space for bottom dock */
    overscroll-behavior-y: none; /* iOS bounce fix */
}

/* --- Layout Wrappers --- */
.app-container {
    padding: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.surface-card {
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* --- Header & Status --- */
.top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr; /* Logo/Space - Status - Actions/Space */
    align-items: center;
    margin-bottom: 2px;
    padding: 12px 16px;
}

.logo-area {
    justify-self: start;
}
.logo-area img { 
    height: 24px; 
    width: auto; 
    display: block;
}

.status-indicator-box {
    justify-self: center;
    /* Reset from previous */
    background: var(--bg-surface-2);
    padding: 4px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Ensure connection dot is strictly sized */
.connection-dot {
    width: 8px !important;
    height: 8px !important;
    min-width: 8px;
    border-radius: 50%;
    display: block;
}

/* --- Hero Prices (Best Entry) --- */
/* Fixed Hero Grid Alignment via Grid Areas */
.price-hero-grid {
    display: grid;
    grid-template-areas:
        "ext-ask . ."
        "ask center bid"
        ". . ext-bid";
    grid-template-columns: 1fr auto 1fr;
    /* Row gap 8px, Col gap 12px */
    gap: 8px 12px; 
    align-items: center; /* Center vertically in their rows */
}

/* Assign Grid Areas */
#extendedAskPanel { grid-area: ext-ask; width: 100%; }
#wrap_ask         { grid-area: ask; width: 100%; }
.center-info      { grid-area: center; }
#wrap_bid         { grid-area: bid; width: 100%; }
#extendedBidPanel { grid-area: ext-bid; width: 100%; }

.price-col { display: contents; } /* If wrapper stays in HTML, make it transparent to grid */

.price-col {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Space between Extended and Main */
}

.price-card {
    background: var(--bg-surface-2);
    border-radius: var(--border-radius-sm);
    padding: 12px 8px;
    text-align: center;
    position: relative;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.price-card.ask { border-color: rgba(239, 68, 68, 0.2); }
.price-card.bid { border-color: rgba(16, 185, 129, 0.2); }

.mainPrice {
    font-size: 24px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}
.mainPrice.ask { color: var(--accent-sell); }
.mainPrice.bid { color: var(--accent-buy); }

.sizeTag {
    position: absolute;
    top: -6px; right: -6px;
    background: #333;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    color: #fff;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.center-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
    width: 60px;
}

/* --- Grade Chips & Badges --- */
.gradeChip {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 0;
    text-transform: uppercase;
}
.grade-A, .grade-APlus, .grade-APlusPlus, .grade-APlusPlusPlus {
    color: #fbbf24; /* Gold */
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

/* ============================================================================
   Exec & Spoof Badges (Upper Left)
   ============================================================================ */
.topLeftPills {
    position: absolute;
    top: 2px;
    left: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
    z-index: 20;
    pointer-events: none;
}

/* Badge pour le pilier Exécution (Violet pour différencier) */
.gradeChip.exec {
    position: static !important;
    display: inline-block !important; /* Override default display:none */
    background: rgba(156, 39, 176, 0.15); /* Purple tint */
    border: 1px solid rgba(156, 39, 176, 0.4);
    color: #ce93d8;
    box-shadow: 0 0 8px rgba(156, 39, 176, 0.2);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 800;
    text-transform: uppercase;
    transform: none !important;
}

/* Alerte Spoofing */
.spoof-alert-banner {
    position: static !important;
    display: block !important;
    background: rgba(255, 23, 68, 0.95);
    border: 1px solid #ff1744;
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 900;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    box-shadow: 0 2px 6px rgba(255, 23, 68, 0.4);
    animation: flashRed 1.5s infinite ease-in-out;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

@keyframes flashRed {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.02); opacity: 0.9; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Extended Panels (Hidden by default) --- */
.ext-panel {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255,255,255,0.1);
}

/* --- Gauge Modernized --- */
.modern-gauge-wrap {
    height: 6px;
    background: #333;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    margin: 10px 0;
    display: flex;
}
.modern-gauge-fill { height: 100%; transition: width 0.3s ease; }
.biasSell { background: var(--accent-sell); }
.biasBuy { background: var(--accent-buy); }

/* --- Last 3 Setups (Horizontal Scroll) --- */
.history-scroller {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none; /* Firefox */
}

/* ============================================================================
   SHARED LAYOUT STYLES (Navigation & Headers)
   ============================================================================ */

/* Bottom Navigation */
.bottomNav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 60px !important;
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #333;
    display: flex !important;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 99999 !important;
}

.bottomNavItem {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: #9aa6b2; /* Default muted */
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    text-decoration: none;
    transition: color 0.2s, background 0.2s;
}

.bottomNavItem.active {
    color: #2979ff;
    background: rgba(41, 121, 255, 0.05);
    border-top: 2px solid #2979ff;
}

.bottomNavItem.danger {
    color: #ff453a;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* Common Header Style (Like Journal) */
.page-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #2e2e2e);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 0.5px;
}

.page-subtitle {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    display:block;
}

/* --- DOM Tables --- */
.dom-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.dom-col {
    background: var(--bg-surface-2);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}
.dom-header {
    background: rgba(255,255,255,0.03);
    padding: 6px;
    text-align: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.dom-table-mini {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
}
.dom-table-mini th { text-align: right; padding: 4px; color: #666; font-weight: normal; }
.dom-table-mini td { text-align: right; padding: 4px; border-bottom: 1px solid rgba(255,255,255,0.02); }
.dom-table-mini tr:last-child td { border-bottom: none; }

/* --- Config / Login Panel --- */
.login-overlay {
    background: var(--bg-surface);
    border: 1px solid var(--accent-primary);
    padding: 16px;
    border-radius: var(--border-radius);
    margin-bottom: 12px;
}
.login-input {
    width: 100%;
    background: #000;
    border: 1px solid #333;
    color: #fff;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
}

/* --- Bottom Fixed Bar (Action Dock) --- */
.bottom-dock {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(20, 20, 23, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 10px 16px;
    padding-bottom: max(10px, var(--safe-area-bottom));
    display: flex;
    justify-content: center;
    gap: 12px;
    z-index: 1000;
}

.dock-btn {
    flex: 1;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s;
}
.dock-btn:active { transform: scale(0.96); }

.btn-start { background: var(--accent-primary); color: white; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4); }
.btn-stop { background: #27272a; color: #ef4444; border: 1px solid #3f3f46; }
.btn-replay { background: #27272a; color: var(--text-main); border: 1px solid #3f3f46; }

/* --- Consolidated Last A Card */
.last-a-card {
    background: var(--bg-surface-2);
    border-radius: var(--border-radius);
    padding: 0;
    margin-top: 4px;
    display: flex;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.05);
}

.last-a-side {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    border-bottom: 2px solid transparent; /* Colored line at bottom */
}
.last-a-side.ask { border-right: 1px solid rgba(255,255,255,0.05); border-bottom-color: var(--accent-sell); }
.last-a-side.bid { border-bottom-color: var(--accent-buy); }

.a-grade-badge {
    position: absolute;
    top: 8px; right: 8px;
    font-size: 10px;
    font-weight: 800;
    color: #fbbf24;
    text-shadow: 0 0 5px rgba(251,191,36,0.3);
}

.a-price-large {
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    margin-top: 8px;
}

.a-details {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* --- Revamped News / Alert Panel --- */
.system-message-card {
    background: var(--bg-surface-2);
    border-left: 3px solid var(--accent-primary);
    border-radius: 4px;
    padding: 10px 12px;
    margin: 8px 0;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.system-message-card.alert {
    background: rgba(239, 68, 68, 0.1);
    border-left-color: var(--accent-sell);
    color: #fca5a5;
}

.news-v2 {
    /* More polished news look */
    background: var(--bg-surface);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    margin-top: 10px;
    position: relative;
    overflow: hidden;
    margin: 12px 0 0 0; /* Align spacing with cards */
    width: 100%;
}
.news-v2::before {
    content: '';
    position: absolute; left:0; top:0; bottom:0; width: 4px;
    background: var(--accent-primary);
}
.news-v2.tragedy::before { background: var(--accent-sell); }

.news-v2-content {
    padding: 10px 12px 10px 16px;
    font-size: 12px;
    line-height: 1.4;
}

/* --- Badge / Pill Enhancements --- */

/* Base Pill Style */
.status-pill, .matchPill, .distinctPill, .wall-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    margin: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Specific Colors */
.wall-badge {
    background: #7c3aed; /* Violet */
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
}

.matchPill {
    background: #2563eb; /* Blue */
    color: #fff;
}

.distinctPill {
    background: #d97706; /* Amber */
    color: #fff;
}

/* Ensure they are visible inside cards */
.price-card .badges-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
    min-height: 16px; /* Reserve space so layout doesn't jump */
}

/* Extended Card Styling updates */
.price-card.extended {
    transform: scale(0.95); /* Slightly smaller to indicate secondary */
    opacity: 0.9;
    border-style: dashed;
}

/* Fix Image Sizing Globally in Header */
.logo-area img {
    max-height: 32px;
    width: auto;
    max-width: 120px; /* Constraint width */
}

.status-indicator-box img {
    max-width: 24px;
    max-height: 24px;
}
/* Ensure no rogue SVGs take over */
svg, img { max-width: 100%; }

/* Utilities */
.text-xs { font-size: 10px; }
.text-muted { color: var(--text-muted); }
.flex { display: flex; }
.hidden { display: none !important; }
.wall-badge { 
    background: #7c3aed; color: white; 
    font-size: 9px; padding: 1px 4px; border-radius: 4px; 
    display: inline-block; margin-left: 2px;
}

/* Hide Legacy Navigation inserted by page-init/bottom-nav */
#bottomNav, nav, .bottom-nav-legacy {
    display: none !important;
}

/* Feature: Tragedy Red Alert for News */
.news-v2.tragedy {
    background: linear-gradient(135deg, #b91c1c 0%, #7f1d1d 100%);
    border: 1px solid #ef4444;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
    animation: pulse-red 2s infinite;
}

/* --- News Carousel Internals (Injected by JS) --- */
.news-carousel-wrapper {
    display: flex;
    overflow: hidden;
    width: 100%;
    position: relative;
    /* ensure it respects parent padding */
}

.news-track {
    display: flex;
    transition: transform 0.5s ease-in-out;
    width: 100%;
}

.news-slide {
    min-width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 4px; 
}

.news-currency {
    font-size: 10px;
    font-weight: 900;
    color: #fff;
    background: var(--accent-primary);
    padding: 2px 4px;
    border-radius: 4px;
    min-width: 30px;
    text-align: center;
}

.news-title {
    font-size: 11px;
    font-weight: 600;
    color: #eaeaea;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.news-time-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    margin-left: auto;
}

/* Alert Mode for V2 News */
.news-v2.alert-mode {
    border-color: var(--accent-sell);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.news-v2.alert-mode .news-currency {
    background: var(--accent-sell);
}

/* Timer is usually inside news-v2 but handled inline in HTML structure. 
   We can target typical span if needed, but JS only adds class to card. */
.news-v2.alert-mode #newsTimer {
    color: var(--accent-sell);
    font-weight: 900;
    text-shadow: 0 0 5px rgba(239,68,68,0.5);
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Hide old styles if they leak */
.connection-text { display: none; } /* User only wants the icon */
