/* Analysis Deck — Editorial Light theme
 * Served at adeck.thomas-lab.dev (Cloudflare Pages).
 *
 * Aesthetic: financial newspaper / quarterly report.
 *   - Cream paper background, charcoal text
 *   - Burgundy primary accent, navy secondary
 *   - Playfair Display headers (editorial), JetBrains Mono numbers
 *   - Sharp 4px radii, hairline warm-tan borders
 *   - Action colors muted slightly from neon spec for print feel
 *
 * Distinct from VN Scanner (dark + neon green/blue).
 * Same class names so the shared app.js works unchanged.
 */

:root {
  /* Surfaces — softer cream, less yellow saturation than v1 */
  --bg-primary: #faf8f2;
  --bg-paper: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #fdfbf6;
  --bg-soft: #f6f2ea;

  /* Text — slightly less hard than near-black */
  --text-primary: #2a241e;
  --text-secondary: #786a5b;
  --text-muted: #a8998a;

  /* Borders — softened */
  --border: #e0d8c8;
  --border-soft: #ece6d6;

  /* Brand accents — toned slightly */
  --accent-burgundy: #8a3920;
  --accent-navy: #1e3a8a;

  /* Action semantic — muted for print/light feel */
  --accent-green: #16803c;
  --accent-red:   #a31a3f;
  --accent-amber: #ad6b0e;
  --accent-gray:  #7d7d83;
  --accent-blue:  #1e3a8a;

  /* Shadows — softer warm tint */
  --shadow-sm: 0 1px 2px rgba(42, 36, 30, 0.04);
  --shadow-md: 0 3px 10px rgba(42, 36, 30, 0.06), 0 1px 2px rgba(42, 36, 30, 0.03);
  --shadow-lg: 0 10px 28px rgba(42, 36, 30, 0.10), 0 2px 5px rgba(42, 36, 30, 0.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  /* Soft paper warmth — radial gradients only, no scanline grid (too busy) */
  background-image:
    radial-gradient(ellipse at 12% -5%, rgba(138, 57, 32, 0.018) 0%, transparent 50%),
    radial-gradient(ellipse at 88% 105%, rgba(30, 58, 138, 0.015) 0%, transparent 50%);
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(28, 24, 20, 0.18); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(28, 24, 20, 0.30); }

/* ==========================================================
 * LOGIN OVERLAY
 * ========================================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(246, 243, 236, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}
.login-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 420px;
  position: relative;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-burgundy), var(--accent-navy));
  border-radius: 6px 6px 0 0;
}
.login-brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}
.login-brand h1 {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}
.login-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-style: italic;
  letter-spacing: 0.2px;
}
.login-field { margin-bottom: 18px; }
.login-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.login-field input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 11px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.login-field input:focus {
  outline: none;
  border-color: var(--accent-burgundy);
  background: var(--bg-paper);
  box-shadow: 0 0 0 3px rgba(124, 45, 18, 0.08);
}
.login-btn {
  width: 100%;
  background: var(--accent-burgundy);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  margin-top: 6px;
}
.login-btn:hover:not(:disabled) { background: #6b1d0a; }
.login-btn:active { transform: translateY(1px); }
.login-btn:disabled { opacity: 0.55; cursor: wait; }
.login-err {
  margin-top: 14px;
  min-height: 18px;
  font-size: 12px;
  color: var(--accent-red);
  text-align: center;
  font-weight: 500;
}
.login-footer {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
}
.login-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.8px;
}

/* ==========================================================
 * HEADER
 * ========================================================== */
.header {
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--accent-burgundy);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.logo-mark {
  color: var(--accent-burgundy);
  font-weight: 700;
}
.header-right {
  display: flex;
  gap: 14px;
  align-items: center;
}
.brand-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.6px;
  color: var(--accent-burgundy);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-soft);
}
.last-scan {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}
.refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-burgundy);
  box-shadow: 0 0 6px rgba(124, 45, 18, 0.45);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
.logout-btn {
  background: var(--bg-paper);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  letter-spacing: 0.2px;
}
.logout-btn:hover {
  background: var(--bg-soft);
  border-color: var(--accent-burgundy);
  color: var(--accent-burgundy);
}

/* ==========================================================
 * VISUAL BOARD — Adeck reshape: horizontal "ticker tape" strip
 * Each timeframe is a slim horizontal panel showing all 4 stats
 * inline. Removes VN Scanner's bulky 3-column grid feel.
 * ========================================================== */
