/* =================================================================
   Trading Dashboard — Unified Design System
   style-guide.css — Master Stylesheet
   Version: 2.0 — Synced to production Set A tokens (2026-03-03)
   ================================================================= */

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

/* Ensure [hidden] attribute always wins over any display rule in author stylesheets.
   Without this, elements with display:flex/block/grid in CSS stay visible even when
   hidden is set via JS (e.g. modal-overlay, side-panel). */
[hidden] { display: none !important; }

/* ── Core Design Tokens (Set A — matches all production dashboards) ── */
:root {
  /* Backgrounds */
  --bg:      #0f1117;
  --card:    #1a1d27;
  --card2:   #22263a;

  /* Text */
  --text:    #e1e4eb;
  --text2:   #8b90a0;

  /* Borders */
  --border:  #2a2e3f;

  /* Signal Colors */
  --bull:    #FF9800;
  --bull-bg: rgba(255, 152, 0, 0.13);
  --bear:    #2196F3;
  --bear-bg: rgba(33, 150, 243, 0.13);

  --green:   #3fb950;
  --red:     #f85149;
  --yellow:  #ffd600;
  --yellow-bg: rgba(255, 214, 0, 0.10);
  --blue:    #448aff;
  --blue-bg: rgba(68, 138, 255, 0.10);

  /* ── Extended Tokens (design preview components only) ── */
  --bg-hover:     rgba(136, 152, 170, 0.08);
  --text-faint:   #484f58;
  --border-light: #30363d;
  --grey:         #484f58;
  --grey-bg:      rgba(72, 79, 88, 0.20);

  /* Typography */
  --font: 'Roboto Mono', 'Courier New', monospace;
  --text-xs:   0.7rem;
  --text-sm:   0.8rem;
  --text-md:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Radius */
  --radius-sm:   3px;
  --radius:      6px;
  --radius-lg:   8px;
  --radius-pill: 9999px;

  /* Layout */
  --header-h: 48px;
  --nav-h:    40px;
}

/* ── Base ───────────────────────────────────────────────────────── */
html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover {
  color: var(--blue);
  text-decoration: underline;
}

/* Scrollbar */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* Selection */
::selection {
  background: rgba(68, 138, 255, 0.3);
  color: var(--text);
}


/* =================================================================
   1. NAVIGATION BAR
   Fixed at very top — dashboard links grouped by market
   ================================================================= */
.td-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 var(--sp-4);
  height: var(--nav-h);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.td-nav::-webkit-scrollbar { height: 0; }

.td-nav-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 var(--sp-3);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.td-nav-group:last-child { border-right: none; }

.td-nav-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  white-space: nowrap;
  padding-right: var(--sp-2);
  flex-shrink: 0;
}

.td-nav-link {
  font-size: var(--text-xs);
  color: var(--text-faint);
  padding: var(--sp-1) 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  text-decoration: none;
}

.td-nav-link:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.td-nav-link.active {
  color: var(--blue);
  background: var(--blue-bg);
}


/* =================================================================
   2. HEADER BLOCK
   Fixed below nav — title row + subtitle row in one card container
   ================================================================= */
.td-header-block {
  position: fixed;
  top: var(--nav-h);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-6) var(--sp-2);
}

/* Stale/error banner */
.td-banner {
  background: rgba(248, 81, 73, 0.12);
  color: var(--red);
  border-bottom: 1px solid rgba(248, 81, 73, 0.3);
  padding: var(--sp-2) var(--sp-6);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
}

/* Row 1: title + countdown + market status */
.td-header-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-1);
}

.td-header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.td-header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-shrink: 0;
}

/* Row 2: subtitle + source/stocks/last/next/status — all one line */
.td-header-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text2);
  gap: var(--sp-4);
}

.td-meta-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
  white-space: nowrap;
}

.td-meta-item {
  color: var(--text2);
}

.td-meta-item strong {
  color: var(--text);
  font-weight: 600;
}

.td-meta-sep {
  color: var(--text-faint);
  font-size: 0.6rem;
}

/* Market status: Live / Closed */
.td-market-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
}

.td-market-status.live {
  color: var(--bull);
  background: var(--bull-bg);
}

.td-market-status.live .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bull);
  box-shadow: 0 0 6px rgba(255, 152, 0, 0.6);
  animation: pulse 2s ease-in-out infinite;
}

.td-market-status.closed {
  color: var(--text-faint);
  background: var(--grey-bg);
}

