/* VN Scanner — Dark Dashboard
 * Served at scanner.thomas-lab.dev. Extracted from inline <style> so browsers
 * long-cache this file and we only re-download on genuine code changes.
 */

:root {
  --bg-primary: #0a0a0f;
  --bg-card: rgba(20, 20, 30, 0.85);
  --bg-card-hover: rgba(30, 30, 45, 0.95);
  --border: rgba(255, 255, 255, 0.06);
  --text-primary: #e0e0e0;
  --text-secondary: #6b7280;
  --accent-green: #10B981;
  --accent-red: #EF4444;
  --accent-blue: #3B82F6;
  --accent-amber: #F59E0B;
  --accent-gray: #6B7280;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 15% 30%, rgba(16, 185, 129, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 70%, rgba(59, 130, 246, 0.05) 0%, transparent 50%);
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* HEADER */
.header {
  padding: 20px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 15, 0.9);
}
.header h1 {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, #10B981, #3B82F6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-right { display: flex; gap: 16px; align-items: center; }
.header-right .last-scan { font-size: 12px; color: var(--text-secondary); }
.header-right .refresh-dot {
  width: 8px; height: 8px; background: var(--accent-green);
  border-radius: 50%; animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.logout-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.logout-btn:hover { color: #fff; border-color: rgba(255,255,255,0.2); }

/* VISUAL BOARD */
.visual-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);   /* 30m | D1 | W1 */
  gap: 24px;
  padding: 24px 32px;
}
@media (max-width: 1300px) {
  .visual-board { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .visual-board { grid-template-columns: 1fr; }
}
.board-col {
  background: rgba(20, 20, 30, 0.6);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 24px;
}
.board-col .header-title {
  width: 100%;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding-bottom: 12px;
}
.chart-box { width: 130px; flex-shrink: 0; text-align: center; }
.stat-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat-box {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-box .count { font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 6px; }
.stat-box .lbl { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.stat-box.buy .count { color: var(--accent-green); }
.stat-box.sell .count { color: var(--accent-red); }
.stat-box.wait .count { color: var(--accent-gray); }
.stat-box.total .count { color: var(--accent-blue); }

/* FILTERS */
.toolbar {
  padding: 0 32px 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.tf-tabs {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.04);
  padding: 4px;
  border-radius: 10px;
}
.tf-tab {
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  transition: all 0.2s;
}
.tf-tab.active { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.tf-tab:hover:not(.active) { color: #fff; }
.filter-btns { display: flex; gap: 4px; margin-left: auto; }
.filter-btn {
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.filter-btn.active { border-color: var(--accent-green); color: var(--accent-green); }
.filter-btn:hover:not(.active) { border-color: rgba(255,255,255,0.2); color: #fff; }

/* TICKER CARDS GRID — fixed 6 columns at typical desktop widths,
 * stepping down on narrower viewports so cards never get too cramped. */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 0 32px 32px;
}
@media (max-width: 1600px) { .cards-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 1300px) { .cards-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .cards-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 768px)  { .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* Watchlist uses a similar compact grid; both grids share visual rhythm */
.card-grid-compact {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  padding: 0 32px 8px;
}

/* MAIN 2-COLUMN GRID (market+stocks left, watchlist sidebar right) */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;   /* fluid left, fixed right */
  gap: 20px;
  padding: 0 32px;
  align-items: start;
}
.main-col-left  { min-width: 0; }
.main-col-right { min-width: 0; position: sticky; top: 16px; }
@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr; }
  .main-col-right { position: static; }
}
/* Inside main-grid, sections lose their own horizontal padding so they nest cleanly */
.main-col-left  > #indexSection,
.main-col-left  > #stockSection { padding: 0; }
.main-col-left  .index-grid,
.main-col-left  .cards-grid { padding-left: 0; padding-right: 0; }

/* WATCHLIST SIDEBAR */
.watchlist-section {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 16px;
}
.watchlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.watchlist-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.watchlist-add {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.watchlist-add input,
.watchlist-add select {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.watchlist-add input { flex: 1; min-width: 0; text-transform: uppercase; }
.card-grid-watchlist {
  display: grid;
  grid-template-columns: 1fr;   /* sidebar = 1 column stack */
  gap: 8px;
}
.watchlist-add input:focus,
.watchlist-add select:focus {
  border-color: var(--accent-green);
}
/* Briefly flashed when client-side symbol regex rejects the input. */
.watchlist-add input.input-error {
  border-color: var(--accent-red, #ef4444);
  animation: input-shake 0.18s ease-in-out 2;
}
@keyframes input-shake {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(-3px); }
}
.watchlist-add button {
  background: var(--accent-green);
  color: #022c1f;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.3px;
  transition: filter 0.15s;
}
.watchlist-add button:hover:not(:disabled) { filter: brightness(1.15); }
.watchlist-add button:disabled { opacity: 0.5; cursor: not-allowed; }
.watchlist-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  padding: 24px;
  font-size: 13px;
  background: rgba(255,255,255,0.02);
  border: 1px dashed rgba(255,255,255,0.08);
  border-radius: 10px;
}
.watchlist-card-wrap {
  position: relative;
}
.watchlist-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(239,68,68,0.18);
  border: 1px solid rgba(239,68,68,0.35);
  color: #ef4444;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s;
}
.watchlist-card-wrap:hover .watchlist-remove { opacity: 1; }
.watchlist-no-data {
  grid-column: span 1;
  background: rgba(255,255,255,0.02);
  border: 1px dashed rgba(255,255,255,0.10);
  border-radius: 10px;
  padding: 16px 14px;
  font-size: 12px;
  color: var(--text-secondary);
}
.ticker-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.ticker-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}
.ticker-card .ticker-name { font-size: 18px; font-weight: 800; letter-spacing: 0.5px; }
.ticker-card .action-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
}
.badge-mua { background: rgba(16,185,129,0.15); color: var(--accent-green); border: 1px solid rgba(16,185,129,0.3); }
.badge-ban { background: rgba(239,68,68,0.15); color: var(--accent-red); border: 1px solid rgba(239,68,68,0.3); }
.badge-cho { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.badge-avoid { background: rgba(107,114,128,0.15); color: var(--accent-gray); border: 1px solid rgba(107,114,128,0.3); }
.ticker-card .signal-info { margin-top: 10px; font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.ticker-card .signal-info span { color: var(--text-primary); font-weight: 600; }
.ticker-card .confidence-bar {
  margin-top: 10px;
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.confidence-bar .fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }
.ticker-card .scan-time { font-size: 11px; color: var(--text-secondary); margin-top: 8px; }
.ticker-card .no-data { color: var(--text-secondary); font-size: 13px; margin-top: 8px; }
.ticker-card.signal-mua { border-color: rgba(16,185,129,0.2); }
.ticker-card.signal-ban { border-color: rgba(239,68,68,0.2); }

/* INDEX SECTION */
.section-label {
  padding: 0 32px 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label .line { flex: 1; height: 1px; background: var(--border); }
.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  padding: 0 32px 24px;
}
.index-grid .ticker-card {
  border-color: rgba(59,130,246,0.2);
  background: linear-gradient(135deg, rgba(20,20,30,0.9), rgba(30,30,50,0.9));
}
.index-grid .ticker-name {
  font-size: 22px;
  background: linear-gradient(135deg, #3B82F6, #10B981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 24px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #14141e;
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 1440px;          /* wider so verdict column gets readable line length */
  width: 100%;
  max-height: 92vh;
  padding: 28px 32px;
  /* Flex column: header/badges/tabs are intrinsic-height, the active panel
   * fills whatever vertical space is left. Eliminates the modal-level
   * scrollbar — only the verdict text panel scrolls now. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 14px;
}
.modal-header,
#modalAction,
#modalSignal,
.modal-tabs { flex: 0 0 auto; }
.modal-panel { min-height: 0; }
.modal-panel.active {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.overview-grid {
  flex: 1 1 auto;
  min-height: 0;
}

/* Combined overview: chart on the left, verdict text on the right.
 * Heights are filled by flexbox from the modal — no fixed pixel value, which
 * means we don't have to estimate header/tabs reservation. Only the verdict
 * text panel scrolls; the modal itself never scrolls. */
.overview-grid {
  display: grid;
  /* 3:2 ratio (~60/40) — verdict gets ~480-540px so VN text wraps less and
   * stays at a comfortable reading line-length (~70 chars per line). */
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 20px;
  align-items: stretch;
  height: 100%;
}
/* Chart panel: framed (border + subtle bg) — the visual anchor of the modal */
.overview-chart {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  box-sizing: border-box;
  min-width: 0;                    /* let grid track shrink — needed for chart auto-resize */
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
}
.overview-chart > #modalChart {
  flex: 1 1 auto;
  height: 100% !important;          /* override inline — fills wrapper */
  min-height: 0;
}

/* Verdict panel: as subtle as possible — no border, no card, just a thin
 * left divider so it visually separates from the chart. Text is muted to
 * recede further; the chart is the hero, the verdict is supporting context. */
.overview-verdict {
  box-sizing: border-box;
  min-height: 0;
  background: transparent;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 0;
  overflow-y: auto;
  padding: 4px 8px 4px 26px;
  font-size: 14px;
  line-height: 1.75;
  color: rgba(255, 255, 255, 0.68);
}

/* Compact verdict header — pulled from the first line of verdict_text and
 * rendered as a centered hero band so the action verdict reads at a glance. */
.verdict-hero {
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 14px 18px;
  border-radius: 10px;
  margin: 0 0 18px 0;
  border: 1px solid;
  background-clip: padding-box;
}
.verdict-hero-mua   { color: #34d399; background: rgba(16,185,129,0.10);  border-color: rgba(16,185,129,0.30); }
.verdict-hero-ban   { color: #f87171; background: rgba(239,68,68,0.10);   border-color: rgba(239,68,68,0.30); }
.verdict-hero-cho   { color: #fbbf24; background: rgba(245,158,11,0.10);  border-color: rgba(245,158,11,0.30); }
.verdict-hero-avoid { color: #d1d5db; background: rgba(107,114,128,0.10); border-color: rgba(107,114,128,0.30); }
.overview-verdict::-webkit-scrollbar       { width: 6px; }
.overview-verdict::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
.overview-verdict::-webkit-scrollbar-track { background: transparent; }

/* Stack vertically on narrower viewports — verdict drops below chart. */
@media (max-width: 1100px) {
  .overview-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 3fr) minmax(0, 2fr);
  }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 20px; font-weight: 800; }
.modal-close {
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.12); color: #fff; }
.modal-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: rgba(255,255,255,0.04);
  padding: 6px;
  border-radius: 12px;
}
.modal-tab {
  padding: 12px 28px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  transition: all 0.2s;
  letter-spacing: 0.2px;
}
.modal-tab.active { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.modal-tab:hover:not(.active) { color: #fff; }
.modal-panel { display: none; }
.modal-panel.active { display: block; }
.verdict-text {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
  color: #d1d5db;
  max-height: 50vh;
  overflow-y: auto;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-primary);
}
.history-table tr { cursor: pointer; transition: background 0.15s; }
.history-table tr:hover { background: rgba(255,255,255,0.04); }
.history-table .badge-sm {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

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

/* RESPONSIVE */
@media (max-width: 768px) {
  .header { padding: 16px 20px; }
  .summary { padding: 16px 20px; grid-template-columns: repeat(3, 1fr); }
  .toolbar { padding: 0 20px 12px; }
  .cards-grid { padding: 0 20px 20px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .index-grid { padding: 0 20px 16px; grid-template-columns: 1fr; }
  .ticker-card { padding: 14px 16px; }
  .modal { padding: 24px; margin: 16px; }
  .section-label { padding: 0 20px 8px; }
}
