:root {
  --bg-base: #090d16;
  --bg-elevated: #111827;
  --bg-surface: #151e30;
  --bg-input: #0d1320;
  --bg-input-focus: #101829;
  --bg-hover: rgba(255, 255, 255, 0.035);
  --bg-topbar: rgba(9, 13, 22, 0.9);
  --bg-status: rgba(17, 24, 39, 0.7);
  --bg-th: rgba(13, 19, 32, 0.9);
  --bg-tfoot: rgba(13, 19, 32, 0.95);
  --bg-tooltip: rgba(9, 13, 22, 0.96);
  --bg-backdrop: rgba(2, 6, 23, 0.75);
  --bg-code: rgba(56, 189, 248, 0.1);
  --text-code: #bae6fd;

  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --placeholder: #475569;

  --accent: #38bdf8;
  --accent-indigo: #818cf8;
  --profit: #10b981;
  --profit-bg: rgba(16, 185, 129, 0.12);
  --loss: #f43f5e;
  --loss-bg: rgba(244, 63, 94, 0.12);
  --danger-text: #fda4af;
  --warning: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
}

:root[data-theme="light"] {
  --bg-base: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-surface: #e2e8f0;
  --bg-input: #f8fafc;
  --bg-input-focus: #ffffff;
  --bg-hover: rgba(15, 23, 42, 0.035);
  --bg-topbar: rgba(248, 250, 252, 0.92);
  --bg-status: rgba(255, 255, 255, 0.85);
  --bg-th: #f1f5f9;
  --bg-tfoot: #f1f5f9;
  --bg-tooltip: rgba(255, 255, 255, 0.98);
  --bg-backdrop: rgba(15, 23, 42, 0.45);
  --bg-code: rgba(2, 132, 199, 0.1);
  --text-code: #0369a1;

  --border-subtle: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.22);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --placeholder: #94a3b8;

  --accent: #0284c7;
  --accent-indigo: #4f46e5;
  --profit: #059669;
  --profit-bg: rgba(5, 150, 105, 0.12);
  --loss: #e11d48;
  --loss-bg: rgba(225, 29, 72, 0.1);
  --danger-text: #be123c;
  --warning: #d97706;

  --shadow-card: 0 8px 24px -10px rgba(15, 23, 42, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 15% -10%, rgba(56, 189, 248, 0.09), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(129, 140, 248, 0.08), transparent 55%),
    var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

[hidden] {
  display: none !important;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 24px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin: -24px -24px 0;
  padding: 18px 24px 14px;
  background: var(--bg-topbar);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

@media (max-width: 640px) {
  .topbar {
    margin: -14px -12px 0;
    padding: 12px 12px 10px;
  }
}

.topbar-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.help-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  flex-shrink: 0;
}

.help-icon-btn:hover {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.08);
}

/* PocketBase Auth Modal */
.oauth-btn-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.oauth-btn {
  width: 100%;
  justify-content: center;
  padding: 10px 14px;
  font-weight: 600;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 2px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
}

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