.td-market-status.closed .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}


/* =================================================================
   CONTENT AREA
   Offset for fixed nav + header block
   --header-block-h set by JS after render, fallback 80px
   ================================================================= */
.td-content {
  padding-top: calc(var(--nav-h) + var(--header-block-h, 80px) + var(--sp-4));
  padding-left: var(--sp-6);
  padding-right: var(--sp-6);
  padding-bottom: var(--sp-8);
}


/* =================================================================
   3. MARKET GROUP BADGE
   Pill showing NSE F&O / US / MCX
   ================================================================= */
.badge-market {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
}

.badge-market.nse {
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid rgba(68, 138, 255, 0.2);
}

.badge-market.us {
  color: var(--bull);
  background: var(--bull-bg);
  border: 1px solid rgba(255, 152, 0, 0.2);
}

.badge-market.mcx {
  color: var(--yellow);
  background: var(--yellow-bg);
  border: 1px solid rgba(255, 214, 0, 0.2);
}


/* =================================================================
   4. STRATEGY BADGE
   Pill showing Intraday / Positional
   ================================================================= */
.badge-strategy {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-strategy.intraday {
  color: #f0883e;
  background: rgba(240, 136, 62, 0.15);
  border: 1px solid rgba(240, 136, 62, 0.2);
}

.badge-strategy.positional {
  color: #a371f7;
  background: rgba(163, 113, 247, 0.15);
  border: 1px solid rgba(163, 113, 247, 0.2);
}


/* =================================================================
   5. DATA TABLE
   Alternating rows, sticky headers, right-aligned numbers
   ================================================================= */
.td-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.td-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
  white-space: nowrap;
}

/* Sticky column headers */
.td-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  color: var(--text2);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 2px solid var(--border-light);
  text-align: left;
  user-select: none;
}

.td-table thead th.num { text-align: right; }

/* Body cells */
.td-table tbody td {
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.td-table tbody td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.td-table tbody td.symbol {
  font-weight: 700;
  color: var(--text);
}

/* Alternating row shading */
.td-table tbody tr:nth-child(even) td {
  background: var(--card2);
}

/* Hover */
.td-table tbody tr:hover td {
  background: var(--bg-hover);
}

/* Signal cell colors */
.td-table .signal-buy  { color: var(--bull); font-weight: 700; }
.td-table .signal-sell { color: var(--bear);   font-weight: 700; }

/* Row-level highlights */
.td-table tbody tr.row-super td   { background: rgba(255, 214, 0, 0.07) !important; }
.td-table tbody tr.row-aligned td { background: rgba(255, 152, 0, 0.07)  !important; }
.td-table tbody tr.row-against td { background: rgba(33, 150, 243, 0.07)  !important; }

/* Collision state — inline badges and row tints */
.collision-aligned       { color: var(--green);      background: rgba(63, 185, 80, 0.10); }
.collision-amplified     { color: var(--bull);        background: var(--bull-bg); }
.collision-dampened      { color: var(--text2);       background: var(--grey-bg); }
.collision-inverted      { color: var(--bear);        background: var(--bear-bg); }
.collision-indeterminate { color: var(--yellow);      background: var(--yellow-bg); }

/* Row-level tints (table rows, signal cards) */
.td-table tbody tr.collision-aligned td       { background: rgba(63, 185, 80, 0.06)  !important; }
.td-table tbody tr.collision-amplified td     { background: rgba(255, 152, 0, 0.08)  !important; }
.td-table tbody tr.collision-dampened td      { background: rgba(72, 79, 88, 0.10)   !important; }
.td-table tbody tr.collision-inverted td      { background: rgba(33, 150, 243, 0.08) !important; }
.td-table tbody tr.collision-indeterminate td { background: rgba(255, 214, 0, 0.05)  !important; }

/* Signal card left-border variants */
.signal-card.collision-aligned       { border-left-color: var(--green); }
.signal-card.collision-amplified     { border-left-color: var(--bull); }
.signal-card.collision-dampened      { border-left-color: var(--grey); }
.signal-card.collision-inverted      { border-left-color: var(--bear); }
.signal-card.collision-indeterminate { border-left-color: var(--yellow); }

/* Sortable column indicator */
.td-table thead th.sortable { cursor: pointer; }
.td-table thead th.sortable:hover { color: var(--text); }
.td-table thead th.sortable::after {
  content: ' \2195';
  color: var(--text-faint);
  font-size: 0.6rem;
}
.td-table thead th.sort-asc::after  { content: ' \2191'; color: var(--blue); }
.td-table thead th.sort-desc::after { content: ' \2193'; color: var(--blue); }


/* =================================================================
   6. SIGNAL CARD
   Compact card for fired signals — symbol, type, entry, SL, target
   ================================================================= */
.signal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-4);
}

