/* ============================================================
   CHINA EXCHANGE — PREMIUM DARK DESIGN SYSTEM v4
   ============================================================ */

/* ─── Fonts ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ─── Design Tokens ──────────────────────────────────────── */
:root {
    /* Core backgrounds */
    --bg:              #05070f;
    --bg-elevated:     #080b15;
    --surface:         rgba(13, 17, 30, 0.80);
    --surface-solid:   #0d111e;
    --surface-2:       rgba(18, 24, 40, 0.90);
    --surface-3:       rgba(10, 14, 24, 0.95);
    --surface-hover:   rgba(22, 30, 52, 0.85);

    /* Borders */
    --line:            rgba(130, 150, 200, 0.10);
    --line-soft:       rgba(130, 150, 200, 0.06);
    --line-strong:     rgba(130, 150, 200, 0.18);
    --line-glow:       rgba(82, 160, 255, 0.30);

    /* Typography */
    --text:            #eef2fc;
    --text-secondary:  #b8c4de;
    --muted:           #7888a8;
    --faint:           #49566e;

    /* Brand colors */
    --blue:            #3a9fff;
    --blue-bright:     #65b8ff;
    --blue-soft:       rgba(58, 159, 255, 0.12);
    --blue-glow:       rgba(58, 159, 255, 0.20);

    --green:           #3dd68c;
    --green-soft:      rgba(61, 214, 140, 0.12);
    --green-glow:      rgba(61, 214, 140, 0.18);

    --gold:            #f0c14b;
    --gold-soft:       rgba(240, 193, 75, 0.12);

    --purple:          #8b7cff;
    --purple-soft:     rgba(139, 124, 255, 0.12);

    --danger:          #ff6070;
    --danger-soft:     rgba(255, 96, 112, 0.12);

    /* Radii */
    --r-sm:   10px;
    --r-md:   16px;
    --r-lg:   22px;
    --r-xl:   28px;
    --r-2xl:  36px;

    /* Shadows & Glows */
    --shadow:       0 32px 80px rgba(0,0,0,0.55);
    --shadow-sm:    0 8px 28px rgba(0,0,0,0.30);
    --shadow-card:  0 16px 48px rgba(0,0,0,0.40);
    --glow-blue:    0 0 48px rgba(58,159,255,0.18), 0 0 80px rgba(58,159,255,0.08);
    --glow-green:   0 0 40px rgba(61,214,140,0.18), 0 0 70px rgba(61,214,140,0.08);
    --glow-gold:    0 0 40px rgba(240,193,75,0.16);

    /* Typography */
    --font: "Inter", system-ui, -apple-system, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;

    /* Layout */
    --sidebar-w: 272px;
    --topbar-h:  72px;
    --mobnav-h:  76px;
}

/* ─── Light theme ────────────────────────────────────────── */
body.theme-light {
    --bg:            #f0f3fa;
    --bg-elevated:   #ffffff;
    --surface:       rgba(255,255,255,0.85);
    --surface-solid: #ffffff;
    --surface-2:     rgba(248,250,255,0.95);
    --surface-3:     #f5f7fc;
    --surface-hover: rgba(235,240,255,0.90);
    --line:          rgba(20,30,60,0.08);
    --line-soft:     rgba(20,30,60,0.05);
    --line-strong:   rgba(20,30,60,0.14);
    --line-glow:     rgba(58,159,255,0.25);
    --text:          #0f1829;
    --text-secondary:#2d3a55;
    --muted:         #5a6a88;
    --faint:         #98a8c4;
    --shadow:        0 24px 60px rgba(15,25,50,0.10);
    --shadow-sm:     0 6px 20px rgba(15,25,50,0.06);
    --shadow-card:   0 12px 36px rgba(15,25,50,0.08);
    --glow-blue:     0 0 32px rgba(58,159,255,0.12);
    --glow-green:    0 0 28px rgba(61,214,140,0.12);
    color-scheme: light;
}