.auth-user-card {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

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

.page-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.nav-tab {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.is-active {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
  font-weight: 600;
}

.control-group {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.control-select {
  background: transparent;
  color: var(--text-primary);
  border: none;
  padding: 7px 10px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

.control-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 13px;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-icon {
  padding: 6px 10px;
  font-size: 1rem;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

:root:not([data-theme="light"]) .btn-primary {
  color: #06131f;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger-text);
  border-color: rgba(244, 63, 94, 0.25);
}

.btn-danger-ghost:hover {
  background: var(--loss-bg);
  border-color: rgba(244, 63, 94, 0.45);
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: #7dd3fc;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-status);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.status-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.save-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--profit);
  background: var(--profit-bg);
  padding: 3px 10px;
  border-radius: 999px;
}

.save-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.hint-text {
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.hint-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

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

.kpi-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.kpi-label {
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
}

.kpi-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.12);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.kpi-tag.info {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  cursor: help;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.pos {
  color: var(--profit);
}

.neg {
  color: var(--loss);
}

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

/* Panels */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-sub {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

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

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.swatch-value {
  background: var(--accent);
}

.swatch-invested {
  background: var(--accent-indigo);
}

.swatch-profit {
  background: var(--profit);
}

.swatch-loss {
  background: var(--loss);
}

.swatch-div {
  background: #f59e0b;
}

.chart-wrap {
  position: relative;
  height: 245px;
  width: 100%;
}

.chart-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
}

.chart-empty[hidden] {
  display: none;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-tooltip);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 0.78rem;
  color: var(--text-primary);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
  white-space: nowrap;
}

/* Initial Capital Box */
.table-header {
  flex-direction: column;
  align-items: flex-start;
}

.initial-capital-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-md);
}

.initial-capital-box label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-with-prefix {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  transition: border-color 0.15s ease;
}

.input-with-prefix:focus-within {
  border-color: var(--accent);
}

.currency-prefix {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
}

.input-with-prefix input {
  width: 118px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 6px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.86rem;
  outline: none;
  text-align: right;
}

/* Ledger Table */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  scrollbar-color: rgba(148, 163, 184, 0.35) rgba(13, 19, 32, 0.9);
  scrollbar-width: thin;
}

.table-scroll::-webkit-scrollbar {
  height: 9px;
}

.table-scroll::-webkit-scrollbar-track {
  background: rgba(13, 19, 32, 0.95);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.table-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.32);
  border-radius: 999px;
  border: 2px solid rgba(13, 19, 32, 0.95);
}

.table-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.ledger-table.ledger-wide {
  min-width: 1440px;
}

.ledger-table.ledger-wide th:first-child,
.ledger-table.ledger-wide td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #101726;
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.28);
}

.ledger-table.ledger-wide thead th:first-child {
  z-index: 3;
  background: #0d1320;
}

.ledger-table.ledger-wide tfoot td:first-child {
  background: #0d1320;
}

.ledger-table th {
  text-align: left;
  padding: 9px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  background: var(--bg-th);
  border-bottom: 1px solid var(--border-subtle);
  white-space: normal;
  line-height: 1.25;
}

.ledger-table th.num,
.ledger-table td.num {
  text-align: right;
}

.th-hint {
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.18);
  color: var(--text-secondary);
  font-size: 0.68rem;
  margin-left: 3px;
  cursor: help;
}

.ledger-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.12s ease;
}

.ledger-table tbody tr:hover {
  background: var(--bg-hover);
}

.ledger-table tbody tr.is-filled {
  background: rgba(56, 189, 248, 0.025);
}

.ledger-table tbody tr.is-filled:hover {
  background: rgba(56, 189, 248, 0.055);
}

.ledger-table td {
  padding: 6px 6px;
  vertical-align: middle;
}

.month-cell {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  white-space: nowrap;
}

.month-badge {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.month-badge.pos {
  background: var(--profit);
}

.month-badge.neg {
  background: var(--loss);
}

.cell-input {
  width: 100%;
  min-width: 72px;
  max-width: 112px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  color: var(--text-primary);
  padding: 6px 6px;
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
  text-align: right;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cell-input:focus {
  border-color: var(--accent);
  background: var(--bg-input-focus);
}

.cell-input::placeholder {
  color: var(--placeholder);
}

.cell-input-pct-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 0 6px 0 2px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cell-input-pct-wrap:focus-within {
  border-color: var(--accent);
  background: var(--bg-input-focus);
}

.cell-input-pct-wrap input {
  width: 52px;
  min-width: 44px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 6px 3px;
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
  text-align: right;
  outline: none;
}

.cell-input-pct-wrap input::placeholder {
  color: var(--placeholder);
}

.pct-suffix {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
}

.cell-notes {
  font-family: 'Inter', sans-serif;
  text-align: left;
  min-width: 96px;
  max-width: none;
}

.year-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.year-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auto-note {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 500;
}

.swatch-bench {
  background: var(--accent-indigo);
}

.bw-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.25;
}

.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.pill-pos {
  color: var(--profit);
  background: var(--profit-bg);
}

.pill-neg {
  color: var(--loss);
  background: var(--loss-bg);
}

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

.row-clear-btn {
  opacity: 0.45;
  padding: 4px 8px;
  font-size: 0.8rem;
}

.row-clear-btn:hover {
  opacity: 1;
  color: var(--loss);
}

.totals-row td {
  background: var(--bg-tfoot);
  border-top: 2px solid var(--border-strong);
  padding: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.foot-note {
  color: var(--text-secondary);
  font-weight: 400 !important;
  font-size: 0.78rem;
  white-space: normal !important;
  line-height: 1.25;
}

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

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.stat-name {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.stat-val {
  font-weight: 600;
  font-size: 0.9rem;
}

/* Goal Controls */
.goal-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.field-group input,
.field-group select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 11px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  outline: none;
}

.field-group select {
  font-family: inherit;
  cursor: pointer;
}

.field-group select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.field-group input:focus,
.field-group select:focus {
  border-color: var(--accent);
}

.btn-accent-soft {
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.35);
}

.btn-accent-soft:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.24);
  border-color: rgba(56, 189, 248, 0.55);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ledger-actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.fetch-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.fetch-status.ok {
  color: var(--profit);
}