.signal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--grey);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.signal-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.signal-card.buy  { border-left-color: var(--bull); }
.signal-card.sell { border-left-color: var(--bear); }

.signal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.signal-card-symbol {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}

.signal-card-type {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.signal-card-type.buy  { color: var(--bull); background: var(--bull-bg); }
.signal-card-type.sell { color: var(--bear);   background: var(--bear-bg); }

.signal-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-2);
}

.signal-card-field {
  display: flex;
  flex-direction: column;
}

.signal-card-label {
  font-size: var(--text-xs);
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.signal-card-value {
  font-size: var(--text-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.signal-card-value.entry  { color: var(--text); }
.signal-card-value.sl     { color: var(--bear); }
.signal-card-value.target { color: var(--bull); }

.signal-card-meta {
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text2);
  display: flex;
  justify-content: space-between;
}


/* =================================================================
   6b. DUAL-ENGINE CONFIDENCE BARS
   Shows Engine 1 (catalyst) and Engine 2 (mechanics) confidence
   side by side as thin horizontal fill bars.
   Usage:
     <div class="engine-bar-wrap">
       <span class="engine-bar-label">E1</span>
       <div class="engine-bar cat">
         <div class="engine-bar-fill" style="width:72%"></div>
       </div>
       <span class="engine-bar-label">E2</span>
       <div class="engine-bar mech">
         <div class="engine-bar-fill" style="width:58%"></div>
       </div>
     </div>
   ================================================================= */
.engine-bar-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.engine-bar-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
}

.engine-bar {
  height: 4px;
  border-radius: 2px;
  flex: 1;
  background: var(--border);
  overflow: hidden;
}

.engine-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Engine 1 — Catalyst (WHY) → orange/bull */
.engine-bar.cat .engine-bar-fill  { background: var(--bull); }

/* Engine 2 — Mechanics (HOW) → blue/bear */
.engine-bar.mech .engine-bar-fill { background: var(--bear); }

/* Confidence value labels (optional, shown next to bar) */
.engine-bar-value {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text2);
  flex-shrink: 0;
  min-width: 26px;
  text-align: right;
}

.engine-bar.cat  + .engine-bar-value { color: var(--bull); }
.engine-bar.mech + .engine-bar-value { color: var(--bear); }


/* =================================================================
   7. STATUS BADGE
   Three states: Active (green), No Signal (grey), Error (red)
   ================================================================= */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.03em;
}

.status-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.active     { color: var(--bull);      background: var(--bull-bg); }
.status-badge.active .dot { background: var(--bull); }

.status-badge.none       { color: var(--text-faint);  background: var(--grey-bg); }
.status-badge.none .dot  { background: var(--text-faint); }

.status-badge.error      { color: var(--bear);          background: var(--bear-bg); }
.status-badge.error .dot { background: var(--bear); }


/* =================================================================
   7b. LAYER HEALTH GRID
   Compact grid for engine_health.html — shows all 21 layers at a
   glance. Each cell is a small tile with layer ID + status dot.
   Auto-wraps: 15 catalyst tiles then 6 mechanics tiles.
   Usage:
     <div class="layer-grid">
       <div class="layer-grid-section">
         <div class="layer-grid-heading">Engine 1 — Catalyst</div>
         <div class="layer-grid-cells">
           <div class="layer-cell ok">
             <span class="layer-cell-dot"></span>
             <span class="layer-cell-id">L06</span>
             <span class="layer-cell-name">Econ</span>
           </div>
           <div class="layer-cell stale">...</div>
           <div class="layer-cell tripped">...</div>
         </div>
       </div>
     </div>
   ================================================================= */
.layer-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.layer-grid-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.layer-grid-heading {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
}

.layer-grid-cells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}

/* Individual layer tile */
.layer-cell {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s;
}

