:root {
  --bg: #070b14;
  --bg-elev: #0e1526;
  --bg-card: #11192e;
  --bg-card-hover: #16213b;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.25);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* 台股慣例：紅漲綠跌 */
  --tw-up: #fb7185;
  --tw-up-bg: rgba(244, 63, 94, 0.14);
  --tw-down: #34d399;
  --tw-down-bg: rgba(16, 185, 129, 0.14);

  --accent: #38bdf8;
  --accent-indigo: #818cf8;
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.14);
  --radius: 14px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 12% 0%, rgba(56, 189, 248, 0.08), transparent 40%),
              radial-gradient(circle at 88% 10%, rgba(129, 140, 248, 0.08), transparent 36%),
              var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app-shell {
  max-width: 1460px;
  margin: 0 auto;
  padding: 20px 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, rgba(17, 25, 46, 0.96), rgba(14, 21, 38, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  color: #070b14;
  font-weight: 800;
  font-size: 18px;
  display: grid;
  place-items: center;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-title-row h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-subtitle {
  color: var(--text-muted);
  font-size: 0.84rem;
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-virtual {
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge-cron {
  background: rgba(16, 185, 129, 0.13);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.cron-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
  display: inline-block;
}

.cron-sub {
  color: #7dd3fc;
  font-size: 0.76rem;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.btn-auth {
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  padding: 8px 12px;
  font-size: 0.8rem;
}

.btn-auth.unlocked {
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.4);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 0.86rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.28);
}

.btn-secondary {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.3);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.12);
  color: var(--tw-up);
  border-color: rgba(244, 63, 94, 0.3);
}

.status-banner {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.86rem;
  color: #bae6fd;
}

.hidden {
  display: none !important;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.kpi-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

/* Panels */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-header h2 {
  font-size: 1.02rem;
  font-weight: 700;
}

.panel-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Chart */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-ai {
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.7);
}

.dot-bench {
  background: #94a3b8;
}

.backtest-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stat-pill {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.8rem;
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}

.stat-pill span {
  color: var(--text-muted);
}

.stat-pill strong {
  color: var(--text);
}

.chart-container {
  position: relative;
  width: 100%;
  height: 320px;
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.equity-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(7, 11, 20, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 0.78rem;
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  min-width: 195px;
  z-index: 10;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip .tt-date {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 5px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.chart-tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3px;
}

/* Grids & Tables */
.two-col-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap.scroll-y {
  max-height: 360px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.76rem;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

tbody td {
  padding: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(56, 189, 248, 0.04);
}

.num {
  text-align: right;
  white-space: nowrap;
}

.empty-cell {
  text-align: center;
  color: var(--text-dim);
  padding: 26px 12px;
}

.ticker-cell {
  display: flex;
  flex-direction: column;
}

.ticker-code {
  font-weight: 700;
  color: var(--text);
}

.ticker-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Color utility classes (台股：紅漲綠跌) */
.up {
  color: var(--tw-up);
}

.down {
  color: var(--tw-down);
}

.neutral {
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.73rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill-buy {
  background: var(--tw-up-bg);
  color: var(--tw-up);
  border: 1px solid rgba(244, 63, 94, 0.35);
}

.pill-sell {
  background: var(--tw-down-bg);
  color: var(--tw-down);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.pill-hold {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.pill-bull {
  background: var(--tw-up-bg);
  color: var(--tw-up);
}

.pill-bear {
  background: var(--tw-down-bg);
  color: var(--tw-down);
}

.pill-neutral {
  background: var(--warn-bg);
  color: var(--warn);
}

/* Probability Bar */
.prob-wrap {
  min-width: 115px;
}

.prob-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  margin-bottom: 4px;
}

.prob-bar {
  height: 6px;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  overflow: hidden;
}

.prob-fill {
  height: 100%;
  border-radius: 999px;
}

.reason-cell {
  max-width: 280px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Feeds */
.feed-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 430px;
  overflow-y: auto;
  padding-right: 4px;
}

.feed-item {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feed-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.feed-title {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}

.feed-title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.ticker-tag {
  background: rgba(129, 140, 248, 0.16);
  color: #c7d2fe;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

.decision-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.decision-line strong {
  color: var(--text);
}

/* Footer & Toast */
.footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 6px 4px;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}

.toast {
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}

.toast.error {
  border-color: rgba(244, 63, 94, 0.6);
  color: #fecdd3;
}

/* Admin Passcode Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(160deg, #11192e, #0c1324);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.modal-input {
  width: 100%;
  background: rgba(7, 11, 20, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
}

.modal-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.modal-error {
  font-size: 0.8rem;
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .two-col-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .app-shell {
    padding: 14px;
  }
}
