:root {
  /* === Modern Fintech Dark Theme（對齊大型系統）=== */
  --primary: #6366f1;        /* indigo */
  --primary-2: #8b5cf6;      /* violet */
  --accent: #06b6d4;         /* cyan */
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;

  --bg: #0b1020;
  --bg-2: #1a1f3a;
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.10);

  --text: #e5e7eb;
  --text-strong: #f8fafc;
  --muted: #94a3b8;
  --muted2: #5f6776;

  --press-bg: rgba(239, 68, 68, .14);
  --press-fg: #f87171;
  --close-bg: rgba(255, 255, 255, .06);
  --support-bg: rgba(34, 197, 94, .14);
  --support-fg: #4ade80;

  --grad-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  --grad-bg: linear-gradient(135deg, #0b1020 0%, #1a1f3a 50%, #16213e 100%);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, .35);
  --radius: 20px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100vh; }
body {
  background: var(--grad-bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
               -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}
/* 背景光暈，營造立體層次（與大型系統一致）*/
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 15% 8%,  rgba(99,102,241,0.20), transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(6,182,212,0.16),  transparent 38%),
    radial-gradient(circle at 50% 95%, rgba(139,92,246,0.18), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px calc(48px + env(safe-area-inset-bottom));
}

/* ── 標題 ── */
.header { margin: 4px 0 18px; }
.header-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-strong);
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-title .bi { color: var(--accent); }
.header-sub { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: .72rem;
  font-weight: 400;
  color: var(--muted);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 5px 12px;
}

/* ── 通用面板 ── */
.panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-bottom: 16px;
}
.panel.controls { position: relative; z-index: 20; }

/* ── 頁籤 ── */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tab:hover { border-color: var(--primary); color: var(--text); }
.tab.active { background: var(--grad-primary); color: #fff; border-color: transparent; }

/* ── 搜尋列 ── */
.searchbar { display: flex; gap: 8px; margin-top: 12px; }
#search {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 1rem;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  outline: none;
}
#search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, .25); }
#search::placeholder { color: var(--muted); }
.icon-btn {
  flex: 0 0 auto;
  width: 48px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--primary); color: var(--accent); }

