/**
 * emerald-theme.css — Stoswarm Emerald & Glassmorphic Design System v2.0
 * Canonical shared stylesheet. Mount read-only into every app container.
 * App-specific stylesheets override tokens or add components AFTER importing this file.
 * DO NOT redefine the entire :root block in app-specific stylesheets.
 *
 * Mount via compose.yaml:
 *   volumes:
 *     - /mnt/container-storage/stacks/_template/theme/emerald-theme.css:/app/static/css/emerald-theme.css:ro,Z
 *
 * Load in HTML:
 *   <link rel="stylesheet" href="/static/css/emerald-theme.css">
 *   <link rel="stylesheet" href="/static/css/app.css">  <!-- app overrides -->
 */

/* ============================================================
   TIER 1: PRIMITIVE COLOR TOKENS
   Literal hex values. Never reference directly in components.
   ============================================================ */
:root {
    --color-emerald:  #10b981;
    --color-cyan:     #2dd4bf;
    --color-teal:     #0d9488;
    --color-amber:    #f59e0b;
    --color-rose:     #f43f5e;
    --color-sky:      #0ea5e9;
    --color-purple:   #a855f7;
    --color-white:    #f2f7f5;
}

/* ============================================================
   TIER 2: SEMANTIC ROLE TOKENS — DARK MODE (DEFAULT)
   Use these in all components and layouts.
   ============================================================ */
:root {
    /* --- Backgrounds & Surfaces --- */
    --bg-primary:       #121c19;
    --bg-secondary:     #192723;
    --bg-card:          #1a2a26;
    --bg-card-hover:    #1f322d;
    --bg-overlay:       rgba(26, 42, 38, 0.82); /* glassmorphic nav/modal only */

    /* --- Borders & Dividers --- */
    --border-color:     #273d36;
    --border-highlight: var(--color-cyan);
    --border-success:   var(--color-emerald);

    /* --- Typography --- */
    --text-primary:     #f2f7f5;
    --text-secondary:   #a2b8b1;
    --text-muted:       #6b847d;

    /* --- Semantic Accent Roles --- */
    --accent-brand:     var(--color-cyan);     /* Primary brand, active tab, focus */
    --accent-success:   var(--color-emerald);  /* Bullish, verified, healthy, cash */
    --accent-warning:   var(--color-amber);    /* Warning, urgency, pair swaps */
    --accent-danger:    var(--color-rose);     /* Bearish, error, critical */
    --accent-info:      var(--color-sky);      /* Informational, links, neutral */
    --accent-ai:        var(--color-purple);   /* AI model, volatility, committee */
    --accent-gradient:  var(--color-teal);     /* Secondary brand & gradient anchor */

    /* --- Badge Tokens --- */
    --badge-bg:         rgba(45, 212, 191, 0.12);
    --badge-border:     rgba(45, 212, 191, 0.35);
    --badge-text:       var(--color-cyan);

    /* --- Elevation & Shadows --- */
    --shadow-sm:        0 1px 2px 0 rgba(0, 0, 0, 0.35);
    --shadow-md:        0 4px 8px -1px rgba(0, 0, 0, 0.50), 0 2px 4px -2px rgba(0, 0, 0, 0.45);
    --shadow-lg:        0 10px 20px -3px rgba(0, 0, 0, 0.65), 0 4px 8px -4px rgba(0, 0, 0, 0.55);
    --shadow-xl:        0 20px 40px -4px rgba(0, 0, 0, 0.75);

    /* --- Corner Radii --- */
    --radius-xs:        4px;
    --radius-sm:        6px;
    --radius-md:        10px;
    --radius-lg:        14px;
    --radius-xl:        20px;
    --radius-pill:      9999px;

    /* --- Spacing Scale --- */
    --space-1:          4px;
    --space-2:          8px;
    --space-3:          12px;
    --space-4:          16px;
    --space-5:          20px;
    --space-6:          24px;
    --space-8:          32px;
    --space-10:         40px;
    --space-12:         48px;

    /* --- Typography Stacks --- */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Roboto Mono', monospace;

    /* --- Font Size Scale --- */
    --font-size-xs:   11px;
    --font-size-sm:   13px;
    --font-size-base: 15px;
    --font-size-md:   16px;
    --font-size-lg:   18px;
    --font-size-xl:   24px;
    --font-size-2xl:  32px;

    /* --- Transitions --- */
    --transition-fast: all 0.15s ease;
    --transition-base: all 0.20s ease;
    --transition-slow: all 0.30s ease;
}

/* ============================================================
   CANONICAL LIGHT THEME
   ============================================================ */
