/* ==========================================================================
       IMPECCABLE DESIGN SYSTEM (IYL LIVING LEDGER + TERMINAL DARK + HIGH CONTRAST)
       Mobile-First · Tokenized Spacing · WCAG AAA Contrast · Zero Horizontal Bleed
       ========================================================================== */
    :root {
      /* Mode 1: Warm Editorial Ledger (Default) */
      --bg-canvas: #f6f3ec;
      --bg-card: #ffffff;
      --bg-card-sub: #faf8f3;
      --bg-muted: #ebe6dc;
      --bg-topbar: #112b31;
      --bg-topbar-sub: #16363e;
      --bg-popover: #112b31;

      --ink-primary: #112b31;
      --ink-secondary: #35464a;
      --ink-muted: #5a6b70;
      --ink-inverse: #fff8ed;
      --ink-popover: #f8fafc;

      --accent-brand: #e04826;
      --accent-brand-soft: rgba(224, 72, 38, 0.12);
      --accent-teal: #1c5d66;
      --accent-teal-soft: rgba(28, 93, 102, 0.12);
      --accent-gold: #c9982b;
      --accent-gold-soft: rgba(201, 152, 43, 0.16);

      /* Traffic Light Semantic Tokens (Red=4B, Orange=4A, Yellow=3, Green=Others) */
      --st-green: #10b981;
      --st-green-ink: #065f46;
      --st-green-bg: rgba(16, 185, 129, 0.13);
      --st-green-bd: rgba(16, 185, 129, 0.38);

      --st-yellow: #eab308;
      --st-yellow-ink: #854d0e;
      --st-yellow-bg: rgba(234, 179, 8, 0.15);
      --st-yellow-bd: rgba(234, 179, 8, 0.45);

      --st-orange: #f97316;
      --st-orange-ink: #9a3412;
      --st-orange-bg: rgba(249, 115, 22, 0.14);
      --st-orange-bd: rgba(249, 115, 22, 0.42);

      --st-red: #ef4444;
      --st-red-ink: #991b1b;
      --st-red-bg: rgba(239, 68, 68, 0.14);
      --st-red-bd: rgba(239, 68, 68, 0.42);

      --border-subtle: rgba(17, 43, 49, 0.13);
      --border-strong: rgba(17, 43, 49, 0.24);
      --shadow-card: 0 2px 10px rgba(17, 43, 49, 0.05);
      --shadow-hover: 0 8px 22px rgba(17, 43, 49, 0.10);
      --shadow-pop: 0 14px 34px rgba(8, 21, 24, 0.35);

      --font-display: "Playfair Display", Georgia, serif;
      --font-sans: "Manrope", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      --font-mono: "DM Mono", "SF Mono", Menlo, Consolas, monospace;

      --scale: 1;
      --radius-sm: 6px;
      --radius-md: 10px;
      --radius-lg: 14px;
    }

    html[data-theme="dark"] {
      --bg-canvas: #0b1116;
      --bg-card: #121b22;
      --bg-card-sub: #17232c;
      --bg-muted: #1e2d38;
      --bg-topbar: #080d11;
      --bg-topbar-sub: #121b22;
      --bg-popover: #1c2934;

      --ink-primary: #f1f5f9;
      --ink-secondary: #cbd5e1;
      --ink-muted: #8b9bb0;
      --ink-inverse: #f8fafc;
      --ink-popover: #f8fafc;

      --accent-brand: #ff6b4a;
      --accent-brand-soft: rgba(255, 107, 74, 0.16);
      --accent-teal: #38bdf8;
      --accent-teal-soft: rgba(56, 189, 248, 0.15);
      --accent-gold: #fbbf24;
      --accent-gold-soft: rgba(251, 191, 36, 0.16);

      --st-green: #10b981;
      --st-green-ink: #6ee7b7;
      --st-green-bg: rgba(16, 185, 129, 0.16);
      --st-green-bd: rgba(16, 185, 129, 0.42);

      --st-yellow: #eab308;
      --st-yellow-ink: #fde047;
      --st-yellow-bg: rgba(234, 179, 8, 0.16);
      --st-yellow-bd: rgba(234, 179, 8, 0.42);

      --st-orange: #f97316;
      --st-orange-ink: #fdba74;
      --st-orange-bg: rgba(249, 115, 22, 0.18);
      --st-orange-bd: rgba(249, 115, 22, 0.45);

      --st-red: #ef4444;
      --st-red-ink: #fca5a5;
      --st-red-bg: rgba(239, 68, 68, 0.18);
      --st-red-bd: rgba(239, 68, 68, 0.45);

      --border-subtle: rgba(255, 255, 255, 0.10);
      --border-strong: rgba(255, 255, 255, 0.22);
      --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);
      --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.5);
    }

    html[data-theme="contrast"] {
      --bg-canvas: #fffdf5;
      --bg-card: #ffffff;
      --bg-card-sub: #f7f3d7;
      --bg-muted: #ede6be;
      --bg-topbar: #09191d;
      --bg-topbar-sub: #112b31;
      --bg-popover: #09191d;

      --ink-primary: #09191d;
      --ink-secondary: #112b31;
      --ink-muted: #243b41;
      --ink-inverse: #ffffff;
      --ink-popover: #ffffff;

      --st-green-ink: #044e3a;
      --st-yellow-ink: #6b3c05;
      --st-orange-ink: #7c280c;
      --st-red-ink: #7f1414;

      --border-subtle: #112b31;
      --border-strong: #09191d;
    }

    html[data-font="normal"] { --scale: 1; }
    html[data-font="large"] { --scale: 1.12; }
    html[data-font="xlarge"] { --scale: 1.24; }

    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
    }

    html {
      font-size: calc(15.5px * var(--scale));
      scroll-behavior: smooth;
      -webkit-text-size-adjust: 100%;
    }

    body {
      background: var(--bg-canvas);
      color: var(--ink-primary);
      font-family: var(--font-sans);
      line-height: 1.55;
      min-height: 100vh;
      padding-bottom: 48px;
      overflow-x: hidden;
      transition: background 0.2s ease, color 0.2s ease;
    }

    /* ==========================================================================
       1. STICKY TOPBAR & MOBILE SPACE-SAVING STYLES
       ========================================================================== */
    .topbar {
      position: sticky;
      top: 0;
      z-index: 100;
      background: var(--bg-topbar);
      color: var(--ink-inverse);
      border-bottom: 2px solid var(--accent-gold);
      box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
      padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    }

    .topbar-inner {
      max-width: 1180px;
      margin: 0 auto;
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 8px;
      flex-wrap: wrap;
    }

    .brand-cluster {
      display: flex;
      align-items: center;
      gap: 9px;
      min-width: 0;
    }

    .app-logo-wrap {
      width: 36px;
      height: 36px;
      border-radius: 9px;
      overflow: hidden;
      flex-shrink: 0;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
      border: 1px solid rgba(201, 152, 43, 0.55);
      display: flex;
      align-items: center;
      justify-content: center;
      background: #112b31;
      cursor: pointer;
    }

    .app-logo-wrap svg {
      width: 100%;
      height: 100%;
      display: block;
    }

    .brand-titles {
      display: flex;
      flex-direction: column;
      min-width: 0;
    }

    .brand-kicker {
      font-family: var(--font-mono);
      font-size: 0.65rem;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      color: #fbbf24;
      line-height: 1.1;
    }

    .brand-main {
      font-family: var(--font-display);
      font-size: 1.02rem;
      font-weight: 700;
      color: #ffffff;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.2;
    }

    .topbar-actions {
      display: flex;
      align-items: flex-start;
      gap: 6px;
      flex-wrap: wrap;
    }

    /* Market Toggle (US | HK) */
    .mkt-toggle-group {
      display: inline-flex;
      height: 38px;
      background: rgba(255, 255, 255, 0.10);
      border: 1px solid rgba(255, 255, 255, 0.20);
      border-radius: 9px;
      padding: 3px;
      gap: 3px;
    }

    .mkt-btn {
      font-family: var(--font-mono);
      font-size: 0.78rem;
      font-weight: 700;
      color: rgba(255, 248, 237, 0.72);
      background: transparent;
      border: none;
      border-radius: 6px;
      padding: 5px 11px;
      min-height: 28px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: all 0.15s ease;
    }

    .mkt-btn:hover {
      color: #ffffff;
      background: rgba(255, 255, 255, 0.12);
    }

    .mkt-btn.active {
      background: var(--accent-brand);
      color: #ffffff;
      box-shadow: 0 2px 8px rgba(224, 72, 38, 0.4);
    }

    .mkt-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      display: inline-block;
      flex-shrink: 0;
    }

    /* General Topbar Action Buttons */
    .btn-topbar {
      font-family: var(--font-sans);
      font-size: 0.76rem;
      font-weight: 700;
      color: #fff8ed;
      background: rgba(255, 255, 255, 0.12);
      border: 1px solid rgba(255, 255, 255, 0.22);
      border-radius: 8px;
      padding: 5px 10px;
      height: 38px;
      min-height: 38px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: all 0.15s ease;
      white-space: nowrap;
    }

    .btn-topbar:hover {
      background: rgba(255, 255, 255, 0.22);
      border-color: rgba(255, 255, 255, 0.35);
    }

    .btn-topbar:active {
      transform: scale(0.97);
    }

    .btn-topbar.active-pill {
      background: rgba(201, 152, 43, 0.28);
      border-color: #fbbf24;
      color: #ffffff;
    }

    .btn-topbar.active-chart {
      background: var(--accent-teal);
      border-color: #38bdf8;
      color: #ffffff;
      box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
    }

    .btn-topbar svg {
      width: 15px;
      height: 15px;
      flex-shrink: 0;
      transition: transform 0.2s ease;
    }

    .utility-cluster {
      display: inline-flex;
      height: 38px;
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.15);
      border-radius: 8px;
      padding: 2px;
      gap: 2px;
    }

    .btn-util {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      font-weight: 700;
      color: rgba(255, 248, 237, 0.85);
      background: transparent;
      border: none;
      border-radius: 6px;
      padding: 4px 7px;
      min-height: 30px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      transition: all 0.15s ease;
    }

    .btn-util svg {
      width: 14px;
      height: 14px;
      flex-shrink: 0;
    }

    .btn-util:hover, .btn-util.active {
      background: rgba(255, 255, 255, 0.20);
      color: #ffffff;
    }

    /* Responsive Space-Saving Labels */
    .lbl-full { display: inline-block; }
    .lbl-short { display: none; }

    /* Narrow / tablet screens: compact labels & icons (US / HK / CN · Chart · All) */
    @media (max-width: 820px) {
      .lbl-full { display: none !important; }
      .lbl-short { display: inline-block !important; }
    }

    /* Very small screens: drop the market dots to free up button space */
    @media (max-width: 480px) {
      .mkt-dot { display: none !important; }
      .brand-main { display: none !important; }
    }

    /* Narrow screens: Chart & theme buttons collapse to icons only */
    @media (max-width: 640px) {
      .icon-only-sm .lbl-full,
      .icon-only-sm .lbl-short { display: none !important; }
      .icon-only-sm svg { display: block !important; }
    }

    @media (max-width: 640px) {
      .topbar {
        padding: max(6px, env(safe-area-inset-top)) 8px 6px;
      }
      .topbar-inner {
        gap: 4px;
        flex-wrap: nowrap;
      }
      .brand-cluster {
        gap: 6px;
      }
      .app-logo-wrap {
        width: 30px;
        height: 30px;
        border-radius: 7px;
      }
      .brand-kicker {
        display: none !important;
      }
      .brand-main {
        font-size: 0.88rem !important;
        letter-spacing: -0.01em;
      }
      .topbar-actions {
        gap: 3px;
        flex-wrap: nowrap;
      }
      .mkt-toggle-group {
        height: 34px;
        padding: 2px;
      }
      .mkt-btn {
        padding: 4px 6px !important;
        font-size: 0.72rem !important;
        min-height: 28px !important;
        gap: 3px !important;
      }
      .btn-topbar {
        padding: 4px 7px !important;
        height: 34px !important;
        min-height: 34px !important;
        font-size: 0.72rem !important;
        gap: 3px !important;
      }
      .utility-cluster {
        height: 34px;
      }
      .btn-util {
        padding: 2px 4px !important;
        min-height: 28px !important;
        font-size: 0.68rem !important;
      }
    }

    /* ==========================================================================
       2. MARKET CONTEXT STRIP & OVERALL PEAK ALERT BANNER
       ========================================================================== */
    .market-strip {
      background: var(--bg-topbar-sub);
      color: rgba(255, 248, 237, 0.9);
      border-bottom: 1px solid rgba(255, 255, 255, 0.12);
      padding: 7px 12px;
      font-size: 0.78rem;
    }

    .market-strip-inner {
      max-width: 1180px;
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      overflow-x: auto;
      white-space: nowrap;
      scrollbar-width: none;
    }
    .market-strip-inner::-webkit-scrollbar { display: none; }

    .strip-metrics {
      display: flex;
      align-items: center;
      gap: 14px;
    }

    .strip-item {
      display: inline-flex;
      align-items: center;
      gap: 5px;
    }

    .strip-label {
      color: rgba(255, 248, 237, 0.62);
      font-size: 0.72rem;
    }

    .strip-val {
      font-family: var(--font-mono);
      font-weight: 700;
      color: #ffffff;
    }

    .chg-up { color: #34d399; font-family: var(--font-mono); font-weight: 700; }
    .chg-dn { color: #f87171; font-family: var(--font-mono); font-weight: 700; }

    .container {
      max-width: 1180px;
      margin: 16px auto 0;
      padding: 0 12px;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    
    /* Index Rotator Button in Hero Card */
    .index-pill-btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      background: var(--bg-card);
      border: 1.5px solid var(--accent-brand);
      color: var(--accent-brand);
      border-radius: 999px;
      padding: 4px 12px;
      font-family: var(--font-mono);
      font-size: 0.78rem;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 1px 3px rgba(0,0,0,0.12);
      transition: all 0.18s ease;
      user-select: none;
    }
    .index-pill-btn:hover {
      background: var(--accent-brand);
      color: #0d1e23;
      transform: translateY(-1px);
      box-shadow: 0 3px 10px rgba(201, 152, 43, 0.35);
    }
    .index-pill-btn:active {
      transform: translateY(0);
    }
    .index-rotate-icon {
      font-size: 0.90rem;
      font-weight: 900;
      line-height: 1;
      display: inline-block;
      transition: transform 0.25s ease;
    }
    .index-pill-btn:hover .index-rotate-icon {
      transform: rotate(180deg);
    }

    
    .hero-peak-off {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      font-weight: 700;
      padding: 2px 8px;
      border-radius: 5px;
      display: inline-flex;
      align-items: center;
      line-height: 1.2;
      transition: all 0.2s ease;
    }
    /* >15% is red, >8% is orange, >3% is yellow, else green */
    .hero-peak-off.peak-red {
      color: #ef4444;
      background: rgba(239, 68, 68, 0.12);
      border: 1px solid rgba(239, 68, 68, 0.38);
    }
    .hero-peak-off.peak-orange {
      color: #f97316;
      background: rgba(249, 115, 22, 0.12);
      border: 1px solid rgba(249, 115, 22, 0.38);
    }
    .hero-peak-off.peak-yellow {
      color: #eab308;
      background: rgba(234, 179, 8, 0.12);
      border: 1px solid rgba(234, 179, 8, 0.38);
    }
    .hero-peak-off.peak-green {
      color: #10b981;
      background: rgba(16, 185, 129, 0.12);
      border: 1px solid rgba(16, 185, 129, 0.38);
    }
    [data-theme="dark"] .hero-peak-off.peak-red {
      color: #fca5a5;
      background: rgba(239, 68, 68, 0.20);
      border-color: rgba(239, 68, 68, 0.50);
    }
    [data-theme="dark"] .hero-peak-off.peak-orange {
      color: #fdba74;
      background: rgba(249, 115, 22, 0.20);
      border-color: rgba(249, 115, 22, 0.50);
    }
    [data-theme="dark"] .hero-peak-off.peak-yellow {
      color: #fef08a;
      background: rgba(234, 179, 8, 0.20);
      border-color: rgba(234, 179, 8, 0.50);
    }
    [data-theme="dark"] .hero-peak-off.peak-green {
      color: #6ee7b7;
      background: rgba(16, 185, 129, 0.20);
      border-color: rgba(16, 185, 129, 0.50);
    }
    .st-bg-grey {
      background: #64748b !important;
    }
    [data-theme="dark"] .st-bg-grey {
      background: #475569 !important;
    }
    [data-theme="contrast"] .st-bg-grey {
      background: #4b5563 !important;
    }

    /* Overall Market Peak Status Hero Card */
    .status-hero {
      background: var(--bg-card);
      border: 1.5px solid var(--border-subtle);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-card);
      padding: 16px;
      display: grid;
      grid-template-columns: 1fr;
      gap: 14px;
      position: relative;
      overflow: hidden;
    }

    @media (min-width: 820px) {
      .status-hero {
        grid-template-columns: 1.35fr 1fr;
        align-items: center;
        padding: 18px 22px;
      }
    }

    .status-hero-left {
      display: flex;
      align-items: flex-start;
      gap: 14px;
    }

    /* Traffic Light Housing */
    .traffic-pillar {
      background: #0d1b20;
      border: 2px solid #2b4249;
      border-radius: 24px;
      padding: 7px 6px;
      display: flex;
      flex-direction: column;
      gap: 6px;
      flex-shrink: 0;
      box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
    }

    .tl-bulb {
      width: 16px;
      height: 16px;
      border-radius: 50%;
      opacity: 0.22;
      transition: all 0.25s ease;
    }
    .tl-bulb.red { background: #ef4444; }
    .tl-bulb.orange { background: #f97316; }
    .tl-bulb.yellow { background: #eab308; }
    .tl-bulb.green { background: #10b981; }

    .tl-bulb.lit.red {
      opacity: 1;
      box-shadow: 0 0 12px #ef4444, 0 0 4px #ffffff;
    }
    .tl-bulb.lit.orange {
      opacity: 1;
      box-shadow: 0 0 12px #f97316, 0 0 4px #ffffff;
    }
    .tl-bulb.lit.yellow {
      opacity: 1;
      box-shadow: 0 0 12px #eab308, 0 0 4px #ffffff;
    }
    .tl-bulb.lit.green {
      opacity: 1;
      box-shadow: 0 0 12px #10b981, 0 0 4px #ffffff;
    }

    .hero-copy {
      flex: 1;
      min-width: 0;
    }

    .hero-kicker-row {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      margin-bottom: 4px;
    }

    .stage-pill-lg {
      font-family: var(--font-mono);
      font-size: 0.74rem;
      font-weight: 700;
      padding: 3px 10px;
      border-radius: 999px;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    .stage-pill-lg.st-4B { background: var(--st-red-bg); color: var(--st-red-ink); border: 1px solid var(--st-red-bd); }
    .stage-pill-lg.st-4A { background: var(--st-orange-bg); color: var(--st-orange-ink); border: 1px solid var(--st-orange-bd); }
    .stage-pill-lg.st-3  { background: var(--st-yellow-bg); color: var(--st-yellow-ink); border: 1px solid var(--st-yellow-bd); }
    .stage-pill-lg.st-G  { background: var(--st-green-bg); color: var(--st-green-ink); border: 1px solid var(--st-green-bd); }

    .hero-title {
      font-family: var(--font-display);
      font-size: 1.25rem;
      font-weight: 700;
      line-height: 1.25;
      margin-bottom: 6px;
    }

    .hero-summary {
      font-size: 0.86rem;
      color: var(--ink-secondary);
      line-height: 1.5;
    }

    /* Right side KPI Tally Grid */
    .hero-tally-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 8px;
    }

    .tally-box {
      background: var(--bg-card-sub);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      padding: 9px 8px;
      text-align: center;
      cursor: pointer;
      transition: all 0.15s ease;
    }

    .tally-box:hover {
      border-color: var(--border-strong);
      transform: translateY(-1px);
    }

    .tally-box.active-filter {
      outline: 2px solid var(--accent-brand);
      background: var(--bg-card);
    }

    .tally-count {
      font-family: var(--font-mono);
      font-size: 1.25rem;
      font-weight: 700;
      line-height: 1.1;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 5px;
    }

    .tally-lbl {
      font-size: 0.68rem;
      font-weight: 700;
      color: var(--ink-muted);
      margin-top: 3px;
      display: block;
      text-transform: uppercase;
      letter-spacing: 0.03em;
    }

    /* ==========================================================================
       3. NON-MODAL STOCK CHART DIALOG (DESKTOP DRAGGABLE & MOBILE 40VH ANCHORED)
       ========================================================================== */
    .chart-dialog {
      position: fixed;
      z-index: 95;
      width: min(650px, 94vw);
      height: 440px;
      top: 75px;
      right: 20px;
      background: var(--bg-card);
      border: 1.5px solid var(--border-strong);
      border-radius: 14px;
      box-shadow: 0 16px 44px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.08);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      touch-action: none;
    }

    .chart-dlg-header {
      background: var(--bg-topbar);
      color: var(--ink-inverse);
      padding: 8px 12px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      flex-wrap: wrap;
      border-bottom: 1px solid rgba(255, 255, 255, 0.15);
      cursor: grab;
      user-select: none;
      -webkit-user-select: none;
    }
    .chart-dialog.dragging .chart-dlg-header {
      cursor: grabbing;
    }

    .chart-drag-handle {
      color: rgba(255, 255, 255, 0.45);
      font-size: 1rem;
      line-height: 1;
      letter-spacing: -2px;
      margin-right: 4px;
      flex-shrink: 0;
    }

    .chart-dlg-title-group {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 0;
    }

    .chart-dlg-title {
      font-family: var(--font-display);
      font-size: 0.96rem;
      font-weight: 700;
      color: #ffffff;
      white-space: nowrap;
    }
    .chart-dlg-subtitle {
      font-size: 0.68rem;
      color: rgba(255, 248, 237, 0.65);
      line-height: 1;
    }

    .chart-dlg-badge {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      font-weight: 700;
      padding: 2px 7px;
      border-radius: 5px;
      white-space: nowrap;
    }

    .chart-dlg-actions {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .btn-chart-ctl {
      font-family: var(--font-sans);
      font-size: 0.73rem;
      font-weight: 700;
      color: var(--ink-inverse);
      background: rgba(255, 255, 255, 0.12);
      border: 1px solid rgba(255, 255, 255, 0.22);
      border-radius: 6px;
      padding: 4px 8px;
      min-height: 28px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: all 0.15s ease;
    }
    .btn-chart-ctl:hover {
      background: rgba(255, 255, 255, 0.22);
    }
    .btn-chart-ctl.active {
      background: var(--accent-teal);
      border-color: #38bdf8;
      color: #ffffff;
      box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
    }
    .ctl-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: #94a3b8;
      display: inline-block;
    }
    .btn-chart-ctl.active .ctl-dot {
      background: #34d399;
      box-shadow: 0 0 6px #34d399;
    }

    .btn-chart-close {
      background: transparent;
      border: none;
      color: rgba(255, 255, 255, 0.7);
      font-size: 1.15rem;
      line-height: 1;
      padding: 2px 6px;
      cursor: pointer;
      border-radius: 4px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }
    .btn-chart-close:hover {
      background: rgba(239, 68, 68, 0.3);
      color: #ffffff;
    }

    .chart-stats-bar {
      background: var(--bg-card-sub);
      border-bottom: 1px solid var(--border-subtle);
      padding: 5px 10px;
      font-family: var(--font-mono);
      font-size: 0.70rem;
      color: var(--ink-secondary);
      display: flex;
      align-items: center;
      gap: 8px;
      overflow-x: auto;
      white-space: nowrap;
      scrollbar-width: none;
    }
    .chart-stats-bar::-webkit-scrollbar { display: none; }

    .chart-canvas-wrap {
      flex: 1;
      position: relative;
      width: 100%;
      min-height: 180px;
      background: #080d11;
    }
    #chartCanvas {
      display: block;
      width: 100%;
      height: 100%;
      cursor: crosshair;
    }

    /* Mobile Rule: Fix to 40vh, anchor to 50th to 90th percentile of screen */
    @media (max-width: 640px) {
      .chart-dialog {
        position: fixed !important;
        top: 50vh !important;
        height: 40vh !important;
        bottom: 10vh !important;
        left: 2vw !important;
        right: 2vw !important;
        width: 96vw !important;
        max-width: none !important;
        transform: none !important;
        border-radius: 12px !important;
        z-index: 105 !important;
        box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6) !important;
      }
      .chart-drag-handle {
        display: none !important;
      }
      .chart-dlg-header {
        cursor: default !important;
        padding: 6px 10px !important;
      }
      .chart-dlg-subtitle {
        display: none !important;
      }
      .chart-stats-bar {
        font-size: 0.65rem !important;
        padding: 3px 8px !important;
      }
    }

    /* ==========================================================================
       4. 210-TRADING-DAY / 30-WEEK HISTORY PANEL (OVERALL + ALL 14 INDICATORS)
       ========================================================================== */
    .panel-card {
      background: var(--bg-card);
      border: 1.5px solid var(--border-subtle);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-card);
      overflow: hidden;
    }

    .panel-header {
      padding: 13px 16px;
      border-bottom: 1px solid var(--border-subtle);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      flex-wrap: wrap;
      background: var(--bg-card-sub);
    }

    .panel-title-wrap {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }

    .panel-title {
      font-family: var(--font-display);
      font-size: 1.02rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .panel-controls {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }

    .seg-group {
      display: inline-flex;
      background: var(--bg-muted);
      border: 1px solid var(--border-subtle);
      border-radius: 8px;
      padding: 2px;
      gap: 2px;
    }

    .seg-btn {
      font-family: var(--font-sans);
      font-size: 0.74rem;
      font-weight: 700;
      color: var(--ink-secondary);
      background: transparent;
      border: none;
      border-radius: 6px;
      padding: 4px 10px;
      min-height: 28px;
      cursor: pointer;
      transition: all 0.15s ease;
    }

    .seg-btn.active {
      background: var(--bg-card);
      color: var(--ink-primary);
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    }

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

    /* Legend & Scrubber Readout Bar */
    .history-meta-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      flex-wrap: wrap;
      margin-bottom: 10px;
      font-size: 0.76rem;
    }

    .legend-cluster {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

    .legend-item {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      font-weight: 600;
      color: var(--ink-secondary);
    }

    .legend-swatch {
      width: 10px;
      height: 10px;
      border-radius: 3px;
      display: inline-block;
    }
    .sw-red    { background: var(--st-red); }
    .sw-orange { background: var(--st-orange); }
    .sw-yellow { background: var(--st-yellow); }
    .sw-green  { background: var(--st-green); }

    .scrubber-readout {
      font-family: var(--font-mono);
      font-size: 0.74rem;
      background: var(--bg-card-sub);
      border: 1px solid var(--border-subtle);
      border-radius: 6px;
      padding: 4px 9px;
      color: var(--ink-primary);
    }

    /* Overall History Strip */
    .overall-strip-wrap {
      overflow-x: auto;
      padding-bottom: 6px;
      -webkit-overflow-scrolling: touch;
    }
    .overall-strip-wrap::-webkit-scrollbar,
    .matrix-scroll-wrap::-webkit-scrollbar {
      height: 6px;
    }
    .overall-strip-wrap::-webkit-scrollbar-thumb,
    .matrix-scroll-wrap::-webkit-scrollbar-thumb {
      background: rgba(100, 116, 139, 0.4);
      border-radius: 4px;
    }

    .overall-strip-row {
      display: flex;
      gap: 2px;
      min-width: max-content;
      align-items: flex-end;
    }

    .hist-cell {
      width: 10px;
      height: 28px;
      border-radius: 2px;
      cursor: pointer;
      transition: transform 0.1s ease, opacity 0.15s ease;
      position: relative;
      flex-shrink: 0;
    }

    .hist-cell.weekly-cell {
      width: 24px;
      height: 30px;
      border-radius: 4px;
    }

    .hist-cell.mobile-daily-cell {
      width: 12px;
      height: 28px;
    }

    .hist-cell:hover, .hist-cell.selected-day {
      transform: scaleY(1.18);
      outline: 2px solid var(--ink-primary);
      z-index: 5;
    }

    .st-bg-4B { background: var(--st-red); }
    .st-bg-4A { background: var(--st-orange); }
    .st-bg-3  { background: var(--st-yellow); }
    .st-bg-G  { background: var(--st-green); }

    .axis-dates {
      display: flex;
      justify-content: space-between;
      font-family: var(--font-mono);
      font-size: 0.68rem;
      color: var(--ink-muted);
      margin-top: 4px;
    }

    /* All-14-Indicators Heatmap Matrix */
    .matrix-toggle-bar {
      margin-top: 12px;
      padding-top: 10px;
      border-top: 1px dashed var(--border-subtle);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      flex-wrap: wrap;
    }

    .btn-matrix-toggle {
      font-family: var(--font-sans);
      font-size: 0.78rem;
      font-weight: 700;
      color: var(--accent-teal);
      background: var(--accent-teal-soft);
      border: 1px solid rgba(28, 93, 102, 0.3);
      border-radius: 7px;
      padding: 5px 11px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      transition: all 0.15s ease;
    }
    html[data-theme="dark"] .btn-matrix-toggle {
      color: #38bdf8;
      border-color: rgba(56, 189, 248, 0.35);
    }

    .matrix-scroll-wrap {
      margin-top: 10px;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      background: var(--bg-card-sub);
    }

    .matrix-table {
      border-collapse: collapse;
      width: max-content;
      min-width: 100%;
      font-size: 0.73rem;
    }

    .matrix-table th, .matrix-table td {
      padding: 4px 6px;
      border-bottom: 1px solid var(--border-subtle);
      vertical-align: middle;
    }

    .matrix-table tr:last-child td {
      border-bottom: none;
    }

    .matrix-sticky-col {
      position: sticky;
      left: 0;
      z-index: 4;
      background: var(--bg-card-sub);
      font-weight: 700;
      color: var(--ink-primary);
      border-right: 1px solid var(--border-subtle);
      min-width: 175px;
      max-width: 210px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .matrix-cells-strip {
      display: flex;
      gap: 2px;
      align-items: center;
    }

    .m-cell {
      width: 8px;
      height: 14px;
      border-radius: 1.5px;
      flex-shrink: 0;
      cursor: pointer;
    }
    .m-cell.weekly-m-cell {
      width: 20px;
      height: 15px;
      border-radius: 2.5px;
    }
    .m-cell.mobile-m-cell {
      width: 10px;
      height: 14px;
    }
    .m-cell:hover {
      outline: 1.5px solid var(--ink-primary);
      transform: scaleY(1.25);
    }

    /* ==========================================================================
       5. COLLAPSIBLE DETAILED DEFINITIONS & ASSESSMENT MECHANISM
       ========================================================================== */
    .mech-trigger {
      width: 100%;
      background: var(--bg-card-sub);
      border: none;
      padding: 14px 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      cursor: pointer;
      text-align: left;
      color: var(--ink-primary);
      transition: background 0.15s ease;
    }

    .mech-trigger:hover {
      background: var(--bg-muted);
    }

    .mech-trigger-left {
      display: flex;
      align-items: center;
      gap: 10px;
      min-width: 0;
    }

    .mech-badge {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      font-weight: 700;
      background: var(--accent-gold-soft);
      color: var(--ink-primary);
      border: 1px solid rgba(201, 152, 43, 0.4);
      padding: 2px 8px;
      border-radius: 6px;
      text-transform: uppercase;
      flex-shrink: 0;
    }

    .mech-body {
      border-top: 1px solid var(--border-subtle);
      padding: 16px;
      display: none;
    }

    .mech-body.open {
      display: block;
    }

    .mech-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 14px;
      margin-bottom: 16px;
    }

    @media (min-width: 820px) {
      .mech-grid {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    .mech-stage-card {
      background: var(--bg-card-sub);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      padding: 12px 14px;
    }

    .mech-stage-card h4 {
      font-size: 0.88rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 6px;
    }

    .mech-stage-card p {
      font-size: 0.8rem;
      color: var(--ink-secondary);
      margin-bottom: 6px;
    }

    .mech-rule-pill {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      background: var(--bg-card);
      border: 1px solid var(--border-subtle);
      border-radius: 6px;
      padding: 5px 8px;
      color: var(--ink-primary);
      display: block;
    }

    .def-table-wrap {
      overflow-x: auto;
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      margin-top: 12px;
    }

    .def-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.78rem;
      min-width: 680px;
    }

    .def-table th, .def-table td {
      padding: 9px 11px;
      border-bottom: 1px solid var(--border-subtle);
      text-align: left;
      vertical-align: top;
    }

    .def-table th {
      background: var(--bg-muted);
      font-family: var(--font-mono);
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--ink-secondary);
    }

    /* ==========================================================================
       6. INDICATORS GRID (PART 1: 6 MACRO & BREADTH, PART 2: 8 STAGE 3 & 4)
       ========================================================================== */
    .section-header-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      flex-wrap: wrap;
      margin-bottom: 10px;
      padding-bottom: 6px;
      border-bottom: 2px solid var(--border-subtle);
    }

    .section-title-group {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .part-num-badge {
      font-family: var(--font-mono);
      font-size: 0.74rem;
      font-weight: 700;
      background: var(--bg-topbar);
      color: #ffffff;
      padding: 3px 9px;
      border-radius: 6px;
      letter-spacing: 0.04em;
    }

    .section-title {
      font-family: var(--font-display);
      font-size: 1.12rem;
      font-weight: 700;
    }

    .section-sub {
      font-size: 0.78rem;
      color: var(--ink-muted);
    }

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

    @media (min-width: 768px) {
      .indicators-grid {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    /* Indicator Card */
    .ind-card {
      background: var(--bg-card);
      border: 1.5px solid var(--border-subtle);
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-card);
      transition: box-shadow 0.18s ease, border-color 0.18s ease;
      overflow: hidden;
      display: flex;
      flex-direction: column;
    }

    .ind-card:hover {
      box-shadow: var(--shadow-hover);
      border-color: var(--border-strong);
    }

    .ind-card.border-4B { border-left: 4.5px solid var(--st-red); }
    .ind-card.border-4A { border-left: 4.5px solid var(--st-orange); }
    .ind-card.border-3  { border-left: 4.5px solid var(--st-yellow); }
    .ind-card.border-G  { border-left: 4.5px solid var(--st-green); }

    .ind-header {
      padding: 12px 14px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      cursor: pointer;
      user-select: none;
      background: var(--bg-card);
      transition: background 0.15s ease;
    }

    .ind-header:hover {
      background: var(--bg-card-sub);
    }

    .ind-header-left {
      display: flex;
      align-items: center;
      gap: 10px;
      min-width: 0;
      flex: 1;
    }

    /* Traffic Light Dot */
    .tl-dot {
      width: 13px;
      height: 13px;
      border-radius: 50%;
      flex-shrink: 0;
    }
    .tl-dot.st-4B { background: var(--st-red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.75); }
    .tl-dot.st-4A { background: var(--st-orange); box-shadow: 0 0 8px rgba(249, 115, 22, 0.75); }
    .tl-dot.st-3  { background: var(--st-yellow); box-shadow: 0 0 8px rgba(234, 179, 8, 0.75); }
    .tl-dot.st-G  { background: var(--st-green); box-shadow: 0 0 8px rgba(16, 185, 129, 0.75); }

    .ind-title-block {
      min-width: 0;
      flex: 1;
    }

    .ind-meta-line {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-bottom: 2px;
      flex-wrap: wrap;
    }

    .ind-num {
      font-family: var(--font-mono);
      font-size: 0.67rem;
      font-weight: 700;
      color: var(--ink-muted);
    }

    .ind-cat-tag {
      font-family: var(--font-mono);
      font-size: 0.65rem;
      font-weight: 600;
      background: var(--bg-muted);
      color: var(--ink-secondary);
      padding: 1px 6px;
      border-radius: 4px;
    }

    .ind-name {
      font-size: 0.92rem;
      font-weight: 800;
      color: var(--ink-primary);
      line-height: 1.25;
    }

    .ind-quick-metric {
      font-family: var(--font-mono);
      font-size: 0.74rem;
      color: var(--ink-secondary);
      margin-top: 3px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .ind-header-right {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }

    .status-badge-sm {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      font-weight: 700;
      padding: 2px 7px;
      border-radius: 6px;
      white-space: nowrap;
    }
    .status-badge-sm.st-4B { background: var(--st-red-bg); color: var(--st-red-ink); border: 1px solid var(--st-red-bd); }
    .status-badge-sm.st-4A { background: var(--st-orange-bg); color: var(--st-orange-ink); border: 1px solid var(--st-orange-bd); }
    .status-badge-sm.st-3  { background: var(--st-yellow-bg); color: var(--st-yellow-ink); border: 1px solid var(--st-yellow-bd); }
    .status-badge-sm.st-G  { background: var(--st-green-bg); color: var(--st-green-ink); border: 1px solid var(--st-green-bd); }

    /* Info Tooltip Trigger Button */
    .btn-info-tip {
      width: 26px;
      height: 26px;
      border-radius: 50%;
      border: 1px solid var(--border-subtle);
      background: var(--bg-card-sub);
      color: var(--ink-secondary);
      font-family: var(--font-mono);
      font-size: 0.74rem;
      font-weight: 700;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: help;
      transition: all 0.15s ease;
    }

    .btn-info-tip:hover {
      background: var(--bg-topbar);
      color: #ffffff;
      border-color: var(--bg-topbar);
    }

    .chevron-icon {
      width: 18px;
      height: 18px;
      color: var(--ink-muted);
      transition: transform 0.2s ease;
    }

    .ind-card.expanded .chevron-icon {
      transform: rotate(180deg);
    }

    /* Collapsible Details Body */
    .ind-details {
      display: none;
      padding: 12px 14px 14px;
      background: var(--bg-card-sub);
      border-top: 1px solid var(--border-subtle);
      font-size: 0.82rem;
    }

    .ind-card.expanded .ind-details {
      display: block;
    }

    .kpi-highlight-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
      margin-bottom: 10px;
    }

    .kpi-box {
      background: var(--bg-card);
      border: 1px solid var(--border-subtle);
      border-radius: 8px;
      padding: 8px 10px;
    }

    .kpi-box-lbl {
      font-size: 0.68rem;
      font-weight: 700;
      color: var(--ink-muted);
      text-transform: uppercase;
      letter-spacing: 0.03em;
      display: block;
      margin-bottom: 2px;
    }

    .kpi-box-val {
      font-family: var(--font-mono);
      font-size: 0.92rem;
      font-weight: 700;
      color: var(--ink-primary);
    }

    .kpi-box-sub {
      font-size: 0.7rem;
      color: var(--ink-secondary);
      margin-top: 2px;
      display: block;
    }

    .ind-narrative {
      color: var(--ink-secondary);
      line-height: 1.5;
      margin-bottom: 10px;
    }

    .ind-mini-history-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-family: var(--font-mono);
      font-size: 0.68rem;
      color: var(--ink-muted);
      margin-bottom: 4px;
    }

    .ind-mini-strip {
      display: flex;
      gap: 1.5px;
      overflow-x: auto;
      padding-bottom: 2px;
    }

    .mini-cell {
      width: 6px;
      height: 10px;
      border-radius: 1px;
      flex-shrink: 0;
    }
    .mini-cell.weekly-mini {
      width: 14px;
      height: 10px;
      border-radius: 2px;
    }

    /* ==========================================================================
       7. FLOATING MOUSEOVER / TAP INDICATOR DEFINITION DIALOG
       ========================================================================== */
    .floating-tooltip {
      position: fixed;
      z-index: 999;
      width: min(340px, 92vw);
      background: var(--bg-popover);
      color: var(--ink-popover);
      border: 1px solid rgba(201, 152, 43, 0.55);
      border-radius: 12px;
      padding: 12px 14px;
      box-shadow: var(--shadow-pop);
      pointer-events: none;
      opacity: 0;
      transform: translateY(4px);
      transition: opacity 0.15s ease, transform 0.15s ease;
      font-size: 0.78rem;
      line-height: 1.45;
    }

    .floating-tooltip.visible {
      opacity: 1;
      transform: translateY(0);
    }

    .ft-kicker {
      font-family: var(--font-mono);
      font-size: 0.66rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: #fbbf24;
      margin-bottom: 2px;
    }

    .ft-title {
      font-size: 0.9rem;
      font-weight: 800;
      color: #ffffff;
      margin-bottom: 6px;
    }

    .ft-desc {
      color: rgba(248, 250, 252, 0.88);
      margin-bottom: 8px;
    }

    .ft-rules {
      border-top: 1px solid rgba(255, 255, 255, 0.14);
      padding-top: 6px;
      font-size: 0.71rem;
      display: grid;
      gap: 3px;
    }

    /* Footer */
    .app-footer {
      max-width: 1180px;
      margin: 24px auto 0;
      padding: 14px 12px 0;
      border-top: 1px solid var(--border-subtle);
      font-size: 0.74rem;
      color: var(--ink-muted);
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 8px;
    }
