/* ==========================================
   Theme tokens (light default, dark via system or toggle)
   ========================================== */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e0dfda;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --up: #d03b3b;          /* Taiwan convention: red = up / buy */
  --down: #0a8a0a;        /* green = down / sell */
  --series-1: #2a78d6;    /* foreign */
  --series-2: #eb6834;    /* trust */
  --series-3: #1baf7a;    /* dealer */
  --grid: #e6e5e0;
  --axis: #8a8984;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #252523;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --up: #ef5b5b;
    --down: #1fae4a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2a2a28;
    --axis: #6f6e69;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #252523;
  --border: #2f2f2c;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;
  --up: #ef5b5b;
  --down: #1fae4a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2a2a28;
  --axis: #6f6e69;
}

/* ==========================================
   Base layout
   ========================================== */
* { box-sizing: border-box; }
[v-cloak] { display: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 96px;   /* bottom padding leaves room for the mobile tab bar */
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }
.data-date { color: var(--text-2); font-size: 13px; margin-left: auto; }
.user { display: flex; gap: 8px; align-items: center; color: var(--text-2); font-size: 13px; white-space: nowrap; }
.user a { color: var(--accent); text-decoration: none; }

/* Tabs: top row on desktop, fixed bottom bar on phones */
.tabs {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 8px 16px 0;
  max-width: 1100px;
  margin: 0 auto;
}
.tabs a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
}
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

@media (max-width: 640px) {
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0;
    max-width: none;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    justify-content: space-around;
  }
  .tabs a { flex-direction: column; gap: 0; font-size: 12px; padding: 4px 10px; }
  .tabs a.active { box-shadow: none; color: var(--accent); background: transparent; }
  .tab-icon { font-size: 18px; }
}

/* ==========================================
   Controls
   ========================================== */
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 2px;
  overflow-x: auto;
  max-width: 100%;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  padding: 6px 12px;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.icon-btn, .ghost-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.icon-btn { width: 36px; height: 36px; font-size: 15px; }
.ghost-btn { padding: 6px 12px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.ghost-btn.small { padding: 3px 10px; font-size: 12px; }

/* ==========================================
   Cards, charts, tables
   ========================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  scroll-margin-top: 64px;      /* keep cards clear of the sticky top bar when scrolled to */
}
.chart-card { padding-bottom: 8px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chart-title { font-weight: 700; font-size: 16px; }
.chart-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.chart { width: 100%; }
.chart-rank { height: 520px; }
.chart-stock { height: 760px; }

.hint { color: var(--text-3); font-size: 12px; margin: 6px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.chips.selectable .chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); }
.chips.selectable .chip.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  font-size: 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 7px 8px; border-bottom: 1px solid var(--grid); }
.table td:first-child { white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }

.sid { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 0.9em; }
.muted { color: var(--text-2); }
.up { color: var(--up); }
.down { color: var(--down); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.grid-2 .card { margin-bottom: 0; }

/* ==========================================
   Stock page
   ========================================== */
.search { position: relative; margin: 8px 0 12px; }
.search input {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.suggest {
  position: absolute;
  z-index: 15;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  max-height: 320px;
  overflow-y: auto;
}
.suggest li { padding: 8px 14px; cursor: pointer; }
.suggest li:hover { background: var(--surface-2); }

.stock-head { display: flex; justify-content: space-between; align-items: center; }
.watch-toggle { margin-top: 6px; }
.watch-toggle.on { color: var(--accent); border-color: var(--accent); }

/* small inline action inside a table row (remove from watchlist) */
.row-btn {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.row-btn:hover { color: var(--up); background: var(--surface-2); }
.stock-name { font-size: 20px; font-weight: 700; }
.price { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.price small { display: block; font-size: 14px; font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat-label { color: var(--text-2); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-foot { color: var(--text-3); font-size: 12px; }

.loading, .error {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
}
.loading { background: var(--surface-2); color: var(--text-2); }
.error { background: var(--up); color: #fff; }

/* ==========================================
   Login pages
   ========================================== */
.login-page { display: flex; justify-content: center; padding-top: 12vh; }
.login-card { max-width: 420px; width: 100%; text-align: center; padding: 28px 24px; }
.login-card h1 { font-size: 20px; margin: 12px 0 4px; }
.login-btn {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 20px;
  border-radius: 10px;
  background: #5865f2;          /* Discord blurple */
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

/* ==========================================
   Intel (experimental): shared reels / reports with AI summaries
   ========================================== */
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}
.intel-mode { margin: 10px 0 8px; }
.intel-form { display: flex; flex-direction: column; gap: 8px; }
.intel-form input[type=url], .intel-form textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
.intel-form input[type=file] { font: inherit; color: var(--text-2); }
.intel-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.intel-actions .hint { margin: 0; }
.primary-btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:disabled { opacity: .6; cursor: default; }

.intel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.intel-head a { color: var(--accent); margin-left: 4px; }
.status { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.status.done { color: var(--text); }
.status.failed { color: var(--up); }
.tldr { font-weight: 600; margin: 10px 0 4px; }
.points { margin: 4px 0 8px; padding-left: 20px; }
.points li { margin: 2px 0; }
.stock-chip { border: 1px solid var(--border); background: var(--surface); }
.stock-chip.up { border-color: var(--up); color: var(--up); }
.stock-chip.down { border-color: var(--down); color: var(--down); }
.error-text { color: var(--up); font-size: 13px; }