/* ─── Reset & Base ───────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    background: var(--bg);
    color-scheme: dark;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    height: 100%;
}

body.theme-light { color-scheme: light; }

body {
    min-height: 100%;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: -0.012em;
    -webkit-font-smoothing: antialiased;
    background:
        radial-gradient(ellipse 90% 60% at 8% -8%,  rgba(58,159,255,0.16)  0%, transparent 55%),
        radial-gradient(ellipse 70% 45% at 92% 2%,  rgba(139,124,255,0.13) 0%, transparent 50%),
        radial-gradient(ellipse 55% 40% at 72% 98%, rgba(61,214,140,0.08)  0%, transparent 55%),
        radial-gradient(ellipse 45% 35% at 0% 82%,  rgba(240,193,75,0.05)  0%, transparent 50%),
        linear-gradient(170deg, #070a14 0%, #05070f 45%, #040610 100%);
    background-attachment: fixed;
    overflow-x: hidden;
}

body.theme-light {
    background:
        radial-gradient(ellipse 75% 50% at 12% -5%, rgba(58,159,255,0.10) 0%, transparent 55%),
        radial-gradient(ellipse 55% 38% at 92% 5%,  rgba(139,124,255,0.08) 0%, transparent 50%),
        linear-gradient(180deg, #f5f8ff 0%, #f0f3fa 100%);
}

/* Dot grid overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(100,130,200,0.18) 1px, transparent 1px);
    background-size: 36px 36px;
    opacity: 0.22;
    mask-image: radial-gradient(ellipse 80% 65% at 50% 30%, #000 10%, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse 80% 65% at 50% 30%, #000 10%, transparent 75%);
}

button,input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
    outline: 2px solid var(--blue-bright);
    outline-offset: 2px;
}
.hidden { display: none !important; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ─── App Shell ──────────────────────────────────────────── */
.app-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0,1fr);
    min-height: 100vh;
}

/* ─────────────────────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex;
    width: var(--sidebar-w);
    flex-direction: column;
    padding: 24px 16px;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg,
        rgba(8,12,22,0.95)  0%,
        rgba(6,9,18,0.98)   100%);
    backdrop-filter: blur(32px) saturate(160%);
    box-shadow: 6px 0 48px rgba(0,0,0,0.28), inset -1px 0 0 var(--line);
}

body.theme-light .sidebar {
    background: linear-gradient(180deg,
        rgba(255,255,255,0.94) 0%,
        rgba(248,250,255,0.97) 100%);
    box-shadow: 6px 0 40px rgba(15,25,50,0.05), inset -1px 0 0 var(--line);
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    color: var(--text);
    text-decoration: none;
    padding: 4px 2px;
}

.brand-mark {
    position: relative;
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    place-items: center;
    border: 1px solid rgba(82,160,255,0.30);
    border-radius: 15px;
    background: linear-gradient(145deg,
        rgba(58,159,255,0.30) 0%,
        rgba(139,124,255,0.14) 55%,
        rgba(61,214,140,0.08) 100%);
    color: var(--blue-bright);
    font-size: 17px;
    box-shadow: var(--glow-blue), inset 0 1px 0 rgba(255,255,255,0.14);
    transition: transform 0.25s ease;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(255,255,255,0.06) 0%, transparent 60%);
    pointer-events: none;
}

.brand:hover .brand-mark { transform: scale(1.04) rotate(-3deg); }

.brand strong, .brand small { display: block; }

.brand strong {
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: linear-gradient(90deg, #ffffff 0%, #c0d8ff 60%, #a0ffcc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.theme-light .brand strong {
    background: none;
    -webkit-text-fill-color: var(--text);
}

.brand small {
    margin-top: 4px;
    color: var(--faint);
    font: 500 9.5px/1 var(--mono);
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

/* System state pill */
.system-state {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 28px 0 22px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--green-soft), rgba(58,159,255,0.05));
    color: var(--muted);
    font: 500 9.5px/1 var(--mono);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.system-state strong {
    margin-left: auto;
    color: var(--green);
    font-size: 9px;
    letter-spacing: 0.10em;
}

/* Status LED */
.status-led {
    display: inline-block;
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 2px rgba(61,214,140,0.12), 0 0 10px rgba(61,214,140,0.70);
    animation: led-pulse 2.6s ease-in-out infinite;
}

@keyframes led-pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.70; transform: scale(0.88); }
}

/* Navigation */
.side-nav { display: grid; gap: 6px; }

.nav-item {
    display: grid;
    grid-template-columns: 20px 1fr auto;
    align-items: center;
    width: 100%;
    min-height: 46px;
    gap: 11px;
    padding: 0 13px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--muted);
    text-align: left;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    transition: 200ms cubic-bezier(0.22,1,0.36,1);
}

.nav-item i {
    width: 18px;
    color: var(--faint);
    text-align: center;
    font-size: 14px;
    transition: color 200ms ease;
}

