/* ══════════════════════════════════════════════════════════
   股票分析決策系統 — 設計系統
   金融終端風格，深色優先，台股紅漲綠跌慣例
   ══════════════════════════════════════════════════════════ */

/* ── 1. 設計代幣 ───────────────────────────────────────── */
:root {
  /* 淺色（預設） */
  --bg:            #F4F6FA;
  --surface:       #FFFFFF;
  --surface-2:     #EDF1F7;
  --surface-hover: #E4EAF3;
  --border:        #D8DFEA;
  --border-strong: #BFC9DA;
  --text:          #131722;
  --text-muted:    #5C6880;
  --text-faint:    #8A94A8;

  --accent:        #2563EB;
  --accent-soft:   rgba(37, 99, 235, .10);
  --accent-text:   #FFFFFF;

  /* 台股慣例：紅漲綠跌 */
  --up:            #E02F2F;   /* 漲／買進 */
  --up-soft:       rgba(224, 47, 47, .12);
  --down:          #00A65A;   /* 跌／賣出 */
  --down-soft:     rgba(0, 166, 90, .12);
  --flat:          #B07A0B;   /* 平／觀望 */
  --flat-soft:     rgba(176, 122, 11, .12);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow:    0 4px 16px -4px rgba(16, 24, 40, .12);
  --shadow-lg: 0 20px 48px -12px rgba(16, 24, 40, .22);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --nav-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI",
          "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg:            #0A0D14;
  --surface:       #12161F;
  --surface-2:     #1A1F2B;
  --surface-hover: #222836;
  --border:        #242B3A;
  --border-strong: #333C50;
  --text:          #E6E9EF;
  --text-muted:    #8E99AF;
  --text-faint:    #626C80;

  --accent:        #4F8CFF;
  --accent-soft:   rgba(79, 140, 255, .14);
  --accent-text:   #06090F;

  --up:            #FF4D5A;
  --up-soft:       rgba(255, 77, 90, .16);
  --down:          #00D68F;
  --down-soft:     rgba(0, 214, 143, .14);
  --flat:          #FFB020;
  --flat-soft:     rgba(255, 176, 32, .14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow:    0 4px 16px -4px rgba(0, 0, 0, .6);
  --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, .75);
}