.layer-cell:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.layer-cell-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.layer-cell-id {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.layer-cell-name {
  font-size: 0.6rem;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── State: OK ── */
.layer-cell.ok {
  border-color: rgba(63, 185, 80, 0.25);
}
.layer-cell.ok .layer-cell-dot {
  background: var(--green);
  box-shadow: 0 0 4px rgba(63, 185, 80, 0.5);
}

/* ── State: STALE (no signal within 3× half-life) ── */
.layer-cell.stale {
  border-color: rgba(255, 214, 0, 0.25);
  background: rgba(255, 214, 0, 0.04);
}
.layer-cell.stale .layer-cell-dot {
  background: var(--yellow);
}
.layer-cell.stale .layer-cell-id {
  color: var(--yellow);
}

/* ── State: TRIPPED (circuit breaker open) ── */
.layer-cell.tripped {
  border-color: rgba(33, 150, 243, 0.3);
  background: rgba(33, 150, 243, 0.06);
}
.layer-cell.tripped .layer-cell-dot {
  background: var(--bear);
  animation: pulse 2s ease-in-out infinite;
}
.layer-cell.tripped .layer-cell-id {
  color: var(--bear);
}


/* =================================================================
   8. REFRESH TIMER
   "Last updated: 2 min ago" countdown text
   ================================================================= */
.refresh-timer {
  font-size: var(--text-xs);
  color: var(--text2);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

.refresh-timer .timer-icon {
  opacity: 0.6;
}

.refresh-timer.stale {
  color: var(--yellow);
}

.refresh-timer.error {
  color: var(--bear);
}


/* =================================================================
   SECTION DIVIDERS (for preview / multi-section pages)
   ================================================================= */
.td-section {
  margin-bottom: var(--sp-8);
}

.td-section-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
}

.td-section-desc {
  font-size: var(--text-sm);
  color: var(--text2);
  margin-bottom: var(--sp-4);
}


/* =================================================================
   UTILITY CLASSES
   ================================================================= */

/* Text colors */
.text-bull   { color: var(--bull)   !important; }
.text-bear   { color: var(--bear)   !important; }
.text-yellow { color: var(--yellow) !important; }
.text-blue   { color: var(--blue)   !important; }
.text-dim    { color: var(--text2)  !important; }
.text-faint  { color: var(--text-faint) !important; }

/* Subtle backgrounds */
.bg-bull   { background: var(--bull-bg) !important; }
.bg-bear   { background: var(--bear-bg) !important; }
.bg-yellow { background: var(--yellow-bg) !important; }
.bg-blue   { background: var(--blue-bg)   !important; }

/* Layout */
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }

/* Typography */
.fw-bold  { font-weight: 700; }
.fw-semi  { font-weight: 600; }
.right    { text-align: right; }
.center   { text-align: center; }
.nowrap   { white-space: nowrap; }
.tabnum   { font-variant-numeric: tabular-nums; }
.uppercase { text-transform: uppercase; letter-spacing: 0.05em; }

/* Spacing */
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.p-4  { padding: var(--sp-4); }

/* Cards (generic) */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
}

/* Inline code / value highlight */
.val {
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.val.up   { color: var(--bull); }
.val.down { color: var(--bear); }

/* Change percentage badge */
.change-pct {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}
.change-pct.up   { color: var(--bull); background: var(--bull-bg); }
.change-pct.down { color: var(--bear);   background: var(--bear-bg); }


/* =================================================================
   9. ANALYSIS CARDS
   Bordered info rows used inside modals — label + body text
   ================================================================= */
.analysis-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--grey);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.analysis-card-label {
  font-weight: 700;
  margin-right: 6px;
}

/* Blue variant — trend, anchor, breakout */
.analysis-card.card-blue {
  border-left-color: var(--bear);
}
.analysis-card.card-blue .analysis-card-label {
  color: var(--bear);
}

/* Orange variant — ORB, range */
.analysis-card.card-orange {
  border-left-color: var(--bull);
}
.analysis-card.card-orange .analysis-card-label {
  color: var(--bull);
}

/* Yellow variant — alert rows, buzz */
.analysis-card.card-yellow {
  border-left-color: #f0c040;
  background: rgba(240, 192, 64, 0.08);
}
.analysis-card.card-yellow .analysis-card-label {
  color: #f0c040;
}

/* Purple variant — patterns, clusters */
.analysis-card.card-purple {
  border-left-color: #a78bfa;
}
.analysis-card.card-purple .analysis-card-label {
  color: #a78bfa;
}