[data-theme="light"] {
    --bg-primary:       #f8fafc;
    --bg-secondary:     #f1f5f9;
    --bg-card:          #ffffff;
    --bg-card-hover:    #f8fafc;
    --bg-overlay:       rgba(255, 255, 255, 0.88);

    --border-color:     #e2e8f0;
    --border-highlight: #0284c7;
    --border-success:   #059669;

    --text-primary:     #0f172a;
    --text-secondary:   #334155;
    --text-muted:       #64748b;

    --accent-brand:     #0284c7;
    --accent-success:   #059669;
    --accent-warning:   #d97706;
    --accent-danger:    #e11d48;
    --accent-info:      #0369a1;
    --accent-ai:        #7c3aed;
    --accent-gradient:  #0d9488;

    --badge-bg:         rgba(2, 132, 199, 0.08);
    --badge-border:     rgba(2, 132, 199, 0.25);
    --badge-text:       #0284c7;

    --shadow-sm:        0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md:        0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
    --shadow-lg:        0 10px 15px -3px rgba(0, 0, 0, 0.10), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
    --shadow-xl:        0 20px 30px -4px rgba(0, 0, 0, 0.12);
}

/* OS-level light theme auto-detection */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg-primary:       #f8fafc;
        --bg-secondary:     #f1f5f9;
        --bg-card:          #ffffff;
        --bg-card-hover:    #f8fafc;
        --bg-overlay:       rgba(255, 255, 255, 0.88);
        --border-color:     #e2e8f0;
        --border-highlight: #0284c7;
        --border-success:   #059669;
        --text-primary:     #0f172a;
        --text-secondary:   #334155;
        --text-muted:       #64748b;
        --accent-brand:     #0284c7;
        --accent-success:   #059669;
        --accent-warning:   #d97706;
        --accent-danger:    #e11d48;
        --accent-info:      #0369a1;
        --accent-ai:        #7c3aed;
        --badge-bg:         rgba(2, 132, 199, 0.08);
        --badge-border:     rgba(2, 132, 199, 0.25);
        --badge-text:       #0284c7;
    }
}

/* ============================================================
   GLOBAL RESETS & BASE STYLES
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: var(--font-size-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   ACCESSIBILITY: FOCUS RINGS
   ============================================================ */
*:focus { outline: none; }

*:focus-visible {
    outline: 2px solid var(--accent-brand);
    outline-offset: 3px;
    border-radius: var(--radius-xs);
}

/* ============================================================
   ACCESSIBILITY: REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   SCROLLBARS (Emerald-tinted)
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
    background: rgba(16, 185, 129, 0.30);
    border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: rgba(16, 185, 129, 0.55); }

/* ============================================================
   SITE HEADER (Single-Page App pattern)
   ============================================================ */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-3) var(--space-6);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.brand-title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
    text-decoration: none;
    color: inherit;
}

.brand-title h1 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.brand-subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: 2px;
}

.nav-pills {
    display: flex;
    gap: var(--space-1);
    flex: 1;
    padding: 0 var(--space-4);
}

.header-controls {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
}

/* ============================================================
   TAB STRIP — Recessed Rut (Canonical Standard v2.1)
   Structure:
     .tab-strip           — centering wrapper
       .tab-strip-track   — outer glass pill (the frame)
         .tab-strip-rut   — dark recessed trough
           .tab-btn       — individual pill tabs
   Active tab raises OUT of the rut with a drop shadow.
   Underline sits at the rut floor.
   ============================================================ */

/* Centering wrapper */
.tab-strip {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

/* Outer glass pill — the frame */
.tab-strip-track {
    display: inline-flex;
    flex-direction: column;
    padding: 10px 12px 8px;
    background: rgba(26, 42, 38, 0.86);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.05);
    max-width: 100%;
}

/* Recessed rut — dark inset trough */
.tab-strip-rut {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 4px 8px;
    background: rgba(10, 18, 15, 0.55);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.55),
                inset 0 0 0 1px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-strip-rut::-webkit-scrollbar { display: none; }

/* Tab pill */
.tab-btn {
    position: relative;
    padding: 11px 24px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s ease;
    text-decoration: none;
}
.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(45, 212, 191, 0.07);
    border-color: var(--border-color);
}

/* Active — raised out of the rut */
.tab-btn.active,
.tab-btn[aria-selected="true"] {
    color: var(--accent-brand);
    background: rgba(26, 42, 38, 0.97); /* matches outer pill = dramatically lighter than dark rut */
    border-color: rgba(45, 212, 191, 0.35);
    font-weight: 700;
    transform: translateY(-2px);
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.7),
                inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

/* Underline at rut floor: 4px rut padding + 2px tab lift = 6px */
.tab-btn.active::after,
.tab-btn[aria-selected="true"]::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-brand);
    border-radius: 2px 2px 0 0;
    box-shadow: 0 0 8px rgba(45, 212, 191, 0.55);
}