/* ── 搜尋結果 ── */
.results {
  list-style: none;
  margin: 10px 0 0;
  padding: 6px;
  background: rgba(20, 24, 48, .96);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  max-height: 340px;
  overflow-y: auto;
}
.results li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
}
.results li:hover, .results li:active { background: rgba(99, 102, 241, .18); }
.results .r-name { font-weight: 600; color: var(--text-strong); }
.results .r-code { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.results .r-tag {
  font-size: .72rem;
  color: var(--muted);
  background: rgba(255, 255, 255, .06);
  border-radius: 6px;
  padding: 2px 8px;
}
.results .r-empty { padding: 16px; text-align: center; color: var(--muted); }

.status { text-align: center; color: var(--muted); font-size: .76rem; margin: 12px 0 0; line-height: 1.5; }
.status.error { color: var(--press-fg); }

/* ── 結果卡片 ── */
.share-area { background: transparent; padding: 2px; }
.card {
  background: linear-gradient(160deg, #1a2138 0%, #141a2e 100%);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 22px;
}
.placeholder-card { display: flex; align-items: center; justify-content: center; min-height: 180px; }
.placeholder { color: var(--muted); font-size: .95rem; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}
.stock-title {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-strong);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.limit-badge { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.limit-up { background: #dc2626; color: #fff; }
.limit-down { background: #16a34a; color: #fff; }
.sim-date { color: var(--accent); font-weight: 700; font-size: .95rem; margin-top: 4px; }

.badge {
  flex: 0 0 auto;
  font-size: .85rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(99, 102, 241, .2);
  color: #a5b4fc;
}
.badge.上櫃 { background: rgba(168, 85, 247, .2); color: #c4b5fd; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 18px;
  border-radius: 13px;
  margin-bottom: 10px;
}
.row:last-child { margin-bottom: 0; }
.row .label { font-size: 1.1rem; font-weight: 700; }
.row .val { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.row-press { background: var(--press-bg); }
.row-press .label, .row-press .val { color: var(--press-fg); }
.row-close { background: var(--close-bg); }
.row-close .label, .row-close .val { color: var(--text-strong); }
.row-support { background: var(--support-bg); }
.row-support .label, .row-support .val { color: var(--support-fg); }

/* 漲停：紅底白字 / 跌停：綠底白字 */
.row-limit-up { background: #dc2626 !important; }
.row-limit-up .label, .row-limit-up .val { color: #fff !important; }
.row-limit-down { background: #16a34a !important; }
.row-limit-down .label, .row-limit-down .val { color: #fff !important; }

.disclaimer {
  text-align: center;
  color: var(--press-fg);
  font-weight: 700;
  font-size: .9rem;
  margin: 16px 6px 0;
  line-height: 1.5;
}

.card-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.action-btn {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  padding: 11px 22px;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
}
.action-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.primary-btn {
  border: none;
  background: var(--grad-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, .4);
}
.primary-btn:disabled { box-shadow: none; }
.method-label { font-size: .8rem; color: var(--muted); }

/* ── 即時分價量面板 ── */
.live {
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--card-border);
}
.live.hidden { display: none !important; }
.live-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}
.live-head .bi-broadcast { color: var(--red); }
.live-time { font-size: .74rem; color: var(--muted); font-weight: 400; }
.live-price { display: flex; align-items: baseline; gap: 10px; margin: 10px 0 12px; }
#live-now { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.live-chg { font-size: 1rem; font-weight: 700; }

/* 分價量階梯（可捲動）*/
.ladder { display: flex; flex-direction: column; gap: 2px; max-height: 420px; overflow-y: auto; }
.ladder::-webkit-scrollbar { width: 4px; }
.ladder::-webkit-scrollbar-thumb { background: rgba(99, 102, 241, .4); border-radius: 2px; }

.lrow {
  display: grid;
  grid-template-columns: 30px 72px 1fr 58px;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
}
.lrow .l-tag { font-size: .78rem; font-weight: 800; text-align: center; }
.lrow .l-price { font-weight: 700; text-align: right; white-space: nowrap; }
.lrow .l-vol { text-align: right; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.lrow .l-bar-wrap { height: 14px; background: rgba(255, 255, 255, .04); border-radius: 4px; overflow: hidden; }
/* 內外盤拆分 bar：內盤(綠/賣方) + 外盤(紅/買方) */
.l-split { display: flex; height: 14px; border-radius: 4px; overflow: hidden; }
.l-split .l-bid { background: rgba(34, 197, 94, .8); }
.l-split .l-ask { background: rgba(239, 68, 68, .8); }

/* 標記 row 底色 */
.lrow.mark-press { background: rgba(239, 68, 68, .16); }
.lrow.mark-press .l-tag { color: var(--press-fg); }
.lrow.mark-support { background: rgba(34, 197, 94, .16); }
.lrow.mark-support .l-tag { color: var(--support-fg); }
.lrow.mark-avg .l-tag { color: #fff; }
.lrow.mark-open .l-tag { color: #fff; }
.lrow.now { background: rgba(255, 255, 255, .08); border: 1px solid var(--card-border); }
.lrow.now .l-price { color: var(--text-strong); font-size: 1rem; }
.lrow.now .l-tag { color: var(--yellow); }

.live-dist { display: flex; justify-content: space-between; margin-top: 12px; font-size: .85rem; color: var(--muted); }
.live-dist b { color: var(--text-strong); font-variant-numeric: tabular-nums; }
.ladder-note { margin-top: 8px; font-size: .72rem; color: var(--muted2); text-align: center; }

/* ── 設定視窗 ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal-box {
  background: #141a2e;
  border: 1px solid var(--card-border);
  width: 100%;
  max-width: 600px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-card);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 1.15rem; color: var(--text-strong); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field select, .field input {
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 1rem;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
}
.field-group { display: flex; gap: 12px; }
.field-group .field { flex: 1; }
.hint { font-size: .8rem; color: var(--muted); line-height: 1.5; margin: 2px 0 16px; }

.hidden { display: none !important; }

@media (min-width: 480px) {
  .modal { align-items: center; padding: 16px; }
  .modal-box { border-radius: 20px; }
}