/* ==========================================================
 * OVERVIEW PANELS (.vb) — 3 timeframes, each as a wide panel
 * with: TF label · bullish bias · counts · total · stacked bar.
 * Replaces the old Chart.js donut + sparse stats strip.
 * ========================================================== */
.vb {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  margin: 18px 32px 14px;
}
.vb-row {
  display: grid;
  grid-template-columns: 110px 110px 1fr 70px;
  grid-template-rows: auto 6px;
  align-items: center;
  gap: 4px 22px;
  padding: 14px 20px;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.vb-row:hover { box-shadow: var(--shadow-md); }

/* Cell 1: TF label */
.vb-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1;
}
.vb-tf {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-burgundy);
  letter-spacing: 0.5px;
  line-height: 1;
}
.vb-tf-sub {
  font-family: 'Inter', sans-serif;
  font-size: 10.5px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* Cell 2: Bullish bias headline (the key number user looks for first) */
.vb-bias {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
  border-left: 1px solid var(--border-soft);
  padding-left: 18px;
}
.vb-bias-val {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1;
}
.vb-bias-val[data-tone="bull"]    { color: var(--accent-green); }
.vb-bias-val[data-tone="bear"]    { color: var(--accent-red); }
.vb-bias-val[data-tone="neutral"] { color: var(--accent-amber); }
.vb-bias-val[data-tone="muted"]   { color: var(--text-muted); }
.vb-bias-lbl {
  font-family: 'Inter', sans-serif;
  font-size: 9.5px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* Cell 3: 3 inline stats */
.vb-stats {
  display: flex;
  gap: 28px;
  align-items: baseline;
  justify-content: flex-start;
  border-left: 1px solid var(--border-soft);
  padding-left: 18px;
}
.vb-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.vb-stat strong {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.4px;
}
.vb-stat span {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.vb-buy strong  { color: var(--accent-green); }
.vb-sell strong { color: var(--accent-red); }
.vb-wait strong { color: var(--accent-amber); }

/* Cell 4: total (right-aligned) */
.vb-total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  border-left: 1px solid var(--border-soft);
  padding-left: 14px;
  line-height: 1;
}
.vb-total strong {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-navy);
  letter-spacing: -0.6px;
  line-height: 1;
}
.vb-total span {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* Bar — full row width below the cells */
.vb-bar {
  grid-column: 1 / -1;
  display: flex;
  height: 5px;
  background: var(--border-soft);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
.vb-seg { height: 100%; transition: width 0.4s ease; }
.vb-seg-mua   { background: var(--accent-green); }
.vb-seg-ban   { background: var(--accent-red); }
.vb-seg-cho   { background: var(--accent-amber); }
.vb-seg-avoid { background: var(--text-muted); }

@media (max-width: 1100px) {
  .vb-row { grid-template-columns: 100px 1fr 70px; gap: 4px 16px; }
  .vb-bias { display: none; }
  .vb-stats { gap: 18px; padding-left: 14px; }
}
@media (max-width: 700px) {
  .vb { margin: 12px 16px; }
  .vb-row { grid-template-columns: 1fr 70px; padding: 12px 14px; }
  .vb-stats { grid-column: 1 / -1; padding-left: 0; border-left: none; gap: 14px; }
}

/* ==========================================================
 * TOOLBAR — TF tabs + filter buttons
 * ========================================================== */
.toolbar {
  padding: 0 32px 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.tf-tabs {
  display: flex;
  gap: 0;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  padding: 0;
  border-radius: 4px;
  overflow: hidden;
}
.tf-tab {
  padding: 8px 18px;
  border-radius: 0;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  border: none;
  border-right: 1px solid var(--border-soft);
  background: transparent;
  transition: background 0.15s, color 0.15s;
}
.tf-tab:last-child { border-right: none; }
.tf-tab.active {
  background: var(--accent-burgundy);
  color: #fff;
}
.tf-tab:hover:not(.active) {
  background: var(--bg-soft);
  color: var(--text-primary);
}

.filter-btns { display: flex; gap: 6px; margin-left: auto; }
.filter-btn {
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-paper);
  color: var(--text-secondary);
  transition: all 0.15s;
}
.filter-btn.active {
  background: var(--accent-burgundy);
  border-color: var(--accent-burgundy);
  color: #fff;
}
.filter-btn:hover:not(.active) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* ==========================================================
 * MAIN GRID — left content + right watchlist sidebar
 * ========================================================== */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 0 32px 32px;
}
@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr; }
}