/* Compact variant — in-card secondary strips */
.tab-strip-sm .tab-strip-track { border-radius: 12px; padding: 7px 9px 6px; }
.tab-strip-sm .tab-strip-rut   { padding: 3px 5px; gap: 5px; border-radius: 8px; }
.tab-strip-sm .tab-btn          { padding: 6px 14px; font-size: 12px; border-radius: 6px; }
.tab-strip-sm .tab-btn.active::after { bottom: -5px; }

/* Mobile: pills scroll horizontally */
@media (max-width: 768px) {
    .tab-strip-track { max-width: calc(100vw - 32px); }
    .tab-strip-rut   { justify-content: flex-start; }
}

/* Legacy alias — .nav-pill → .tab-btn for backward compat */
.nav-pills   { /* use .tab-strip-rut */ }
.nav-pill    { /* use .tab-btn */ }


/* Mobile hamburger (used by nav-pills layout in non-Dash apps) */
.hamburger-btn { display: none; }


@media (max-width: 768px) {
    .site-header { padding: var(--space-3) var(--space-4); }
    .nav-pills { display: none; }
    .hamburger-btn {
        display: flex;
        align-items: center;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        padding: var(--space-2);
        border-radius: var(--radius-sm);
        cursor: pointer;
        font-size: var(--font-size-lg);
        margin-left: auto;
    }
    .mobile-nav {
        position: fixed;
        top: 56px; left: 0; right: 0;
        background: var(--bg-overlay);
        backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--border-color);
        padding: var(--space-3);
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        z-index: 99;
    }
    .mobile-nav[hidden] { display: none; }
}

/* ============================================================
   BADGES
   ============================================================ */
.badge-live {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 3px var(--space-2);
    background: var(--badge-bg);
    border: 1px solid var(--badge-border);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--badge-text);
    letter-spacing: 0.03em;
}

.badge-live::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent-success);
    box-shadow: 0 0 6px var(--accent-success);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.85); }
}

.badge-sub {
    display: inline-flex;
    align-items: center;
    padding: 3px var(--space-2);
    background: rgba(107, 132, 125, 0.15);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ============================================================
   CARDS
   ============================================================ */

/* Elevated opaque — DEFAULT for dashboard cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
    box-shadow: var(--shadow-md);
    transition: var(--transition-fast);
}

.card:hover {
    border-color: rgba(45, 212, 191, 0.25);
    box-shadow: var(--shadow-lg);
}

/* Glassmorphic — ONLY for nav, modals, overlays, hero panels */
.card-glass {
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-lg);
}

/* ============================================================
   KPI METRIC STRIP
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-highlight);
    box-shadow: var(--shadow-md);
}

.kpi-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-2);
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-sub {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 600;
    font-family: var(--font-sans);
    background: linear-gradient(135deg, var(--color-emerald) 0%, var(--color-teal) 100%);
    border: 1px solid rgba(45, 212, 191, 0.4);
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
    transition: var(--transition-base);
    text-decoration: none;
}
.btn:hover { opacity: 0.9; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4); }
.btn:focus-visible { outline: 2px solid var(--accent-brand); outline-offset: 3px; }

.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-sans);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}
.btn-outline:hover, .btn-outline.active {
    border-color: var(--border-highlight);
    color: var(--accent-brand);
    background: rgba(45, 212, 191, 0.12);
}
.btn-outline:focus-visible { outline: 2px solid var(--accent-brand); outline-offset: 3px; }

/* ============================================================
   DATA TABLES
   ============================================================ */
table { width: 100%; border-collapse: collapse; }

th {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

td {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    padding: var(--space-3);
    border-bottom: 1px solid rgba(39, 61, 54, 0.5);
}

tr:hover td { background: rgba(45, 212, 191, 0.04); cursor: pointer; }

/* ============================================================
   STATUS PILL BADGES
   ============================================================ */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    border-radius: var(--radius-xs);
    font-size: var(--font-size-xs);
    font-weight: 600;
}
.pill-success { background: rgba(16, 185, 129, 0.15); color: var(--accent-success); }
.pill-warning { background: rgba(245, 158, 11, 0.15); color: var(--accent-warning); }
.pill-danger  { background: rgba(244, 63, 94,  0.15); color: var(--accent-danger);  }
.pill-info    { background: rgba(14, 165, 233, 0.15); color: var(--accent-info);    }
.pill-ai      { background: rgba(168, 85, 247, 0.15); color: var(--accent-ai);      }
.pill-brand   { background: rgba(45, 212, 191, 0.15); color: var(--accent-brand);   }

/* ============================================================
   SKELETON LOADING SHIMMER
   ============================================================ */
@keyframes shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position:  400px 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-card) 0%,
        rgba(16, 185, 129, 0.08) 50%,
        var(--bg-card) 100%
    );
    background-size: 800px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-kpi-value { height: 32px; width: 160px; margin-bottom: 8px; }
.skeleton-text      { height: 14px; width: 100%;  margin-bottom: 6px;  }
.skeleton-text-sm   { height: 12px; width: 60%;                        }
