:root {
  --bg: #0f1420;
  --bg-panel: #171e2e;
  --bg-panel-2: #1d2537;
  --border: #2a3450;
  --text: #e8ecf5;
  --text-dim: #8b95ab;
  --red: #ff5c5c;      /* 台股習慣：紅漲 */
  --green: #2ecc8f;    /* 綠跌 */
  --accent: #4f8cff;
  --accent-2: #ffb347;
  --radius: 14px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ── 頂部列 ─────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 20, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.update-time { color: var(--text-dim); font-size: 12px; margin-right: 4px; }

/* ── Google 登入門檻 ───────────────── */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-gate[hidden] { display: none; }
.auth-card {
  background: linear-gradient(145deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 44px;
  width: min(520px, 94vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.auth-logo { font-size: 44px; }
.auth-sub { color: var(--text-dim); }
.auth-message { color: var(--accent-2); font-size: 13px; min-height: 1em; }
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 300px;
}
.login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 15px;
  text-align: center;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.btn-login { padding: 11px; font-size: 15px; }

/* ── 頁籤 ─────────────────────────── */
.tabs {
  background: rgba(15, 20, 32, 0.92);
  border-bottom: 1px solid var(--border);
}
.tabs-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 4px;
}
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  font-family: inherit;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  font-weight: 700;
  border-bottom-color: var(--accent);
}
.tab-page { display: flex; flex-direction: column; gap: 22px; }
.tab-page[hidden] { display: none; }

/* ── 按鈕 ─────────────────────────── */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.2); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-accent { background: #d64545; border-color: #d64545; }
.btn-ghost { background: transparent; }
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg-panel-2); color: var(--text); }

/* ── 版面 ─────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ── 總覽卡片 ─────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: linear-gradient(145deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.card-label { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── 面板 ─────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 22px 12px;
}
.panel-header h2 { font-size: 16px; font-weight: 700; }
.hint { color: var(--text-dim); font-size: 12px; }
.panel-header-actions { display: flex; align-items: center; gap: 12px; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.muted { color: var(--text-dim); }

/* ── 表格 ─────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 14px; white-space: nowrap; }
thead th {
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.num, td.num { text-align: right; }
tbody tr { border-bottom: 1px solid rgba(42, 52, 80, 0.5); cursor: pointer; }
tbody tr:hover { background: var(--bg-panel-2); }
tfoot td { font-weight: 700; border-top: 1px solid var(--border); background: var(--bg-panel-2); }
.pos { color: var(--red); }
.neg { color: var(--green); }
.tag-etf {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ── 圖表 ─────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 22px;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-box { padding: 10px 22px 22px; height: 340px; position: relative; }

/* ── 分析 ─────────────────────────── */
.analysis { padding: 6px 22px 22px; display: flex; flex-direction: column; gap: 10px; }
.insight {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}
.insight .icon { font-size: 18px; line-height: 1.4; }
.insight.warn { border-color: rgba(255, 179, 71, 0.5); }
.insight.good { border-color: rgba(46, 204, 143, 0.5); }
.insight.bad { border-color: rgba(255, 92, 92, 0.5); }
.insight b { font-weight: 700; }

/* ── 彈窗 ─────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  width: min(480px, 92vw);
}
.modal h3 { margin-bottom: 18px; font-size: 18px; }
.form-row { display: flex; gap: 14px; margin-bottom: 14px; }
.form-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
}
.form-row input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 15px;
}
.form-row input:focus { outline: none; border-color: var(--accent); }
.form-hint { color: var(--text-dim); font-size: 12px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Toast ────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