/* Green variant — confirmed signals only */
.analysis-card.card-green {
  border-left-color: #3fb950;
}
.analysis-card.card-green .analysis-card-label {
  color: #3fb950;
}


/* =================================================================
   10. STAT BAR
   Row of metric boxes — LTP, Change, Boxes, Buzz, Columns
   ================================================================= */
.stat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.stat-box {
  background: var(--card2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 100px;
  text-align: center;
  flex: 1;
}

.stat-box-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.stat-box-value.highlight {
  color: var(--bull);
}

.stat-box-value.up {
  color: var(--bull);
}

.stat-box-value.down {
  color: var(--bear);
}

.stat-box-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-top: 2px;
}


/* =================================================================
   11. P&F CHART GRID
   Grid of square cells — X (orange), O (blue), empty (invisible)
   ================================================================= */
.pnf-grid {
  display: inline-grid;
  gap: 2px;
  background: var(--bg);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pnf-cell {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.pnf-cell.x-cell {
  border: 1px solid var(--bull);
  color: var(--bull);
  border-radius: 2px;
}

.pnf-cell.o-cell {
  border: 1px solid var(--bear);
  color: var(--bear);
  border-radius: 2px;
}

.pnf-cell.empty {
  border: none;
  color: transparent;
}

.pnf-col-labels {
  display: inline-grid;
  gap: 2px;
  padding: 4px var(--sp-3) 0;
}

.pnf-col-label {
  width: 22px;
  text-align: center;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font);
}


/* =================================================================
   12. NEWS FEED
   List of news items below chart — headline + source/date
   ================================================================= */
.news-feed {
  max-width: 640px;
}

.news-feed-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-bottom: var(--sp-3);
}

.news-item {
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}

.news-item:last-child {
  border-bottom: none;
}

.news-item-headline {
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.5;
}

.news-item-headline:hover {
  text-decoration: underline;
  color: var(--text);
}

.news-item-meta {
  font-size: 11px;
  color: var(--text2);
  margin-top: 3px;
}


/* =================================================================
   13. MODAL BOX
   Popup over dashboard — overlay, close btn, title, body, actions
   ================================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
}

.modal-box {
  background: var(--card);
  border-left: 1px solid var(--border-light);
  width: min(560px, 90vw);
  height: 100vh;
  overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.6);
  position: relative;
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
}

.modal-overlay.open .modal-box {
  transform: translateX(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

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

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: var(--sp-5);
  font-size: var(--text-md);
  color: var(--text);
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}

/* =================================================================
   Detail Panel — stat cards, signal cards, P&F chart
   ================================================================= */

.detail-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.detail-stat {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: center;
}

.detail-stat-label {
  font-size: 10px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-stat-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.detail-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
}

.detail-card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text);
}

/* P&F Chart */

.pnf-chart {
  overflow-x: auto;
  padding: 8px 0;
  margin-bottom: 8px;
}

.pnf-cols {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: 80px;
}

.pnf-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pnf-box {
  width: 22px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  border-radius: 2px;
}

.pnf-x {
  background: rgba(33, 150, 243, 0.2);
  color: var(--bull);
  border: 1px solid rgba(33, 150, 243, 0.3);
}

.pnf-o {
  background: rgba(255, 152, 0, 0.15);
  color: var(--bear);
  border: 1px dashed rgba(255, 152, 0, 0.3);
}

.pnf-current {
  border-width: 2px;
  font-weight: 900;
}

.pnf-x.pnf-current {
  background: rgba(33, 150, 243, 0.35);
  box-shadow: 0 0 6px rgba(33, 150, 243, 0.3);
}

.pnf-o.pnf-current {
  background: rgba(255, 152, 0, 0.3);
  box-shadow: 0 0 6px rgba(255, 152, 0, 0.3);
}

.pnf-col-num {
  font-size: 8px;
  color: var(--text2);
  margin-top: 2px;
}

.modal-btn {
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 7px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.modal-btn.cancel {
  background: transparent;
  color: var(--text2);
  border-color: var(--border-light);
}

.modal-btn.cancel:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-btn.confirm {
  background: var(--bull);
  color: #000;
  border-color: var(--bull);
}

.modal-btn.confirm:hover {
  background: #ffad33;
}


/* =================================================================
   14. TOOLTIP
   Small hover label above element — dark bg, white text, arrow down
   ================================================================= */
.td-tooltip-wrap {
  position: relative;
  display: inline-block;
}

.td-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--border-light);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: var(--radius);
  white-space: nowrap;
  pointer-events: none;
  z-index: 150;
  transition: opacity 0.15s, visibility 0.15s;
}

