/* style.css — 投資組合儀表板 + AI 診斷（含登入遮罩） */

: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}
.hidden{display:none !important}

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}

/* 使用者 chip */
.user-chip{
  display:flex; align-items:center; gap:8px;
  background:var(--panel);
  border:1px solid var(--border);
  color:var(--text);
  border-radius:999px; padding:6px 10px;
}
.user-chip img{width:24px;height:24px;border-radius:50%}

/* Danger button */
button.danger{background:#311b24; border-color:#4a2230; color:#ffdfe5}
button.danger:hover{background:#3a1f2a}

/* 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; position:relative}
.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：一排兩個（避免擠在一起） */
.kpis{display:grid; grid-template-columns:1fr; gap:10px}
.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.5vw,26px); overflow-wrap:anywhere}
@media (min-width:768px){ .kpis{grid-template-columns:repeat(2, minmax(0,1fr))} }
@media (min-width:1024px){
  .kpis{grid-template-columns:repeat(2, minmax(0,1fr))} /* 固定兩欄 */
  .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-med{height:320px}
.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}
tbody button{padding:8px 10px; min-height:40px}
.center{text-align:center}
.right{text-align:right}

/* Info box（診斷說明） */
.info-box{border:1px solid var(--border); border-radius:12px; padding:12px; background:rgba(255,255,255,.03); margin-bottom:12px}
.info-title{font-weight:700; margin-bottom:6px}

/* 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}
.diag-box{background:rgba(255,255,255,.03); border:1px solid var(--border); border-radius:12px; padding:12px}
.diag-box .title{font-weight:700; margin-bottom:6px}
.diag-box .hint{font-size:12px; color:var(--muted); margin-top:6px}

.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 1fr}
}

/* ===== AI 診斷「未登入鎖定」樣式 ===== */
#sec-ai{position:relative}
#sec-ai.locked > *:not(.lock-overlay){filter:blur(2px); pointer-events:none; user-select:none}
.lock-overlay{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  background:rgba(11,16,32,.86); border:1px solid var(--border);
  border-radius:var(--radius); z-index:5; text-align:center; padding:16px;
}
.lock-box{max-width:640px}
.lock-emoji{font-size:36px; margin-bottom:6px}
.lock-title{font-weight:800; font-size:18px; margin-bottom:4px}
.lock-desc{margin-bottom:10px}
.lock-actions button{background:var(--accent); color:#00101a; font-weight:700; border:none}

/* Trend section */
.chart-wrap + .muted.center{display:block;margin-top:6px}