/* ==========================================================
 * ACTION-GROUPED LAYOUT — Adeck v4
 *
 * MUA / BÁN / ĐỨNG NGOÀI  → rich feature cards in 3-5 col grid,
 *                            full entry/SL/TP/confidence visible.
 * CHỜ                       → compact chips (8-12 col), just sym + %,
 *                            so the long tail doesn't dominate.
 *
 * Each section has its own action-tinted heading + count badge.
 * ========================================================== */

/* Section wrapper + header */
.signal-section {
  margin: 0 0 22px;
}
.signal-section .ss-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0 10px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 12px;
}
.ss-mark {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-burgundy);
  line-height: 1;
}
.ss-title {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-primary);
}
.ss-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}
.signal-section-index .ss-mark,
.signal-section-index .ss-count { background: var(--accent-navy); color: #fff; }
.signal-section-index .ss-mark { background: transparent; color: var(--accent-navy); }
.signal-section-mua .ss-mark   { color: var(--accent-green); }
.signal-section-mua .ss-count  { background: var(--accent-green); }
.signal-section-ban .ss-mark   { color: var(--accent-red); }
.signal-section-ban .ss-count  { background: var(--accent-red); }
.signal-section-avoid .ss-mark { color: var(--accent-gray); }
.signal-section-avoid .ss-count{ background: var(--accent-gray); }
.signal-section-cho .ss-mark   { color: var(--accent-amber); }
.signal-section-cho .ss-count  { background: var(--accent-amber); }

/* FEATURE CARD GRID — for MUA/BÁN/AVOID/Index */
.signals-feature {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.cards-grid,    /* legacy alias from app.js */
.index-grid {   /* legacy alias from app.js */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.card-grid-watchlist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
}

/* FEATURE CARD — rich info, ~140-160px tall */
.ticker-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.05s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  box-shadow: var(--shadow-sm);
  min-height: 0;
}
.ticker-card:hover {
  border-color: var(--accent-burgundy);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.ticker-card.action-mua    { border-top: 3px solid var(--accent-green); }
.ticker-card.action-ban    { border-top: 3px solid var(--accent-red); }
.ticker-card.action-cho    { border-top: 3px solid var(--accent-amber); }
.ticker-card.action-avoid  { border-top: 3px solid var(--accent-gray); }
.signal-section-index .ticker-card { border-top: 3px solid var(--accent-navy); }

/* Card head: ticker name + TF inline */
.tk-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  line-height: 1;
}
.ticker-name {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 19px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.4px;
  line-height: 1;
}
.ticker-tf {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Card action row: badge + scan time inline */
.tk-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.action-badge {
  font-family: 'Inter', sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border: 1px solid;
  display: inline-block;
  line-height: 1.4;
}
.action-badge.mua,
.action-mua .action-badge   { color: var(--accent-green); background: rgba(21, 128, 61, 0.08);  border-color: rgba(21, 128, 61, 0.30); }
.action-badge.ban,
.action-ban .action-badge   { color: var(--accent-red);   background: rgba(159, 18, 57, 0.08);  border-color: rgba(159, 18, 57, 0.30); }
.action-badge.cho,
.action-cho .action-badge   { color: var(--accent-amber); background: rgba(161, 98, 7, 0.08);   border-color: rgba(161, 98, 7, 0.30); }
.action-badge.avoid,
.action-avoid .action-badge { color: var(--accent-gray);  background: rgba(113, 113, 122, 0.08); border-color: rgba(113, 113, 122, 0.30); }
.tk-scan-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  color: var(--text-muted);
}

/* Levels row inside a card — entry / sl / tp inline */
.tk-levels {
  display: flex;
  gap: 12px;
  align-items: baseline;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  padding: 6px 10px;
  min-height: 0;
}
.tk-levels-empty { display: none; }
.tk-level {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}
.tk-level-lbl {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.tk-level-val {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}
.tk-level-entry .tk-level-val { color: var(--accent-burgundy); font-weight: 700; }
.tk-level-sl .tk-level-val    { color: var(--accent-red); }
.tk-level-tp .tk-level-val    { color: var(--accent-green); }

/* Confidence row inside card — label + value + bar */
.tk-conf {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
}
.tk-conf-lbl {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.tk-conf-bar {
  height: 4px;
  background: var(--border-soft);
  border-radius: 2px;
  overflow: hidden;
}
.tk-conf-fill { height: 100%; transition: width 0.3s; }
.tk-conf-val {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 700;
  min-width: 38px;
  text-align: right;
}
.tk-conf-high .tk-conf-val  { color: var(--accent-green); }
.tk-conf-high .tk-conf-fill { background: var(--accent-green); }
.tk-conf-mid  .tk-conf-val  { color: var(--accent-amber); }
.tk-conf-mid  .tk-conf-fill { background: var(--accent-amber); }
.tk-conf-low  .tk-conf-val  { color: var(--accent-red); }
.tk-conf-low  .tk-conf-fill { background: var(--accent-red); }
.tk-conf-none .tk-conf-val  { color: var(--text-muted); }
.tk-conf-none .tk-conf-fill { background: var(--text-muted); }

/* Watchlist sidebar — collapsed cells, vertical */
.card-grid-watchlist .ticker-card {
  grid-template-columns: 1fr;
  padding: 9px 12px;
  background: var(--bg-paper);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  gap: 4px;
  min-height: 0;
}
.card-grid-watchlist .ticker-card:nth-child(even) { background: var(--bg-paper); }
.card-grid-watchlist .ticker-card .tk-head { flex-direction: row; align-items: baseline; gap: 6px; }
.card-grid-watchlist .ticker-card .ticker-name { font-size: 15px; }
.card-grid-watchlist .ticker-card .tk-levels  { gap: 8px; flex-wrap: wrap; padding: 4px 8px; }
.card-grid-watchlist .ticker-card .tk-level-val { font-size: 11px; }
.card-grid-watchlist .ticker-card .tk-level-lbl { font-size: 9px; }

/* ==========================================================
 * COMPACT CHIPS — for the long tail of CHỜ signals.
 * Dense grid, just symbol + confidence% on a colored ribbon.
 * Click opens the same modal as feature cards.
 * ========================================================== */
.signals-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
}
.signal-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-amber);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  min-height: 0;
  user-select: none;
}
.signal-chip:hover {
  background: var(--bg-soft);
  border-color: var(--accent-burgundy);
}
.chip-sym {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  line-height: 1;
}
.chip-conf {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: -0.1px;
}
.chip-high .chip-conf { color: var(--accent-green); }
.chip-mid  .chip-conf { color: var(--accent-amber); }
.chip-low  .chip-conf { color: var(--accent-red); }
.chip-none .chip-conf { color: var(--text-muted); }