/* Down-pointing arrow */
.td-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border-light);
}

.td-tooltip-wrap:hover .td-tooltip {
  visibility: visible;
  opacity: 1;
}

/* Column header tooltips via data-tip attribute (set by dashboard.js) */
th[data-tip] {
  cursor: help;
  position: relative;
}

th[data-tip]::after {
  content: attr(data-tip);
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--border-light);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: var(--radius);
  white-space: nowrap;
  pointer-events: none;
  z-index: 150;
  transition: opacity 0.15s, visibility 0.15s;
}

th[data-tip]:hover::after {
  visibility: visible;
  opacity: 1;
}


/* =================================================================
   15. NOTIFICATION POPUP
   Bottom-right alert — success / error / info, auto-dismiss 5s
   ================================================================= */
.notification-stack {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  z-index: 250;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-3);
}

.notification {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  background: var(--card);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--grey);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  animation: notif-in 0.25s ease-out;
  position: relative;
  overflow: hidden;
}

@keyframes notif-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

.notification-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.notification-content {
  flex: 1;
}

.notification-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.notification-msg {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.4;
}

.notification-dismiss {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  flex-shrink: 0;
}

.notification-dismiss:hover {
  color: var(--text);
}

/* Success (bullish orange) */
.notification.success {
  border-left-color: var(--bull);
}
.notification.success .notification-icon {
  color: var(--bull);
}

/* Error (bearish blue) */
.notification.error {
  border-left-color: var(--bear);
}
.notification.error .notification-icon {
  color: var(--bear);
}

/* Info (grey) */
.notification.info {
  border-left-color: var(--text2);
}
.notification.info .notification-icon {
  color: var(--text2);
}

/* Progress bar for auto-dismiss */
.notification-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  border-radius: 0 0 0 var(--radius);
  animation: notif-progress 5s linear forwards;
}

.notification.success .notification-progress { background: var(--bull); }
.notification.error .notification-progress   { background: var(--bear); }
.notification.info .notification-progress    { background: var(--text2); }

@keyframes notif-progress {
  from { width: 100%; }
  to   { width: 0; }
}


/* =================================================================
   16. FILTER BAR
   Search input, filter buttons, sector buttons, toggle columns
   ================================================================= */
.filters {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
  align-items: center;
}

.search {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: var(--text-xs);
  font-family: var(--font);
  width: 200px;
  outline: none;
}
.search:focus { border-color: var(--blue); }

.fbtn {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text2);
  cursor: pointer;
  font-size: var(--text-xs);
  font-family: var(--font);
  transition: all 0.15s;
}
.fbtn:hover { border-color: var(--blue); color: var(--text); }
.fbtn.on { background: var(--blue-bg); border-color: var(--blue); color: var(--blue); }

.toggle-cols-btn {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: var(--text-xs);
  font-family: var(--font);
  transition: all 0.15s;
}
.toggle-cols-btn:hover { border-color: var(--blue); color: var(--blue); }


/* =================================================================
   17. TAB BAR (dashboard.js driven)
   Horizontal tabs below stats — one per signal category
   ================================================================= */
.td-tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp-4);
  overflow-x: auto;
}

.td-tab-btn {
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font);
  color: var(--text2);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.td-tab-btn:hover { color: var(--text); background: var(--bg-hover); }
.td-tab-btn.active { color: var(--bull); border-bottom-color: var(--bull); }

.td-tab-badge {
  display: inline-block;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: var(--text-xs);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  margin-left: 6px;
  font-weight: 700;
}


/* =================================================================
   18. EXTRA COLUMNS (Show More / Show Less)
   Hidden by default, revealed with .show-all on table
   ================================================================= */
.extra-col { display: none; }
table.show-all .extra-col,
.td-table.show-all .extra-col { display: table-cell; }


/* =================================================================
   19. LOADING / EMPTY / ERROR STATES
   ================================================================= */
.loading-state {
  text-align: center;
  padding: 60px var(--sp-5);
  color: var(--text2);
}
.loading-state .spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--bull);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--sp-4);
}

@keyframes spin { to { transform: rotate(360deg) } }

.empty-state {
  text-align: center;
  padding: 40px var(--sp-5);
  color: var(--text2);
  font-size: var(--text-sm);
}