.fetch-status.err {
  color: var(--loss);
}

.progress-block {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.83rem;
  margin-bottom: 9px;
}

.progress-track {
  height: 10px;
  background: rgba(148, 163, 184, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-indigo), var(--profit));
  transition: width 0.3s ease;
}

.progress-fill.behind {
  background: linear-gradient(90deg, var(--loss), var(--warning));
}

.goal-insight {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.alpha-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.alpha-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.alpha-value {
  font-weight: 700;
  font-size: 0.95rem;
}

/* Modals */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 560px;
  width: calc(100% - 28px);
  color: var(--text-primary);
}

.modal::backdrop {
  background: var(--bg-backdrop);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.65);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.formula-item {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.formula-item h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--accent);
}

.formula-item p {
  margin: 4px 0;
  font-size: 0.83rem;
}

.formula-item code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
}

.muted {
  color: var(--text-secondary);
  margin: 0;
  font-size: 0.84rem;
}

.backup-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-btn {
  cursor: pointer;
}

.feedback-msg {
  margin: 0;
  font-size: 0.84rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--profit-bg);
  color: var(--profit);
}

.feedback-msg.error {
  background: var(--loss-bg);
  color: var(--loss);
}

.modal.modal-wide {
  max-width: 720px;
}

.degiro-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.degiro-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.degiro-box h4 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.degiro-box code {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
  font-size: 0.82rem;
}

.degiro-file-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.degiro-file-status.ok {
  color: var(--profit);
}

.degiro-file-status.err {
  color: var(--loss);
}

.degiro-target-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 8px;
  margin-top: 2px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-row input[type='checkbox'] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.degiro-preview {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.82rem;
  max-height: 210px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.degiro-preview-title {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.degiro-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.degiro-preview-row:last-child {
  border-bottom: none;
}

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

@media (max-width: 640px) {
  .degiro-grid {
    grid-template-columns: 1fr;
  }
}

.btn-icon-danger:hover:not(:disabled) {
  color: var(--loss);
  background: var(--loss-bg);
}

.chart-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.segmented-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.is-active {
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
}

.alpha-sub {
  font-size: 0.7rem;
  line-height: 1.2;
  margin-top: 2px;
  opacity: 0.92;
  white-space: nowrap;
}

/* Settings Page */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-fields code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
}

.danger-panel {
  border-color: rgba(244, 63, 94, 0.25);
}

.danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 0;
  border-top: 1px solid var(--border-subtle);
}

.danger-info {
  max-width: 620px;
}

.danger-info h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.danger-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 1080px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* User Manual Modal & Markdown */
.modal.modal-manual {
  max-width: 860px;
}

.modal-manual-card {
  display: flex;
  flex-direction: column;
  max-height: 86vh;
}

.manual-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.manual-body {
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-color: rgba(148, 163, 184, 0.35) rgba(13, 19, 32, 0.9);
  scrollbar-width: thin;
}

.md-body h1 {
  font-size: 1.3rem;
  margin: 0 0 10px;
  color: var(--text-primary);
}

.md-body h2 {
  font-size: 1.05rem;
  margin: 20px 0 8px;
  color: var(--accent);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 5px;
}

.md-body h3 {
  font-size: 0.92rem;
  margin: 14px 0 6px;
  color: var(--text-primary);
}

.md-body p {
  margin: 6px 0 10px;
  color: var(--text-secondary);
  font-size: 0.87rem;
}

