:root {
  --bg: #080d17;
  --bg-card: #101829;
  --bg-elev: #162138;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --dim: #64748b;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.14);
  --red: #f43f5e;
  --red-bg: rgba(244, 63, 94, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --cyan: #06b6d4;
  --cyan-bg: rgba(6, 182, 212, 0.15);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.16);
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, monospace;
}

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

body {
  background: radial-gradient(circle at top right, #12213b 0%, var(--bg) 52%);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.warn { color: var(--amber); }

/* 登入鎖屏 */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(16, 185, 129, 0.08), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(59, 130, 246, 0.1), transparent 45%),
              var(--bg);
  z-index: 100;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.login-logo { font-size: 40px; margin-bottom: 10px; }
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }

.login-card form { text-align: left; display: flex; flex-direction: column; gap: 12px; }
.login-card label { font-size: 13px; color: var(--muted); font-weight: 500; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.login-card input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18); }

.login-error {
  font-size: 13px;
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: 8px;
  padding: 9px 12px;
}

.login-foot { font-size: 12px; color: var(--dim); margin-top: 18px; }

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #10b981);
  color: #04131c;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { opacity: 0.92; }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 9px 16px; font-size: 13px; }

/* 頂部導覽列 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(8, 13, 23, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}
.brand-dot.delayed { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.brand-dot.stale { background: var(--red); box-shadow: 0 0 10px var(--red); }
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: 0.3px; }

.header-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.control-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.last-sync { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-elev);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill-green { background: var(--green-bg); color: var(--green); border-color: rgba(16, 185, 129, 0.3); }
.pill-red { background: var(--red-bg); color: var(--red); border-color: rgba(244, 63, 94, 0.3); }
.pill-amber { background: var(--amber-bg); color: var(--amber); border-color: rgba(245, 158, 11, 0.3); }
.pill-cyan { background: var(--cyan-bg); color: var(--cyan); border-color: rgba(6, 182, 212, 0.35); }
.pill-blue { background: var(--blue-bg); color: #60a5fa; border-color: rgba(59, 130, 246, 0.3); }
.pill-readonly { background: rgba(148, 163, 184, 0.12); color: #cbd5e1; }
.pill-v4 { background: var(--cyan-bg); color: var(--cyan); border-color: rgba(6, 182, 212, 0.25); }

.btn-ghost, .select-compact {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
}
.btn-ghost:hover, .select-compact:hover { border-color: var(--border-strong); }
.btn-danger-subtle { color: #fda4af; }

/* 主容器 */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-tag { font-size: 10px; color: var(--dim); font-family: var(--font-mono); }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.kpi-value-sm { font-size: 16px; font-weight: 700; line-height: 1.35; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.split-bar-wrap, .dd-meter-wrap { display: flex; flex-direction: column; gap: 5px; margin-top: 2px; }
.split-bar, .dd-meter {
  height: 6px;
  width: 100%;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  overflow: hidden;
}
.split-bar-crypto { height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width 0.35s ease; }
.dd-meter-fill { height: 100%; background: linear-gradient(90deg, var(--amber), var(--red)); transition: width 0.35s ease; }
.split-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* Section headers */
.section-card { display: flex; flex-direction: column; gap: 16px; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.section-head h2 { font-size: 16px; font-weight: 700; }
.section-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Segmented buttons */
.chart-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-group {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
}
.seg-btn.active { background: rgba(59, 130, 246, 0.25); color: #e0f2fe; font-weight: 600; }

/* Charts */
.chart-box-main { position: relative; height: 290px; width: 100%; }
.chart-box-dd { position: relative; height: 120px; width: 100%; padding-top: 6px; border-top: 1px solid var(--border); }
.subchart-title { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

/* Positions Grid */
.positions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 28px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
}
.pos-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pos-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pos-sym { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.pos-pnl { text-align: right; }
.pos-pnl-usd { font-size: 16px; font-weight: 700; display: block; }
.pos-pnl-pct { font-size: 12px; }
.pos-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.pos-metric span { display: block; font-size: 11px; color: var(--muted); }
.pos-metric strong { font-size: 13px; }
.pos-bars { display: flex; flex-direction: column; gap: 7px; font-size: 11px; color: var(--muted); }
.progress-track { height: 6px; background: rgba(148, 163, 184, 0.18); border-radius: 999px; overflow: hidden; margin-top: 3px; }
.progress-fill-safe { height: 100%; background: linear-gradient(90deg, var(--green), var(--cyan)); }
.progress-fill-warn { height: 100%; background: linear-gradient(90deg, var(--amber), var(--red)); }
.progress-fill-time { height: 100%; background: var(--blue); }

/* Thoughts */
.thought-hero {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.06), rgba(59, 130, 246, 0.07));
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thought-hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; }
.thought-hero h3 { font-size: 16px; font-weight: 700; color: #f8fafc; }
.thought-bullets { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.thought-bullets li {
  position: relative;
  padding-left: 16px;
  font-size: 13px;
  color: #cbd5e1;
}
.thought-bullets li::before {
  content: "•";
  position: absolute;
  left: 3px;
  color: var(--cyan);
  font-weight: 700;
}
.thought-actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; border-top: 1px solid var(--border); }

.radar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}
.radar-head h3 { font-size: 14px; font-weight: 700; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 720px; }
.data-table th {
  text-align: left;
  padding: 9px 10px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: rgba(148, 163, 184, 0.05); }
.score-bar-cell { display: flex; align-items: center; gap: 6px; }
.score-bar { width: 52px; height: 5px; background: rgba(148, 163, 184, 0.16); border-radius: 999px; overflow: hidden; }
.score-bar > span { display: block; height: 100%; background: var(--cyan); }
.reason-cell { white-space: normal; min-width: 190px; }

/* Gemini Drawer */
.gemini-drawer {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.gemini-drawer summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #bae6fd;
  list-style: none;
}
.gemini-body { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.gemini-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
}
.chip-btn:hover { background: rgba(59, 130, 246, 0.22); }
.gemini-form { display: flex; gap: 8px; }
.gemini-form input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.gemini-answer {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.6;
  color: #e2e8f0;
}

/* Trade Stats Strip */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}
.stat-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-k { font-size: 11px; color: var(--muted); }
.stat-box strong { font-size: 15px; }

.footer {
  text-align: center;
  padding: 14px 16px 28px;
  font-size: 12px;
  color: var(--dim);
}

/* Responsive */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .positions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .positions-grid { grid-template-columns: 1fr; }
  .stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 10px 12px; }
  .card { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .chart-box-main { height: 230px; }
}