/* Responsive */
@media (max-width: 700px) {
  .signals-feature { grid-template-columns: 1fr 1fr; }
  .signals-chips { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}

/* INDEX SECTION */
.section-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent-burgundy);
}
.section-label .line { flex: 1; height: 1px; background: var(--border); }

.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  padding: 0 0 20px;
}
.index-grid .ticker-card {
  border-color: var(--accent-navy);
  background: linear-gradient(135deg, #ffffff, #f7f5ef);
}
.index-grid .ticker-name {
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent-burgundy), var(--accent-navy));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ==========================================================
 * WATCHLIST SIDEBAR
 * ========================================================== */
.watchlist-section {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}
.watchlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.watchlist-header h3 {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}
.watchlist-add {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.watchlist-add input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.watchlist-add input:focus {
  outline: none;
  border-color: var(--accent-burgundy);
  background: var(--bg-paper);
}
#wlAddBtn {
  background: var(--accent-burgundy);
  color: #fff;
  border: 1px solid var(--accent-burgundy);
  border-radius: 4px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#wlAddBtn:hover { background: #6b1d0a; }
.watchlist-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 8px;
  font-style: italic;
}

/* ==========================================================
 * MODAL — detail popup
 * ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
/* JS in app.js toggles `.show`, not `.active` — keep both for safety */
.modal-overlay.show,
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  padding: 28px 32px;
  max-width: 1200px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent-burgundy);
}
.modal-header h2 {
  font-family: 'Be Vietnam Pro', 'Inter', sans-serif;
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.4px;
}
.modal-close {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--bg-card); color: var(--accent-burgundy); }