.nav-item kbd {
    color: var(--faint);
    font: 500 9.5px/1 var(--mono);
    opacity: 0.65;
}

.nav-item:hover {
    border-color: var(--line);
    background: var(--surface-hover);
    color: var(--text);
    transform: translateX(3px);
}

.nav-item:hover i { color: var(--blue-bright); }

.nav-item.active {
    border-color: var(--line-glow);
    background: linear-gradient(135deg,
        rgba(58,159,255,0.18) 0%,
        rgba(139,124,255,0.08) 100%);
    color: var(--text);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.07),
        var(--glow-blue);
}

.nav-item.active i,
.nav-item.active kbd { color: var(--blue-bright); }

/* Sidebar footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.utility-button {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--muted);
    font: 600 10.5px/1 var(--mono);
    transition: 180ms ease;
    backdrop-filter: blur(12px);
}

.utility-button:hover {
    border-color: var(--line-glow);
    color: var(--blue-bright);
    box-shadow: var(--glow-blue);
    transform: translateY(-2px);
}

.ai-shortcut {
    margin-left: auto;
    border-color: transparent;
    background: linear-gradient(135deg, #2f9bff 0%, #6b8cff 55%, #3dd68c 140%);
    color: white !important;
    box-shadow: 0 8px 28px rgba(47,155,255,0.38);
    position: relative;
    overflow: hidden;
}

.ai-shortcut::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.22) 50%, transparent 65%);
    transform: translateX(-120%);
    transition: transform 0.55s ease;
}

.ai-shortcut:hover::before { transform: translateX(120%); }

.ai-shortcut:hover {
    filter: brightness(1.10);
    box-shadow: 0 12px 36px rgba(47,155,255,0.50);
    transform: translateY(-2px);
}

/* ─────────────────────────────────────────────────────────
   WORKSPACE
───────────────────────────────────────────────────────── */
.workspace {
    grid-column: 2;
    display: flex;
    min-width: 0;
    min-height: 100vh;
    flex-direction: column;
    padding: 0 44px;
}

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    min-height: var(--topbar-h);
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(5,7,15,0.70);
    backdrop-filter: blur(24px) saturate(140%);
    margin: 0 -44px;
    padding: 0 44px;
}

body.theme-light .topbar {
    background: rgba(240,243,250,0.82);
}