/* ── 2. 基礎 ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .82rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ── 3. 版面 ──────────────────────────────────────────── */
.shell { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.page  { padding: 28px 0 64px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head .sub { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ── 4. 導覽列 ────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  height: 100%; display: flex; align-items: center; gap: 8px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: -.02em; color: var(--text);
  margin-right: 12px; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #7C4DFF);
  color: #fff; font-size: 15px; font-weight: 800;
}
.nav-links { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.nav-link {
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .9rem; font-weight: 500;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-user {
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; margin-left: 6px; border-left: 1px solid var(--border);
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
}
.icon-btn {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.theme-sun { display: none; }
.theme-moon { display: block; }
:root[data-theme="dark"] .theme-sun { display: block; }
:root[data-theme="dark"] .theme-moon { display: none; }

.nav-toggle { display: none; }
@media (max-width: 860px) {
  .nav-toggle { display: grid; margin-left: auto; }
  .nav-links {
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    padding: 10px 16px 16px; margin: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); display: none;
  }
  .nav-links.open { display: flex; }
  .nav-user { border-left: 0; border-top: 1px solid var(--border); padding: 10px 0 0; margin: 6px 0 0; }
}

/* ── 5. 卡片 ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-body { padding: 20px; }
.card-title { font-size: .95rem; font-weight: 650; }

/* ── 6. 搜尋列 ────────────────────────────────────────── */
.search { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.search .field { position: relative; flex: 1 1 260px; }
.search .field svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none;
}
.search input {
  width: 100%; height: 48px; padding: 0 14px 0 42px;
  font-size: 1rem; font-family: var(--mono); letter-spacing: .02em;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: .15s;
}
.search input::placeholder { font-family: var(--font); letter-spacing: 0; color: var(--text-faint); }
.search input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .btn { height: 48px; padding: 0 26px; font-size: .95rem; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.chip {
  padding: 5px 11px; border-radius: 999px; font-size: .8rem; font-weight: 500;
  color: var(--text-muted); background: var(--surface-2);
  border: 1px solid var(--border); cursor: pointer; transition: .15s;
}
.chip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }

/* ── 7. 按鈕 ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px;
  font: inherit; font-size: .88rem; font-weight: 600; line-height: 1;
  border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 4px 14px -4px var(--accent); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-danger { background: transparent; color: var(--up); border-color: rgba(224, 47, 47, .4); }
.btn-danger:hover:not(:disabled) { background: var(--up-soft); }
.btn-sm { height: 30px; padding: 0 11px; font-size: .8rem; }
.btn-block { width: 100%; }

/* ── 8. 決策橫幅 ──────────────────────────────────────── */
.verdict {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 28px; flex-wrap: wrap;
  padding: 24px 28px; margin-bottom: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.verdict::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 4px;
  background: var(--tone, var(--flat));
}
.verdict-id { min-width: 150px; }
.verdict-code { font-size: 2rem; font-weight: 750; letter-spacing: -.03em; line-height: 1.15; }
.verdict-meta { color: var(--text-muted); font-size: .84rem; }
.verdict-call { margin-left: auto; text-align: right; }
.verdict-tag {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 18px; border-radius: 999px;
  font-size: 1.05rem; font-weight: 700; letter-spacing: .04em;
  color: var(--tone); background: var(--tone-soft);
  border: 1px solid var(--tone);
}
.tone-buy  { --tone: var(--up);   --tone-soft: var(--up-soft); }
.tone-sell { --tone: var(--down); --tone-soft: var(--down-soft); }
.tone-hold { --tone: var(--flat); --tone-soft: var(--flat-soft); }
@media (max-width: 640px) {
  .verdict { gap: 18px; padding: 20px; }
  .verdict-call { margin-left: 0; text-align: left; width: 100%; }
}

/* ── 9. 分數環 ────────────────────────────────────────── */
.gauge { display: grid; place-items: center; position: relative; flex: none; }
.gauge-ring {
  width: 116px; height: 116px; border-radius: 50%;
  background: conic-gradient(var(--tone) calc(var(--pct) * 1%), var(--surface-2) 0);
  display: grid; place-items: center;
  transition: background .6s ease;
}
.gauge-ring::after {
  content: ""; position: absolute; width: 92px; height: 92px;
  border-radius: 50%; background: var(--surface);
}
.gauge-val { position: relative; z-index: 1; text-align: center; line-height: 1.1; }
.gauge-num { font-size: 1.85rem; font-weight: 750; color: var(--tone); font-family: var(--mono); }
.gauge-cap { font-size: .68rem; color: var(--text-faint); letter-spacing: .1em; }

/* ── 10. 統計格 ───────────────────────────────────────── */
.stat {
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.stat-label {
  font-size: .74rem; font-weight: 600; letter-spacing: .09em;
  color: var(--text-faint); text-transform: uppercase; margin-bottom: 8px;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; letter-spacing: -.02em; font-family: var(--mono); }
.stat-foot { margin-top: 10px; }

.bar { height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--tone, var(--accent)); transition: width .6s ease; }

/* ── 11. 分頁籤 ───────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; overflow-x: auto;
  padding: 4px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 8px 16px; border: 0; border-radius: var(--radius-sm);
  font: inherit; font-size: .87rem; font-weight: 550;
  color: var(--text-muted); background: transparent; cursor: pointer;
  white-space: nowrap; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tabpanel[hidden] { display: none; }

/* ── 12. 表格 ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  padding: 10px 14px; text-align: left; white-space: nowrap;
  font-size: .72rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
.tnum { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── 13. 徽章 ─────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 650; white-space: nowrap;
  color: var(--tone, var(--text-muted));
  background: var(--tone-soft, var(--surface-2));
  border: 1px solid currentColor;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-plain { --tone: var(--text-muted); --tone-soft: var(--surface-2); }
.badge-accent { --tone: var(--accent); --tone-soft: var(--accent-soft); }

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* ── 14. 表單 ─────────────────────────────────────────── */
.field-group { margin-bottom: 16px; }
label.lbl { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input, select.input {
  width: 100%; height: 42px; padding: 0 13px;
  font: inherit; font-size: .92rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); transition: .15s;
}
.input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: .78rem; color: var(--text-faint); margin-top: 5px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 160px; }
.form-row > .btn { flex: none; }

.range-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.range-row .lbl { margin: 0; width: 72px; flex: none; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row output { width: 56px; flex: none; text-align: right; font-family: var(--mono); font-weight: 650; font-size: .9rem; }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .87rem; cursor: pointer; transition: .15s;
}
.check:hover { border-color: var(--border-strong); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 550; }

/* ── 15. 提示條 ───────────────────────────────────────── */
.note {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px 16px; border-radius: var(--radius);
  font-size: .87rem; line-height: 1.55;
  color: var(--tone, var(--text-muted));
  background: var(--tone-soft, var(--surface-2));
  border: 1px solid currentColor;
}
.note svg { flex: none; margin-top: 2px; }
.note-error { --tone: var(--up); --tone-soft: var(--up-soft); }
.note-info  { --tone: var(--accent); --tone-soft: var(--accent-soft); }
.note-warn  { --tone: var(--flat); --tone-soft: var(--flat-soft); }

/* ── 16. 空狀態 ───────────────────────────────────────── */
.empty { padding: 56px 24px; text-align: center; }
.empty-mark {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); color: var(--text-faint);
}
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--text-muted); font-size: .9rem; max-width: 400px; margin: 0 auto; }