.signal-info {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.modal-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.modal-tab.active {
  color: var(--accent-burgundy);
  border-bottom-color: var(--accent-burgundy);
}
.modal-panel { display: none; }
.modal-panel.active { display: block; }

.overview-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 22px;
  align-items: stretch;
  min-height: 600px;
}
@media (max-width: 1000px) {
  .overview-grid { grid-template-columns: 1fr; min-height: 0; }
}
.overview-chart {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  /* Stretch to row height so chart canvas fills the verdict's height */
  display: flex;
  flex-direction: column;
  min-height: 600px;
}
.overview-chart > div {
  flex: 1;
  width: 100%;
  height: 100%;
}
.overview-verdict {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-burgundy);
  border-radius: 4px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
}
.overview-verdict::before {
  content: "KHUYẾN NGHỊ";
  position: absolute;
  top: 12px;
  left: 28px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--accent-burgundy);
  background: var(--bg-paper);
  padding: 0 6px;
  margin-left: -6px;
}
.verdict-text {
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  margin-top: 14px;
  text-align: justify;
  text-justify: inter-character;
  flex: 1;
  letter-spacing: 0.05px;
}
.verdict-text strong,
.verdict-text b {
  font-weight: 700;
  color: var(--accent-burgundy);
}
/* Empty / placeholder state: show a centered ellipsis dash */
.verdict-text:empty::before,
.verdict-text:has(> :only-child:empty)::before {
  content: "—";
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 28px;
  margin-top: 30px;
}

/* Verdict hero pills (action emphasis) */
.verdict-hero-mua,
.verdict-hero-ban,
.verdict-hero-cho,
.verdict-hero-avoid {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.verdict-hero-mua   { color: var(--accent-green); background: rgba(21, 128, 61, 0.08);  border: 1px solid rgba(21, 128, 61, 0.30); }
.verdict-hero-ban   { color: var(--accent-red);   background: rgba(159, 18, 57, 0.08);  border: 1px solid rgba(159, 18, 57, 0.30); }
.verdict-hero-cho   { color: var(--accent-amber); background: rgba(161, 98, 7, 0.08);   border: 1px solid rgba(161, 98, 7, 0.30); }
.verdict-hero-avoid { color: var(--accent-gray);  background: rgba(113, 113, 122, 0.08); border: 1px solid rgba(113, 113, 122, 0.30); }

/* History table inside modal */
#modalHistory table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
}
#modalHistory thead th {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
#modalHistory tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
}
#modalHistory tbody tr:hover { background: var(--bg-soft); }

/* ==========================================================
 * LOADING / EMPTY STATES
 * ========================================================== */
.loading { text-align: center; padding: 60px 32px; color: var(--text-secondary); }
.loading .spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-burgundy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  text-align: center;
  padding: 60px 32px;
  color: var(--text-secondary);
}
.empty-state .icon { font-size: 36px; margin-bottom: 10px; opacity: 0.6; }

/* ==========================================================
 * RESPONSIVE — 3 tiers
 *   ≤1024px  iPad portrait / small laptop  — tighten
 *   ≤768px   landscape phone / small tablet — stack heavily
 *   ≤480px   phone portrait                  — minimal
 * ========================================================== */

/* ── iPad portrait & narrow laptop (≤1024) ─────────────────── */
@media (max-width: 1024px) {
  .header { padding: 16px 20px; }
  .brand-tag { display: none; }
  .last-scan { font-size: 10.5px; }

  .vb { margin: 14px 20px 10px; gap: 6px; }
  .vb-row {
    grid-template-columns: 100px 1fr 70px;
    gap: 4px 14px;
    padding: 12px 16px;
  }
  .vb-bias { display: none; }
  .vb-stats { padding-left: 14px; gap: 18px; }

  .toolbar { padding: 0 20px 12px; gap: 8px; }
  .filter-btns { margin-left: 0; }

  .main-grid {
    grid-template-columns: 1fr 280px;
    padding: 0 20px 24px;
    gap: 16px;
  }

  .signals-feature  { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .signals-chips    { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); }

  .modal { padding: 22px 20px; margin: 14px; }
  .overview-grid { grid-template-columns: 1.3fr 1fr; gap: 16px; }
}

