/* style.css — mobile-first + desktop overflow fix + TOC + Diagnosis */

:root{
  --bg:#0b1020;
  --panel:#101733;
  --panel-2:#0f1530;
  --border:#1f2a4a;
  --text:#e8eefc;
  --muted:#9fb0d3;
  --accent:#36e0ff;
  --danger:#ff6b81;
  --ok:#7ef0b8;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --radius:16px;
  --radius-lg:20px;
}

*{box-sizing:border-box}
html,body{height:100%}
html{scroll-behavior:smooth}
section{scroll-margin-top:96px}

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font:400 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

/* ====== Header ====== */
.app-header{
  position:sticky; top:0; z-index:20;
  background:linear-gradient(180deg, rgba(15,23,48,.95), rgba(15,23,48,.80));
  backdrop-filter: blur(8px);
  border-bottom:1px solid var(--border);
  padding:14px 16px;
  display:flex; align-items:center; justify-content:space-between;
  gap:12px;
}
.app-header h1{
  margin:0 0 2px 0;
  font-weight:700;
  font-size:clamp(18px, 2.4vw, 24px);
}
.muted{color:var(--muted); font-size:12px}
.muted.small{font-size:11px}
.toolbar{display:flex; align-items:center; gap:10px; flex-wrap:wrap}
.toolbar button{
  background:var(--panel);
  border:1px solid var(--border);
  color:var(--text);
  padding:10px 14px;
  border-radius:12px;
  cursor:pointer;
}
.toolbar button:hover{background:#151e3f}
.switch{display:flex; align-items:center; gap:8px; font-size:14px}

/* ====== TOC ====== */
.toc{
  position:sticky; top:72px; z-index:15;
  background:linear-gradient(180deg, rgba(11,16,32,.92), rgba(11,16,32,.86));
  border-bottom:1px solid var(--border);
  display:flex; gap:10px; align-items:center;
  padding:10px 12px;
  overflow:auto;
}
.toc a{
  white-space:nowrap;
  text-decoration:none;
  color:#cfe6ff;
  border:1px solid var(--border);
  padding:8px 12px;
  border-radius:999px;
  font-size:14px;
  background:#0f1731;
}
.toc a:hover{filter:brightness(1.1)}
.toc a.accent{background:var(--accent); color:#00101a; font-weight:700}

/* ====== 版面 Grid ====== */
main.grid{
  width:min(1280px, 100%);
  margin:16px auto;
  padding:0 12px 24px;
  display:grid;
  grid-template-columns:1fr;
  gap:16px;
}
.card{
  background:linear-gradient(180deg, var(--panel), var(--panel-2));
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:14px;
}
.card h3{margin:0 0 12px; font-size:18px}

.card.full{grid-column:1 / -1}
@media (min-width:1024px){
  main.grid{grid-template-columns:1fr 1fr}
  .card.full{grid-column:1 / 3}
}

/* ====== KPI 區（⚠️桌機固定 2 欄） ====== */
.kpis{
  display:grid;
  grid-template-columns:1fr; /* mobile: 1 欄 */
  gap:12px;
}
.kpi{
  background:rgba(255,255,255,.03);
  border:1px solid var(--border);
  border-radius:12px;
  padding:12px;
  min-height:96px;
  overflow:hidden;
}
.kpi .label{color:var(--muted); font-size:13px}
.kpi .value{
  font-weight:700; line-height:1.2; font-variant-numeric: tabular-nums;
  font-size:clamp(18px, 3.2vw, 26px);
  overflow-wrap:anywhere; word-break:break-word;
}

/* >=768px 起就 2 欄，桌機仍維持 2 欄（不再升到 4 欄） */
@media (min-width:768px){
  .kpis{grid-template-columns:repeat(2, minmax(0,1fr))}
}
@media (min-width:1024px){
  .kpi .value{font-size:clamp(18px, 1.8vw, 24px)}
}

/* ====== 圖表區 ====== */
.chart-toolbar{display:flex; align-items:center; gap:10px; flex-wrap:wrap}
.chart-toolbar label{display:flex; align-items:center; gap:6px}
.chart-toolbar input[type="text"], .chart-toolbar select{
  background:#0e1532; color:var(--text);
  border:1px solid var(--border); border-radius:10px;
  padding:10px 12px; min-height:44px;
}
.chart-toolbar button{
  background:var(--accent); color:#00101a; border:none;
  border-radius:12px; padding:10px 14px; font-weight:700; cursor:pointer;
}
.chart-toolbar button:hover{filter:brightness(1.05)}
.chart-wrap{margin-top:10px}
.chart-box{height:280px}
.chart-box.chart-lg{height:360px}
@media (max-width:480px){ .chart-box{height:220px} .chart-box.chart-lg{height:280px} }

/* ====== 表格（持股清單） ====== */
.table-wrap{
  overflow:auto;
  border:1px solid var(--border);
  border-radius:12px;
}
table{width:100%; border-collapse:separate; border-spacing:0; min-width:760px}
thead{position:sticky; top:0; z-index:1; background:#0f1530}
th,td{padding:12px 10px; border-bottom:1px solid var(--border)}
th{font-weight:600; color:#b9c7e6; text-align:left}
td.right, th.right{text-align:right}
tfoot td{border-bottom:0}
input[type="text"], input[type="number"]{
  width:100%; background:#0e1532; color:var(--text);
  border:1px solid var(--border); border-radius:10px;
  padding:10px 12px; min-height:44px;
}
button{
  background:#18224a; color:var(--text);
  border:1px solid var(--border); border-radius:12px;
  padding:10px 14px; min-height:44px; cursor:pointer;
}
button:hover{background:#1b2753}
button.danger{background:#311b24; border-color:#4a2230; color:#ffdfe5}
button.danger:hover{background:#3a1f2a}
tbody button{padding:8px 10px; min-height:40px}

.center{text-align:center}
.right{text-align:right}

/* ====== AI 診斷 ====== */
.badge{
  display:inline-block; padding:4px 10px; border-radius:999px;
  background:#11204a; border:1px solid var(--border);
  color:#cfe6ff; font-size:12px;
}
.badge.ok{background:#0d2a1e; border-color:#1a5a3f; color:#b5ffd5}
.badge.warn{background:#2a1b0d; border-color:#5a3a1a; color:#ffd9b5}
.badge.danger{background:#31161f; border-color:#5a2232; color:#ffd5df}

.diag-controls{
  display:grid; gap:12px; grid-template-columns:1fr;
  background:rgba(255,255,255,.03);
  border:1px solid var(--border); border-radius:12px; padding:12px;
  margin-bottom:10px;
}
.ctrl{display:flex; flex-direction:column; gap:6px}
.ctrl-label{font-weight:600; color:#c9d6ff}
.ctrl-row{display:flex; align-items:center; gap:10px; flex-wrap:wrap}
#profile-age{width:min(360px, 70vw)}
.diag-summary{
  display:grid; gap:10px; grid-template-columns:1fr;
  margin:10px 0 4px 0;
}
.diag-box{
  background:rgba(255,255,255,.03);
  border:1px solid var(--border); border-radius:12px; padding:12px;
}
.diag-holdings{
  margin-top:8px; border:1px solid var(--border); border-radius:12px;
  overflow:hidden;
}
.diag-holdings table{width:100%; border-collapse:separate; border-spacing:0}
.diag-holdings th, .diag-holdings td{padding:10px 8px; border-bottom:1px solid var(--border)}
.diag-holdings thead{background:#0f1530}
.diag-holdings tfoot td{border-bottom:0}

@media (min-width:768px){
  .diag-controls{grid-template-columns:1fr 1fr 1fr}
  .diag-summary{grid-template-columns:1fr 1fr}
}