/* ── 17. 登入 ─────────────────────────────────────────── */
.auth { min-height: calc(100vh - var(--nav-h)); display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head .brand-mark { width: 46px; height: 46px; margin: 0 auto 14px; font-size: 20px; border-radius: 12px; }

/* ── 18. AI 解說 ──────────────────────────────────────── */
.ai-block {
  padding: 18px 20px; border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}
.ai-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-size: .78rem; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent);
}
.ai-block p { margin: 0; line-height: 1.8; }

/* ── 分析依據與查詢 loading ───────────────────────────── */
.evidence > summary { cursor: pointer; list-style: none; }
.evidence > summary::-webkit-details-marker { display: none; }
.evidence-grid { display: grid; gap: 12px; }
.evidence-step {
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.evidence-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.evidence-list { margin: 10px 0; padding-left: 20px; color: var(--text-muted); }
.evidence-list li + li { margin-top: 3px; }
.evidence-calc { padding-top: 9px; border-top: 1px dashed var(--border-strong); color: var(--text); }

.loading-overlay {
  position: fixed; inset: 0; z-index: 200; place-items: center;
  padding: 24px; background: rgb(5 10 20 / 68%); backdrop-filter: blur(3px);
}
.loading-overlay:not([hidden]) { display: grid; }
.loading-card {
  width: min(440px, 100%); display: flex; align-items: center; gap: 16px;
  padding: 22px; border-radius: var(--radius-lg); background: var(--surface);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
}
.spinner {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 19. Toast ────────────────────────────────────────── */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 16px; border-radius: var(--radius);
  font-size: .87rem; font-weight: 500;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: pop .22s ease;
}
.toast.err { border-color: var(--up); color: var(--up); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ── 20. 頁尾 ─────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--border);
  padding: 20px 0; margin-top: 40px;
  font-size: .8rem; color: var(--text-faint);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