/* ── Landscape phone / small tablet (≤768) ─────────────────── */
@media (max-width: 768px) {
  .header {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .header h1 { font-size: 19px; }
  .header-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .last-scan { display: none; }
  .logout-btn { padding: 6px 10px; font-size: 11px; }

  /* Visual board → stack TF + total on row 1, stats on row 2, bar on row 3 */
  .vb { margin: 10px 14px 8px; gap: 6px; }
  .vb-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 6px 12px;
    padding: 10px 12px;
  }
  .vb-label { line-height: 1.05; }
  .vb-tf { font-size: 18px; }
  .vb-tf-sub { font-size: 10px; }
  .vb-stats {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-left: 0;
    border-left: none;
    gap: 18px;
    flex-wrap: wrap;
  }
  .vb-stat strong { font-size: 18px; }
  .vb-total { padding-left: 0; border-left: none; align-items: flex-end; }
  .vb-total strong { font-size: 22px; }
  .vb-bar { grid-row: 3; }

  /* Toolbar — wrap to multi-row, smaller buttons */
  .toolbar { padding: 0 14px 10px; gap: 6px; flex-wrap: wrap; }
  .tf-tabs { order: 1; }
  .filter-btns {
    order: 2;
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-btns::-webkit-scrollbar { display: none; }
  .tf-tab, .filter-btn { padding: 7px 12px; font-size: 11.5px; }
  .filter-btn { white-space: nowrap; flex-shrink: 0; }

  /* Watchlist drops below main content */
  .main-grid {
    grid-template-columns: 1fr;
    padding: 0 14px 20px;
    gap: 14px;
  }
  .main-col-right { order: -1; }   /* Watchlist visible above stocks */
  .watchlist-section {
    position: static;
    max-height: none;
    padding: 14px;
  }

  /* Section headings tighter */
  .signal-section { margin-bottom: 18px; }
  .signal-section .ss-head { padding-bottom: 8px; gap: 8px; }
  .ss-title { font-size: 12px; }

  /* Feature card grid — 2 col on small tablet */
  .signals-feature { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ticker-card { padding: 10px 12px; gap: 6px; }
  .ticker-name { font-size: 17px; }
  .tk-levels { gap: 8px; padding: 5px 8px; }
  .tk-level-val { font-size: 12px; }

  /* Chip grid — denser */
  .signals-chips { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 5px; }
  .signal-chip { padding: 6px 8px; }
  .chip-sym { font-size: 12.5px; }
  .chip-conf { font-size: 10px; }

  /* Modal full-screen-ish on phone */
  .modal-overlay { padding: 0; }
  .modal {
    padding: 18px 14px;
    margin: 0;
    max-height: 100vh;
    border-radius: 0;
    width: 100vw;
  }
  .modal-header { padding-bottom: 10px; margin-bottom: 12px; }
  .modal-header h2 { font-size: 20px; }

  /* Chart + verdict stack */
  .overview-grid {
    grid-template-columns: 1fr;
    min-height: 0;
    gap: 14px;
  }
  .overview-chart { min-height: 380px; }
  .overview-chart > div { min-height: 380px !important; }
  .overview-verdict { padding: 22px 18px 18px; }
  .overview-verdict::before { left: 18px; }
  .verdict-text { font-size: 14px; line-height: 1.7; }

  /* Login overlay */
  .login-overlay { padding: 16px; }
  .login-card { padding: 26px 20px 22px; max-width: 100%; }
  .login-brand h1 { font-size: 26px; }
  .login-sub { margin-bottom: 22px; }
}

/* ── Phone portrait (≤480) ──────────────────────────────────── */
@media (max-width: 480px) {
  .header h1 { font-size: 17px; }
  .header-right .logout-btn { font-size: 10.5px; padding: 5px 9px; }

  .vb { margin: 8px 10px 6px; }
  .vb-row { padding: 8px 10px; }
  .vb-tf { font-size: 16px; }
  .vb-stats { gap: 12px; }
  .vb-stat strong { font-size: 16px; }
  .vb-stat span { font-size: 10px; }
  .vb-total strong { font-size: 19px; }

  .toolbar { padding: 0 10px 8px; }
  .tf-tabs { width: 100%; }
  .tf-tab { flex: 1; text-align: center; }

  .main-grid { padding: 0 10px 16px; }

  /* Feature cards — 1 col on tiny screens */
  .signals-feature { grid-template-columns: 1fr; }
  .ticker-card .tk-head { flex-wrap: wrap; }

  /* Chips even denser */
  .signals-chips { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }
  .chip-sym { font-size: 12px; }

  .modal { padding: 14px 10px; }
  .modal-header h2 { font-size: 18px; }

  .overview-chart { min-height: 320px; }
  .overview-chart > div { min-height: 320px !important; }
  .overview-verdict { padding: 20px 14px 16px; }

  .login-card { padding: 22px 16px 18px; }
  .login-brand h1 { font-size: 23px; }
}