.md-body strong {
  color: var(--text-primary);
}

.md-body ul,
.md-body ol {
  margin: 6px 0 12px;
  padding-left: 20px;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.md-body li {
  margin-bottom: 5px;
}

.md-body code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.81rem;
}

.md-body pre {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0 12px;
}

.md-body pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
}

.md-body blockquote {
  margin: 10px 0;
  padding: 9px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(56, 189, 248, 0.07);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.md-body hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 16px 0;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 8px 0 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.md-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.md-body th {
  text-align: left;
  background: var(--bg-th);
  color: var(--text-primary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.md-body td {
  padding: 7px 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.md-body tr:last-child td {
  border-bottom: none;
}

/* Remove number spinners for cleaner finance inputs */
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type='number'] {
  -moz-appearance: textfield;
}

/* Responsive */
html,
body {
  overflow-x: clip;
}

@media (max-width: 1080px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .charts-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .ledger-table th:first-child,
  .ledger-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-elevated);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.16);
  }

  .ledger-table thead th:first-child {
    z-index: 3;
    background: var(--bg-th);
  }

  .ledger-table tfoot td:first-child {
    background: var(--bg-tfoot);
  }
}

@media (max-width: 768px) {
  .topbar {
    gap: 8px;
  }

  .topbar-head {
    gap: 10px;
  }

  .brand {
    gap: 10px;
    min-width: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    font-size: 0.76rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .help-icon-btn {
    padding: 6px 10px;
    font-size: 0.78rem;
    gap: 5px;
  }

  .toolbar {
    width: 100%;
    gap: 6px;
  }

  .page-nav {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .page-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .control-select {
    padding: 7px 8px;
    font-size: 0.82rem;
  }

  .btn,
  .nav-tab,
  .seg-btn {
    min-height: 36px;
  }

  /* Prevent mobile browser zoom on input focus (>= 16px) and enlarge tap targets */
  .cell-input,
  .cell-input-pct-wrap input,
  .initial-capital-box input,
  .goal-controls input,
  .settings-fields input,
  .settings-fields select,
  .degiro-target-row input,
  .degiro-target-row select {
    font-size: 16px;
    min-height: 38px;
  }

  .cell-input {
    width: 104px;
  }

  .cell-input.cell-notes {
    width: 150px;
  }

  .cell-input-pct-wrap input {
    width: 70px;
  }

  .row-clear-btn {
    min-width: 34px;
    min-height: 34px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px 12px 40px;
    gap: 14px;
  }

  .topbar {
    margin: -14px -12px 0;
    padding: 10px 12px 8px;
  }

  .status-bar {
    padding: 10px 12px;
    gap: 8px;
  }

  .panel {
    padding: 15px 13px;
  }

  .panel-header {
    gap: 10px;
    margin-bottom: 12px;
  }

  .chart-header-right {
    align-items: flex-start;
    width: 100%;
  }

  .legend {
    flex-wrap: wrap;
    gap: 10px;
  }

  .chart-wrap {
    height: 205px;
  }

  .chart-tooltip {
    white-space: normal;
    max-width: 210px;
  }

  .ledger-actions-row {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .initial-capital-box {
    width: 100%;
    justify-content: space-between;
  }

  .input-with-prefix {
    flex: 1 1 130px;
    justify-content: space-between;
  }

  .input-with-prefix input {
    width: 100%;
    min-width: 0;
  }

  #fetchBenchmarksBtn,
  .toolbar-actions,
  .toolbar-actions .btn {
    width: 100%;
  }

  .kpi-grid,
  .goal-controls {
    grid-template-columns: 1fr;
  }

  .kpi-card {
    padding: 14px 16px;
  }

  .kpi-value {
    font-size: 1.45rem;
  }

  .backup-actions,
  .danger-controls {
    width: 100%;
  }

  .backup-actions .btn,
  .backup-actions .file-btn,
  .danger-controls .btn {
    flex: 1 1 140px;
  }

  .modal {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: 92vh;
  }

  .modal-card {
    padding: 16px 14px;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

@media (max-width: 440px) {
  .subtitle {
    display: none;
  }

  .help-icon-btn span {
    display: none;
  }

  .help-icon-btn {
    padding: 7px 9px;
  }
}