.eyebrow {
    color: var(--faint);
    font: 500 10px/1.2 var(--mono);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.eyebrow span { color: var(--blue-bright); }

.topbar h1 {
    font-size: clamp(22px, 2.8vw, 30px);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.15;
    background: linear-gradient(135deg, #ffffff 0%, #c8daff 60%, #a0ffd0 120%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.theme-light .topbar h1 {
    background: none;
    -webkit-text-fill-color: var(--text);
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.mobile-tools, .mobile-weather { display: none; }

/* Clock & weather */
.clock-unit,
.weather-widget {
    display: flex;
    align-items: center;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    backdrop-filter: blur(16px);
    color: var(--muted);
    font: 500 12px/1 var(--mono);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    padding: 0 14px;
    gap: 7px;
}

.clock-unit i { color: var(--blue-bright); font-size: 11px; }
.clock-unit b { color: var(--faint); padding: 0 1px; }

.weather-widget {
    min-width: 96px;
    justify-content: center;
    font-size: 11px;
}

/* ─── Sections ───────────────────────────────────────────── */
.section {
    display: none;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 36px 0 40px;
    animation: section-fade 300ms cubic-bezier(0.22,1,0.36,1) both;
}

.section.active { display: block; }

@keyframes section-fade {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Rate layout ────────────────────────────────────────── */
.rate-layout,
.watch-layout {
    display: grid;
    grid-template-columns: minmax(0,1.65fr) minmax(280px,0.8fr);
    gap: 18px;
    align-items: start;
}

/* ─────────────────────────────────────────────────────────
   TERMINAL PANELS
───────────────────────────────────────────────────────── */
.terminal-panel {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    backdrop-filter: blur(28px) saturate(150%);
    box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: border-color 280ms ease, box-shadow 280ms ease;
}

/* Premium top shimmer line */
.terminal-panel::before {
    content: "";
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(82,160,255,0.60) 40%,
        rgba(61,214,140,0.40) 70%,
        transparent 100%);
    opacity: 0.80;
    pointer-events: none;
}

.terminal-panel:hover {
    border-color: var(--line-glow);
}

/* Panel heading */
.panel-heading {
    display: flex;
    min-height: 54px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 22px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 100%);
    color: var(--muted);
    font: 600 10.5px/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.panel-heading > div {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-index {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    height: 20px;
    padding: 0 7px;
    border-radius: 7px;
    background: var(--blue-soft);
    color: var(--blue-bright);
    font-size: 9.5px;
    letter-spacing: 0.04em;
}

.panel-code,
.modal-kicker {
    color: var(--faint);
    font: 500 10px/1.2 var(--mono);
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border: 1px solid rgba(61,214,140,0.22);
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green);
    font: 600 9.5px/1 var(--mono);
    letter-spacing: 0.08em;
}

/* ─── Rate Core ──────────────────────────────────────────── */
.rate-core {
    position: relative;
    min-height: 270px;
    padding: 48px 40px 40px;
    background:
        radial-gradient(ellipse 70% 80% at 10% 30%, rgba(58,159,255,0.10) 0%, transparent 55%),
        radial-gradient(ellipse 55% 60% at 92% 75%, rgba(61,214,140,0.06) 0%, transparent 50%);
}

.rate-caption {
    color: var(--muted);
    font: 500 10.5px/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.13em;
    margin-bottom: 14px;
}

.rate-value-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

.rate-value-row > strong {
    background: linear-gradient(135deg, #ffffff 10%, #9eceff 55%, #7dffbe 120%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font: 800 clamp(50px,7vw,86px)/0.92 var(--mono);
    letter-spacing: -0.045em;
    white-space: nowrap;
    filter: drop-shadow(0 8px 30px rgba(58,159,255,0.22));
}

body.theme-light .rate-value-row > strong {
    background: linear-gradient(135deg, #0f1829 10%, #1d4ed8 70%, #059669 120%);
    -webkit-background-clip: text;
    background-clip: text;
}

#rate-trend-indicator {
    margin-bottom: 8px;
    padding: 7px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface-2);
    font: 500 10.5px/1 var(--mono);
    white-space: nowrap;
    backdrop-filter: blur(8px);
    transition: 200ms ease;
}

#rate-trend-indicator.trend-up {
    border-color: rgba(61,214,140,0.32);
    color: var(--green);
    background: var(--green-soft);
    box-shadow: 0 0 20px rgba(61,214,140,0.10);
}

#rate-trend-indicator.trend-down {
    border-color: rgba(255,96,112,0.32);
    color: var(--danger);
    background: var(--danger-soft);
    box-shadow: 0 0 20px rgba(255,96,112,0.10);
}

.rate-sync {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 26px;
    color: var(--faint);
    font: 500 10.5px/1.4 var(--mono);
}

.rate-sync i { color: var(--blue-bright); }

/* Metric strip */
.metric-strip {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    border-top: 1px solid var(--line);
    background: rgba(0,0,0,0.10);
}

body.theme-light .metric-strip { background: rgba(15,23,42,0.02); }

.metric-cell {
    padding: 18px 22px;
    border-right: 1px solid var(--line);
}

.metric-cell:last-child { border-right: 0; }

.metric-cell span,
.metric-cell strong { display: block; }

.metric-cell span {
    margin-bottom: 8px;
    color: var(--faint);
    font: 500 9.5px/1 var(--mono);
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.metric-cell strong {
    overflow: hidden;
    font: 600 13.5px/1.2 var(--mono);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Tiers Panel ────────────────────────────────────────── */
.tiers-panel { box-shadow: var(--shadow-card); }

.tiers-toggle {
    display: flex;
    width: 100%;
    min-height: 48px;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    transition: color 160ms ease;
}

.tiers-toggle:hover { color: var(--text); }

.tiers-list { padding: 8px 14px 14px; }

.tier-row {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 8px;
    border-bottom: 1px solid var(--line-soft);
    border-radius: 10px;
    transition: background 160ms ease;
}

.tier-row:last-child { border-bottom: 0; }

.tier-row:hover { background: rgba(255,255,255,0.02); }

.tier-row span {
    color: var(--muted);
    font-size: 12.5px;
}

.tier-row strong {
    font: 600 13.5px/1 var(--mono);
}

.tier-row.featured {
    min-height: 58px;
    margin: 4px 0;
    padding: 0 12px;
    border: 1px solid rgba(82,160,255,0.32);
    border-radius: 14px;
    background: linear-gradient(135deg,
        rgba(58,159,255,0.18) 0%,
        rgba(61,214,140,0.08) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.07),
        0 8px 28px rgba(58,159,255,0.12);
}

.tier-row.featured span,
.tier-row.featured strong { color: var(--blue-bright); }

/* Rate history */
.rate-history {
    border-top: 1px solid var(--line);
    padding: 14px 22px;
}

.rate-history-item {
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
}

.rate-history-item:last-child { border-bottom: 0; }

.rate-history-title {
    font: 600 12px/1.3 var(--mono);
    margin-bottom: 3px;
}

.rate-history-details {
    color: var(--muted);
    font-size: 11.5px;
}

.text-up   { color: var(--green); }
.text-down { color: var(--danger); }

/* ─── Quick Actions ──────────────────────────────────────── */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 14px;
    margin-top: 18px;
}

.quick-actions button {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    min-height: 82px;
    align-items: center;
    gap: 14px;
    padding: 0 18px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    backdrop-filter: blur(20px);
    text-align: left;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    transition: 240ms cubic-bezier(0.22,1,0.36,1);
    position: relative;
    overflow: hidden;
}

.quick-actions button::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 38%, rgba(255,255,255,0.06) 50%, transparent 62%);
    transform: translateX(-120%);
    transition: transform 0.55s ease;
    pointer-events: none;
}

