:root {
  /* 主色 — 深色奢華 */
  --bg: #0a0d14;
  --bg-grad: radial-gradient(at 0% 0%, #1a1530 0%, transparent 50%),
             radial-gradient(at 100% 0%, #0d1a2e 0%, transparent 50%),
             #0a0d14;
  --panel: rgba(20, 25, 38, 0.7);
  --panel-solid: #141926;
  --panel-2: #1a2030;
  --panel-3: #232b40;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);

  --text: #f1f4fa;
  --text-2: #c1c9da;
  --muted: #7a8499;
  --subtle: #4d5670;

  /* 品牌 */
  --brand: #818cf8;
  --brand-2: #c084fc;
  --brand-grad: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;

  /* 台股漲跌 */
  --up: #ff5470;
  --up-soft: rgba(255, 84, 112, 0.12);
  --up-glow: rgba(255, 84, 112, 0.35);
  --down: #34d399;
  --down-soft: rgba(52, 211, 153, 0.12);
  --down-glow: rgba(52, 211, 153, 0.35);
  --flat: #7a8499;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --glow: 0 0 60px rgba(129, 140, 248, 0.15);

  /* 圓角 */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;

  /* 字 */
  --num-font: "SF Mono", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 10px; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", -apple-system, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

button { font-family: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.hidden { display: none !important; }

/* 漲跌色 */
.up    { color: var(--up); }
.down  { color: var(--down); }
.flat  { color: var(--flat); }

/* ═══════════════════════════ TopBar ═══════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: rgba(10, 13, 20, 0.6);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  background: var(--brand-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.topbar-right {
  display: flex;
  gap: 14px;
  align-items: center;
}
#updatedAt::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--down);
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: 0 0 8px var(--down-glow);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ═══════════════════════════ Buttons ═══════════════════════════ */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 8px 16px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn:hover {
  background: var(--panel-3);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--brand-grad);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(129, 140, 248, 0.35);
}
.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(129, 140, 248, 0.5);
  filter: brightness(1.1);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border-strong);
}

.btn-danger {
  background: transparent;
  color: var(--down);
  border-color: rgba(52, 211, 153, 0.3);
}
.btn-danger:hover {
  background: var(--down-soft);
  border-color: var(--down);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--panel-3); color: var(--text); }

/* ═══════════════════════════ Dashboard KPI ═══════════════════════════ */
.dashboard {
  padding: 28px 32px 0;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.kpi-card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s;
}
.kpi-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--brand-grad);
  opacity: 0.6;
}
.kpi-card:nth-child(1)::before { background: linear-gradient(90deg, #818cf8, #6366f1); }
.kpi-card:nth-child(2)::before { background: linear-gradient(90deg, #c084fc, #a855f7); }
.kpi-card:nth-child(3)::before { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.kpi-card:nth-child(4)::before { background: linear-gradient(90deg, #34d399, #10b981); }
.kpi-card:nth-child(5)::before { background: linear-gradient(90deg, #ff5470, #ec4899); }
.kpi-card:nth-child(6)::before { background: linear-gradient(90deg, #06b6d4, #3b82f6); }

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--num-font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* ═══════════════════════════ Rankings ═══════════════════════════ */
.rankings {
  padding: 24px 32px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.rank-card {
  position: relative;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px 24px;
  overflow: hidden;
  transition: all 0.2s;
}
.rank-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.rank-card::after {
  content: "";
  position: absolute;
  top: -50%;
  right: -30%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.15;
  pointer-events: none;
}
.rank-card:nth-child(1)::after { background: var(--gold); }
.rank-card:nth-child(2)::after { background: var(--up); }
.rank-card:nth-child(3)::after { background: var(--brand); }

.rank-title {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.rank-main {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.4;
}
.rank-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.7;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════ Block ═══════════════════════════ */
.block {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  margin: 0 32px 24px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px 24px;
}
.block h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.block-header h2 { margin: 0; }

/* ═══════════════════════════ 投資成本佔比 ═══════════════════════════ */
.ratio-bar {
  display: flex;
  height: 32px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.ratio-bar > div {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  transition: all 0.3s ease;
  position: relative;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.ratio-bar > div:hover {
  filter: brightness(1.15);
  transform: scaleY(1.05);
}
.ratio-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 14px;
  font-size: 12px;
}
.ratio-legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  padding: 4px 10px;
  background: var(--panel-2);
  border-radius: 20px;
  border: 1px solid var(--border);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ═══════════════════════════ Table ═══════════════════════════ */
.table-wrap {
  overflow-x: auto;
  margin: 0 -8px;
}
.stock-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 1200px;
}
.stock-table th {
  text-align: left;
  padding: 12px 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
}
.stock-table th:first-child { border-top-left-radius: var(--r-sm); }
.stock-table th:last-child { border-top-right-radius: var(--r-sm); }
.stock-table th.num { text-align: right; }
.stock-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.stock-table tbody tr {
  transition: background 0.15s;
}
.stock-table tbody tr:hover {
  background: rgba(129, 140, 248, 0.04);
}
.stock-table .symbol-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stock-table .symbol-cell .symbol {
  font-weight: 700;
  font-family: var(--num-font);
  font-size: 14px;
  color: var(--text);
}
.stock-table .symbol-cell .name {
  color: var(--muted);
  font-size: 12px;
}
.stock-table .row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.stock-table .row-actions .btn {
  padding: 5px 12px;
  font-size: 12px;
}

/* 大數字加粗 */
.stock-table .num { font-weight: 500; }

/* ═══════════════════════════ Sub Table ═══════════════════════════ */
.sub-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sub-table th, .sub-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.sub-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sub-table th.num, .sub-table td.num { text-align: right; }

/* ═══════════════════════════ Modal ═══════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-box {
  position: relative;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: 0;
  width: 92%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg), var(--glow);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-box-wide { max-width: 920px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

/* ═══════════════════════════ Form ═══════════════════════════ */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-row input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.15s;
}
.form-row input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.lookup-hint {
  margin: 8px 0 4px;
  padding: 8px 12px;
  background: var(--panel-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

/* ═══════════════════════════ Detail Tabs ═══════════════════════════ */
.detail-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s;
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--brand);
}
.pane-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

/* ═══════════════════════════ Detail Grid ═══════════════════════════ */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.detail-cell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  transition: border-color 0.15s;
}
.detail-cell:hover { border-color: var(--border-strong); }
.detail-cell .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.detail-cell .value {
  font-size: 17px;
  font-weight: 700;
  margin-top: 4px;
  font-family: var(--num-font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ═══════════════════════════ Toast ═══════════════════════════ */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--r-sm);
  z-index: 200;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.toast.error { border-color: var(--up); color: var(--up); }
.toast.success { border-color: var(--down); color: var(--down); }

/* ═══════════════════════════ RWD ═══════════════════════════ */
@media (max-width: 768px) {
  .topbar { padding: 14px 18px; }
  .topbar h1 { font-size: 17px; }
  .dashboard, .rankings { padding-left: 18px; padding-right: 18px; }
  .block { margin-left: 18px; margin-right: 18px; padding: 18px; }
  .kpi-value { font-size: 22px; }
  .rank-main { font-size: 16px; }
}
