:root {
  --bg: #0b0f19;
  --surface: #131b2e;
  --surface-2: #1a243b;
  --border: #23304d;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --up: #ef4444;
  --up-bg: rgba(239, 68, 68, 0.14);
  --down: #22c55e;
  --down-bg: rgba(34, 197, 94, 0.14);
  --flat: #94a3b8;
  --accent: #3b82f6;
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --radius: 14px;
  --nav-h: 62px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* Login Screen */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
}

.login-logo {
  font-size: 42px;
  margin-bottom: 8px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.login-sub {
  margin: 8px 0 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-card input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 14px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-error {
  margin-top: 12px;
  color: var(--up);
  font-size: 13px;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-accent {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-accent {
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  width: auto;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}

.text-btn {
  background: none;
  border: none;
  color: #60a5fa;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}

/* Top Bar */
.app-shell {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(11, 15, 25, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.top-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--down);
  box-shadow: 0 0 8px var(--down);
}

.pulse-dot.loading {
  background: var(--warn);
  box-shadow: 0 0 8px var(--warn);
}

.app-title {
  font-weight: 700;
  font-size: 16px;
}

.update-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.top-actions {
  display: flex;
  gap: 8px;
}

/* Main Content */
.main-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 14px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Hero Card */
.hero-card {
  background: linear-gradient(145deg, #162038, #111827);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 12px;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hero-right {
  text-align: right;
}

.hero-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.hero-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.hero-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.hero-pnl {
  font-size: 20px;
  font-weight: 700;
}

.hero-pnl-pct {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}

.hero-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.hero-actions button {
  flex: 1;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
}

.night-body {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.night-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.night-total {
  border-top: 1px dashed var(--border);
  padding-top: 6px;
  margin-top: 2px;
  font-weight: 700;
  color: var(--text);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.section-note {
  font-size: 12px;
  font-weight: 500;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

/* Quote Item Card */
.quote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.quote-card:active {
  background: var(--surface-2);
}

.fut-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
}

.fut-card:active {
  background: var(--surface-2);
}

.fut-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.fut-name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fut-price {
  font-size: 18px;
  font-weight: 700;
}

.fut-chg {
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
}

.q-left {
  min-width: 0;
  flex: 1;
}

.q-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.q-symbol {
  font-weight: 700;
  font-size: 15px;
}

.q-name {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.q-sub-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.q-right {
  text-align: right;
  flex-shrink: 0;
}

.q-price {
  font-size: 16px;
  font-weight: 700;
}

.q-chg-pill {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.q-chg-pill.up { background: var(--up-bg); color: var(--up); }
.q-chg-pill.down { background: var(--down-bg); color: var(--down); }
.q-chg-pill.flat { background: rgba(148, 163, 184, 0.14); color: var(--flat); }

.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-muted { background: var(--surface-2); color: var(--text-muted); }
.badge-night { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }
.badge-day { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge-warn { background: var(--warn-bg); color: #fbbf24; }
.badge-opp { background: var(--down-bg); color: #4ade80; }

.del-btn {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  margin-left: 6px;
  cursor: pointer;
}

/* Add Bar */
.add-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.add-bar input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.add-bar select {
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

/* Segmented Buttons */
.seg-group {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.full-seg {
  display: flex;
  width: 100%;
  margin-bottom: 12px;
}

.full-seg .seg-btn {
  flex: 1;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

/* Charts */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 190px;
}

.modal-chart-wrap {
  height: 240px;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  top: 6px;
  left: 8px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 25, 0.7);
  font-size: 13px;
  color: var(--text-muted);
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 6px 0;
}

.nav-item.active {
  color: #60a5fa;
}

.nav-icon { font-size: 18px; }
.nav-label { font-size: 11px; font-weight: 600; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 680px;
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--border);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 1;
}

.modal-sheet-tall {
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-body {
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding-top: 12px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.edit-holdings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-holding-row {
  display: grid;
  grid-template-columns: 76px 1fr 90px 34px;
  gap: 6px;
  align-items: center;
}

.edit-holding-row input {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 41, 59, 0.96);
  color: #f8fafc;
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  white-space: nowrap;
}