.quick-actions button:hover::after { transform: translateX(120%); }

.quick-actions button:hover {
    border-color: var(--line-glow);
    background: linear-gradient(145deg, rgba(58,159,255,0.12) 0%, rgba(18,25,44,0.90) 100%);
    box-shadow: var(--glow-blue), var(--shadow-sm);
    transform: translateY(-4px);
}

.quick-actions button > i:first-child {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border: 1px solid rgba(82,160,255,0.22);
    border-radius: 13px;
    background: var(--blue-soft);
    color: var(--blue-bright);
    font-size: 16px;
    transition: box-shadow 220ms ease;
}

.quick-actions button:hover > i:first-child {
    box-shadow: 0 0 20px rgba(58,159,255,0.28);
}

.quick-actions button > i:last-child {
    color: var(--faint);
    font-size: 11px;
    transition: transform 200ms ease, color 200ms ease;
}

.quick-actions button:hover > i:last-child {
    color: var(--blue-bright);
    transform: translateX(4px);
}

.quick-actions small,
.quick-actions strong { display: block; }

.quick-actions small {
    margin-bottom: 5px;
    color: var(--faint);
    font: 500 9.5px/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.quick-actions strong {
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ─────────────────────────────────────────────────────────
   FORMS
───────────────────────────────────────────────────────── */
.form-panel {
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
}

.panel-body {
    display: grid;
    gap: 24px;
    padding: 32px;
}

/* Mode switches */
.mode-switch,
.payment-switch {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 10px;
}

.mode-switch button,
.payment-switch button,
.ai-actions button {
    min-height: 50px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-3);
    color: var(--muted);
    font: 600 12px/1 var(--mono);
    letter-spacing: 0.02em;
    transition: 180ms ease;
}

.mode-switch button:hover,
.payment-switch button:hover {
    border-color: var(--line-glow);
    color: var(--text);
}

.mode-switch button.active,
.payment-switch button.active {
    border-color: var(--line-glow);
    background: linear-gradient(135deg,
        rgba(58,159,255,0.20) 0%,
        rgba(139,124,255,0.10) 100%);
    color: var(--text);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.07), var(--glow-blue);
}

.mode-switch i { margin: 0 7px; color: var(--blue-bright); }

/* Fields */
.field,
.field-group { display: grid; gap: 10px; }

.field > span:first-child,
.group-label {
    color: var(--muted);
    font: 500 10.5px/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.input-shell {
    position: relative;
    display: block;
}

.input-shell > i {
    position: absolute;
    top: 50%;
    left: 16px;
    z-index: 1;
    color: var(--faint);
    font-size: 13px;
    transform: translateY(-50%);
    pointer-events: none;
    transition: color 180ms ease;
}

.input-shell input {
    width: 100%;
    height: 54px;
    padding: 0 16px 0 46px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-3);
    color: var(--text);
    font: 500 14.5px/1 var(--mono);
    transition: 200ms ease;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
    -webkit-appearance: none;
    appearance: none;
}

.input-shell input::placeholder { color: var(--faint); }

