/* 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}

/* AI 診斷 legend */
.diag-legend{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
  position:relative;
  z-index:1;
}
.diag-legend .badge{
  white-space:nowrap;
  background:#132238;
  border:1px solid #27406b;
  border-radius:999px;
  padding:.25rem .6rem;
  color:#cbd6ff;
  font-size:.9rem;
  line-height:1.2;
  cursor:help;
}

/* ===== 走勢下方：單一股票資訊 ===== */
#sec-facts .facts-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap:12px;
}
#sec-facts .facts-grid > div{
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
#sec-facts .facts-grid span{
  display:block; color: var(--muted); font-size:12px; margin-bottom:6px;
}
#sec-facts .facts-grid b{ font-size:18px; font-weight:700; }
#sec-facts .small{ grid-column: 1 / -1; text-align:right; font-size:12px; opacity:.8; }

/* 漲跌色：改成台股習慣（漲紅跌綠） */
.up{ color: var(--danger); } /* + 漲：紅色 */
.down{ color: var(--ok); }   /* - 跌：綠色 */

/* 小型文字連結 */
.risk-link {
  font-size: 0.82rem;
  color: #93c5fd;
  opacity: 0.9;
  text-decoration: none;
}
.risk-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* 細框按鈕（banner 用） */
.risk-btn {
  padding: 6px 12px;
  border: 1px solid rgba(147,197,253,.55);
  border-radius: 8px;
  color: #93c5fd;
  font-size: 0.82rem;
  text-decoration: none;
  transition: 0.15s ease-out;
}
.risk-btn:hover {
  background: rgba(147,197,253,.1);
  border-color: rgba(147,197,253,.9);
}
/* ===== Financial tweaks：數字 & 表格 ===== */

/* 專門給數字用的字型（等寬 + tabular-nums） */
:root{
  --font-number: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
                 "Liberation Mono", "Courier New", monospace;
}

/* 通用數字樣式（之後有需要也可以自己在 HTML 上加 class="num"） */
.num{
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* KPI 數字用等寬字，感覺比較像報價系統 */
.kpi .value{
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.kpi .label{
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: none; /* 中文不會被亂改，但間距會更金融感 */
  opacity: .9;
}
/* 表格：數字右對齊 + 等寬數字 + 條紋 & hover 高亮 */
table th,
table td{
  font-variant-numeric: tabular-nums;
}

/* 所有右對齊欄位：用等寬字（持股數、價格、市值、比例等） */
td.right,
th.right{
  font-family: var(--font-number);
  letter-spacing: 0.02em;
}

/* Zebra 條紋 + hover 高亮 */
tbody tr:nth-child(even) td{
  background: rgba(15,23,48,.6);
}

tbody tr:hover td{
  background: #111a3d;
}

/* 底部輸入列上方多一條「收斂」的線，像報價系統的合計列 */
tfoot td{
  border-top: 1px solid rgba(148,163,184,.8);
  font-size: 13px;
  color: var(--muted);
}

/* AI 診斷持股表也套用同樣的數字感 */
.diag-holdings th.right,
.diag-holdings td.right{
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* 圖表區塊：加細框 + 淡淡的金融感底色 */
.chart-box{
  background: radial-gradient(circle at top,
              rgba(148,163,184,.14),
              transparent 55%);
  border: 1px solid rgba(148,163,184,.28);
  border-radius: 12px;
  padding: 4px 8px 8px;
}
/* ===== 單一股票歷史走勢（手機排版優化） ===== */
@media (max-width: 640px) {
  #sec-trend .chart-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  #sec-trend .chart-toolbar label {
    flex: 1 1 calc(50% - 10px);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
  }

  #sec-trend .chart-toolbar input,
  #sec-trend .chart-toolbar select {
    width: 100%;
    height: 42px;
    padding: 8px 10px;
    border-radius: 10px;
  }

  #sec-trend #trend-btn {
    flex: 1 1 100%;
    height: 44px;
    border-radius: 12px;
  }
}
/* === 股票代號搜尋建議（類 Google 下拉） === */
.symbol-suggest-panel {
  position: absolute;
  z-index: 60;
  display: none;
  max-height: 320px;
  overflow-y: auto;
  background: #020617;
  border-radius: 14px;
  border: 1px solid rgba(148,163,184,.55);
  box-shadow: 0 20px 50px rgba(15,23,42,.95);
  padding: 4px 0;
  font-size: 0.85rem;
}

.symbol-suggest-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

.symbol-suggest-item:hover,
.symbol-suggest-item.is-active {
  background: rgba(15,23,42,.96);
}

.symbol-suggest-code {
  font-weight: 600;
  letter-spacing: .02em;
  min-width: 76px;
}

.symbol-suggest-name {
  flex: 1;
  color: #cbd5f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.symbol-suggest-market {
  font-size: 0.75rem;
  color: #94a3b8;
}
/* === Global entrance animations（全站淡淡進場動畫） === */

@keyframes fade-up-soft {
  from {
    opacity: 0;
    transform: translateY(8px);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes fade-down-soft {
  from {
    opacity: 0;
    transform: translateY(-6px);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}
/* Header entrance：頂部列輕微下滑淡入 */
.app-header,
.ann-header,
.site-header,
.stock-nav {
  animation: fade-down-soft 0.42s cubic-bezier(0.17, 0.84, 0.44, 1) 0.02s both;
}

/* Cards & KPI entrance：主要內容卡片輕微上浮淡入 */
.card,
.kpi,
.kpis .kpi,
#sec-facts .facts-grid > div,
.diag-box,
.info-box {
  animation: fade-up-soft 0.45s cubic-bezier(0.17, 0.84, 0.44, 1) 0.08s both;
}

/* ====== stockLAB 黑色高級 tooltip ====== */
.tooltip-box {
  position: fixed;
  pointer-events: none;
  background: rgba(15, 15, 20, 0.98);
  color: #e5e7eb;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  z-index: 9999;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .15s ease, transform .15s ease;
}

.tooltip-box.show {
  opacity: 1;
  transform: translateY(0);
}