.stale-banner {
  background: rgba(248,81,73,0.1);
  border: 1px solid var(--red);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-5);
  margin-bottom: var(--sp-3);
  color: var(--red);
  font-size: var(--text-sm);
  font-weight: 600;
}

.error-banner {
  background: rgba(248,81,73,0.08);
  border-left: 3px solid var(--red);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-2) 0;
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: var(--text-xs);
}


/* =================================================================
   20. PERFORMANCE LINK
   Floating bottom-right link to performance review
   ================================================================= */
.perf-link {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 150;
  background: var(--bull-bg);
  color: var(--bull);
  border: 1px solid var(--bull);
  border-radius: var(--radius-pill);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 700;
  text-decoration: none;
  transition: all 0.15s;
}
.perf-link:hover {
  background: var(--bull);
  color: #000;
  text-decoration: none;
}


/* =================================================================
   21. MINI P&F SPARKLINE
   Inline bar chart for table cells
   ================================================================= */
.mini-pf {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 28px;
}
.mc {
  width: 3px;
  border-radius: 1px;
  min-height: 2px;
}
.mcx { background: var(--bull); opacity: 0.7; }
.mco { background: var(--bear); opacity: 0.7; }
.mcc { opacity: 1; }


/* =================================================================
   22. PILLS (signal type, pattern, direction badges)
   ================================================================= */
.pill {
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 11px;
  display: inline-block;
  text-transform: uppercase;
}
.pill-g { background: var(--bull-bg); color: var(--bull); }
.pill-r { background: var(--bear-bg); color: var(--bear); }
.pill-y { background: var(--yellow-bg); color: var(--yellow); }
.pill-b { background: var(--blue-bg); color: var(--blue); }
.pill-p { background: var(--purple-bg); color: var(--purple); }
.pill-glow-g { background: var(--bull-bg); color: var(--bull); animation: pg 2s infinite; }
.pill-glow-r { background: var(--bear-bg); color: var(--bear); animation: pr 2s infinite; }

/* Row highlights for P&F dashboards */
.super-pattern-row td { background: rgba(255, 214, 0, 0.07) !important; }

@keyframes pg {
  0%, 100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.4); }
  50% { box-shadow: 0 0 10px 3px rgba(33, 150, 243, 0.25); }
}

@keyframes pr {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.4); }
  50% { box-shadow: 0 0 10px 3px rgba(255, 152, 0, 0.25); }
}


/* =================================================================
   23. INDEX TICKER STRIP
   Live-updating index prices in dashboard header
   ================================================================= */
.ticker-strip {
  display: flex;
  gap: var(--sp-2);
  margin-left: auto;
  align-items: center;
  overflow-x: auto;
  transition: opacity 0.3s;
}

.ticker-strip.ticker-stale {
  opacity: 0.4;
}

.ticker-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px var(--sp-3);
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-xs);
  white-space: nowrap;
  transition: background 0.5s;
}

.ticker-symbol {
  color: var(--text2);
  font-weight: 700;
  margin-right: 2px;
}

.ticker-price {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ticker-change {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ticker-change.ticker-up   { color: var(--green); }
.ticker-change.ticker-down { color: var(--red); }

/* Flash animations — brief background pulse then fade */
.ticker-item.ticker-flash-up {
  animation: ticker-flash-green 0.8s ease-out;
}
.ticker-item.ticker-flash-down {
  animation: ticker-flash-red 0.8s ease-out;
}

@keyframes ticker-flash-green {
  0%   { background: rgba(63, 185, 80, 0.35); }
  100% { background: var(--card2); }
}

@keyframes ticker-flash-red {
  0%   { background: rgba(248, 81, 73, 0.35); }
  100% { background: var(--card2); }
}


/* =================================================================
   24. RESPONSIVE
   ================================================================= */
@media (width <= 768px) {
  .td-header { padding: 0 var(--sp-3); }
  .td-nav { padding: 0 var(--sp-2); }
  .td-content { padding-left: var(--sp-3); padding-right: var(--sp-3); }
  .stat-bar { gap: var(--sp-2); }
  .stat-box { min-width: 80px; padding: var(--sp-2) var(--sp-3); }
  .filters { gap: var(--sp-1); }
  .ticker-strip { gap: var(--sp-2); }
  .ticker-item { padding: 2px var(--sp-2); font-size: 0.65rem; }
}