.input-shell input:focus {
    border-color: rgba(82,160,255,0.60);
    box-shadow: 0 0 0 4px var(--blue-soft), 0 0 28px rgba(58,159,255,0.12);
    outline: 0;
    background: rgba(10,14,25,0.98);
}

.input-shell input:focus + i,
.input-shell:focus-within > i { color: var(--blue-bright); }

body.theme-light .input-shell input:focus { background: #ffffff; }

.input-shell input.error { border-color: var(--danger); }

.field-error {
    display: none;
    color: var(--danger);
    font-size: 11.5px;
}

.field-error.show { display: block; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 16px;
}

/* Payment selector */
.payment-switch button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.payment-mark {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 8px;
    color: white;
    font: 700 11px/1 var(--font);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.payment-mark.alipay { background: linear-gradient(145deg, #3d8fff, #1677ff); }
.payment-mark.wechat { background: linear-gradient(145deg, #2fd47a, #08b75b); }

/* Primary CTA Button */
.primary-button {
    position: relative;
    display: flex;
    width: 100%;
    min-height: 54px;
    align-items: center;
    justify-content: center;
    gap: 11px;
    padding: 0 24px;
    border: 0;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, #2f9bff 0%, #4d7dff 45%, #3dd68c 140%);
    color: white;
    font-size: 13.5px;
    font-weight: 750;
    letter-spacing: 0.02em;
    box-shadow:
        0 14px 36px rgba(47,155,255,0.35),
        inset 0 1px 0 rgba(255,255,255,0.28);
    transition: 220ms cubic-bezier(0.22,1,0.36,1);
    overflow: hidden;
}

.primary-button::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg,
        transparent 38%,
        rgba(255,255,255,0.20) 50%,
        transparent 62%);
    transform: translateX(-120%);
    transition: transform 0.55s ease;
    pointer-events: none;
}

.primary-button:hover {
    transform: translateY(-3px);
    box-shadow:
        0 18px 44px rgba(47,155,255,0.44),
        inset 0 1px 0 rgba(255,255,255,0.32);
    filter: brightness(1.06);
}

.primary-button:hover::after { transform: translateX(120%); }

.primary-button:disabled {
    cursor: not-allowed;
    opacity: 0.44;
    transform: none;
    filter: none;
    box-shadow: none;
}

/* Calculator result */
.calculation-result {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: linear-gradient(180deg, rgba(58,159,255,0.06) 0%, var(--surface-3) 100%);
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.calculation-result > div {
    padding: 20px;
    border-right: 1px solid var(--line);
}

.calculation-result > div:last-child { border-right: 0; }

.calculation-result span,
.calculation-result strong { display: block; }

.calculation-result span {
    margin-bottom: 10px;
    color: var(--faint);
    font: 500 9.5px/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.calculation-result strong {
    overflow: hidden;
    font: 600 13.5px/1.25 var(--mono);
    text-overflow: ellipsis;
}

.calculation-result .result-primary {
    background: linear-gradient(180deg, rgba(61,214,140,0.08) 0%, transparent 100%);
}

.calculation-result .result-primary strong {
    color: var(--green);
    font-size: 15px;
}

/* Watch current */
.watch-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: linear-gradient(135deg, rgba(58,159,255,0.10) 0%, var(--surface-3) 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.watch-current span { color: var(--muted); font-size: 12px; }

.watch-current strong {
    font: 700 22px/1 var(--mono);
    background: linear-gradient(135deg, #fff, #9eceff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.theme-light .watch-current strong {
    background: none;
    -webkit-text-fill-color: var(--text);
}

/* Protocol panel */
.protocol-panel { align-self: start; }

.protocol-list { padding: 8px 18px; }

.protocol-list > div {
    display: grid;
    grid-template-columns: auto 1fr auto;
    min-height: 54px;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 12px;
}

.protocol-list > div:last-child { border-bottom: 0; }

.protocol-list strong {
    color: var(--text);
    font: 600 9.5px/1 var(--mono);
    letter-spacing: 0.07em;
}

/* Footer */
.workspace-footer {
    display: flex;
    max-width: 1200px;
    width: 100%;
    margin: auto auto 0;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 0;
    border-top: 1px solid var(--line);
    color: var(--faint);
    font: 500 9.5px/1.3 var(--mono);
    letter-spacing: 0.11em;
}

.mobile-nav { display: none; }

/* ─────────────────────────────────────────────────────────
   MODALS
───────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    padding: 20px;
    background: rgba(2,4,10,0.75);
    backdrop-filter: blur(18px) saturate(130%);
}

.modal-overlay.active { display: grid; }

.modal-card {
    position: relative;
    width: min(460px, 100%);
    padding: 38px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-xl);
    background: linear-gradient(165deg,
        rgba(18,24,40,0.97) 0%,
        rgba(10,14,24,0.99) 100%);
    box-shadow:
        0 48px 120px rgba(0,0,0,0.60),
        var(--glow-blue);
    animation: modal-pop 240ms cubic-bezier(0.22,1,0.36,1) both;
    overflow: hidden;
}

.modal-card::before {
    content: "";
    position: absolute;
    top: 0; left: 14%; right: 14%;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(82,160,255,0.65) 50%,
        transparent 100%);
    pointer-events: none;
}

body.theme-light .modal-card {
    background: linear-gradient(165deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 0 36px 80px rgba(15,25,50,0.18), var(--glow-blue);
}

@keyframes modal-pop {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
    position: absolute;
    top: 16px; right: 16px;
    display: grid;
    width: 36px; height: 36px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface-3);
    color: var(--muted);
    transition: 160ms ease;
}

.modal-close:hover {
    color: var(--text);
    border-color: var(--line-strong);
}

.modal-logo {
    display: grid;
    width: 58px; height: 58px;
    margin-bottom: 24px;
    place-items: center;
    border: 1px solid rgba(61,214,140,0.32);
    border-radius: 16px;
    background: var(--green-soft);
    color: var(--green);
    font-size: 22px;
    box-shadow: var(--glow-green);
}

.modal-card h2 {
    margin: 10px 0 12px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.035em;
}

.modal-card p {
    margin: 0 0 28px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.70;
    white-space: pre-line;
}

/* AI Modal */
.ai-modal-card { width: min(560px, 100%); }

.ai-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-right: 36px;
}

.ai-header h2 { margin-bottom: 0; }

.ai-chip {
    display: grid;
    width: 54px; height: 54px;
    flex: 0 0 54px;
    place-items: center;
    border: 1px solid rgba(82,160,255,0.32);
    border-radius: 16px;
    background: linear-gradient(145deg,
        rgba(58,159,255,0.22) 0%,
        rgba(139,124,255,0.12) 100%);
    color: var(--blue-bright);
    box-shadow: var(--glow-blue);
    font-size: 18px;
}

.ai-agent-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 22px 0 10px;
    color: var(--muted);
    font: 500 10.5px/1 var(--mono);
}

.ai-response {
    min-height: 140px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-3);
    color: var(--muted);
    font-size: 14px;
    line-height: 1.72;
    white-space: pre-wrap;
}

.ai-actions {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 10px;
    margin-top: 14px;
}

.ai-actions button:hover {
    border-color: var(--line-glow);
    color: var(--blue-bright);
    background: var(--blue-soft);
}

/* App notifications */
.app-notification {
    position: fixed;
    top: 24px;
    left: 50%;
    z-index: 200;
    max-width: min(440px, calc(100vw - 32px));
    padding: 14px 20px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-solid);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 13px;
    transform: translateX(-50%);
    backdrop-filter: blur(22px);
}

.app-notification.success { border-color: rgba(61,214,140,0.42); }
.app-notification.error   { border-color: rgba(255,96,112,0.48); }

.mr-1 { margin-right: 4px; }

/* ─────────────────────────────────────────────────────────
   RESPONSIVE — TABLET  ≤ 960px
───────────────────────────────────────────────────────── */
@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar { display: none; }

    .workspace {
        grid-column: 1;
        padding: 0 24px calc(var(--mobnav-h) + 20px);
        min-height: 100dvh;
    }

    .topbar {
        margin: 0 -24px;
        padding: 0 24px;
    }

    .rate-layout,
    .watch-layout {
        grid-template-columns: 1fr;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }

    /* Mobile nav */
    .mobile-nav {
        position: fixed;
        right: 12px;
        bottom: 12px;
        left: 12px;
        z-index: 50;
        display: grid;
        width: auto;
        min-width: 0;
        grid-template-columns: repeat(4, minmax(0,1fr));
        padding: 8px;
        border: 1px solid var(--line);
        border-radius: 22px;
        background: rgba(10,14,24,0.90);
        box-shadow:
            0 24px 60px rgba(0,0,0,0.50),
            inset 0 1px 0 rgba(255,255,255,0.05);
        backdrop-filter: blur(28px) saturate(160%);
        height: var(--mobnav-h);
    }

    body.theme-light .mobile-nav {
        background: rgba(255,255,255,0.94);
        box-shadow: 0 18px 44px rgba(15,25,50,0.12), inset 0 1px 0 rgba(255,255,255,0.80);
    }

    .mobile-nav button {
        display: grid;
        min-width: 0;
        min-height: 56px;
        place-items: center;
        gap: 4px;
        border: 0;
        border-radius: 16px;
        background: transparent;
        color: var(--faint);
        transition: 180ms ease;
    }

    .mobile-nav button.active {
        background: linear-gradient(145deg,
            rgba(58,159,255,0.22) 0%,
            rgba(61,214,140,0.08) 100%);
        color: var(--blue-bright);
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.07);
    }

    .mobile-nav i { font-size: 16px; }

    .mobile-nav span {
        font-size: 9.5px;
        font-weight: 600;
        letter-spacing: 0.02em;
    }
}

/* ─────────────────────────────────────────────────────────
   RESPONSIVE — MOBILE  ≤ 640px
───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    :root { --topbar-h: 62px; }

    .workspace {
        padding-right: 16px;
        padding-left: 16px;
    }

    .topbar {
        margin: 0 -16px;
        padding: 0 16px;
    }

    .topbar-meta { display: none; }

    .mobile-tools {
        display: flex;
        flex: 0 0 auto;
        gap: 7px;
    }

    .mobile-tools button {
        display: grid;
        width: 38px; height: 38px;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 11px;
        background: var(--surface);
        color: var(--muted);
        font: 600 10px/1 var(--mono);
        backdrop-filter: blur(12px);
        transition: 160ms ease;
    }

    .mobile-tools button:hover {
        border-color: var(--line-glow);
        color: var(--blue-bright);
    }

    .mobile-weather {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        margin-top: 8px;
        padding: 0 10px;
        height: 26px;
        border: 1px solid var(--line);
        border-radius: 999px;
        background: var(--surface);
        color: var(--muted);
        font: 500 10px/1 var(--mono);
    }

    .section { padding: 20px 0; }

    .panel-heading {
        min-height: 48px;
        padding: 0 16px;
        font-size: 10px;
    }

    .panel-code { display: none; }

    .rate-core {
        min-height: 220px;
        padding: 32px 18px 26px;
    }

    .rate-value-row {
        display: block;
    }

    .rate-value-row > strong {
        font-size: clamp(42px,12.5vw,62px);
        white-space: normal;
        overflow-wrap: anywhere;
    }

    #rate-trend-indicator {
        display: inline-block;
        margin-top: 16px;
    }

    .metric-strip { grid-template-columns: 1fr; }

    .metric-cell {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .metric-cell:last-child { border-bottom: 0; }

    .panel-body { padding: 20px 16px; }

    .form-grid,
    .calculation-result { grid-template-columns: 1fr; }

    .calculation-result > div {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .calculation-result > div:last-child { border-bottom: 0; }

    .workspace-footer { display: none; }

    .modal-card {
        padding: 28px 22px 24px;
        border-radius: 24px;
    }

    .ai-modal-card { padding: 28px 20px 22px; }

    .quick-actions button {
        grid-template-columns: 40px 1fr auto;
        min-height: 72px;
        gap: 12px;
        padding: 0 14px;
    }

    .quick-actions button > i:first-child {
        width: 40px; height: 40px;
        font-size: 14px;
    }
}

/* ─── Critical mobile scroll fix ────────────────────────── */
/* Ensure the page scrolls correctly on all mobile browsers  */
html, body {
    overflow-x: hidden;
}

@media (max-width: 960px) {
    /* body must scroll freely — NOT overflow:hidden */
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        min-height: 100dvh;
    }

    /* workspace grows with content, never clips */
    .workspace {
        overflow: visible;
        height: auto;
    }

    /* modals use fixed positioning, safe */
    .modal-overlay {
        position: fixed;
    }

    /* prevent horizontal overflow from wide content */
    .section,
    .terminal-panel,
    .quick-actions button {
        max-width: 100%;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* rate value should shrink instead of overflow */
    .rate-value-row > strong {
        overflow-wrap: anywhere;
        word-break: break-all;
    }
}

/* ─── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,*::before,*::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

