:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  margin-bottom: 16px;
}

.site-header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.site-header p {
  margin: 0;
  color: var(--muted);
}

.app-version {
  font-size: 0.75rem;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 8px 0;
}

.tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.section { display: none; }
.section.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.help {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 720px) {
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.stack-label textarea,
input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
}

button, .small {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--primary);
  color: white;
  cursor: pointer;
}

button.secondary, .small.secondary {
  background: #e2e8f0;
  color: var(--text);
}

button.danger, .small.danger {
  background: var(--danger);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.balance-actions, .modal-actions, .named-version-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.safe-payment-hero .help {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: normal;
}

.safe-payment-hero {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius);
  background: #eff6ff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.safe-payment-hero .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.safe-payment-hero .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.info-banner, .warning-banner, .offline-banner, .startup-error-banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.info-banner {
  background: #eff6ff;
  color: #1e40af;
}

.warning-banner {
  background: #fef3c7;
  color: #92400e;
}

.offline-banner {
  background: #fef9c3;
  text-align: center;
}

.startup-error-banner {
  background: #fee2e2;
  display: flex;
  gap: 12px;
  align-items: center;
}

.startup-error-banner[hidden] {
  display: none !important;
}

.timeline-month { margin-bottom: 20px; }

.timeline-month-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.timeline-month-header h3 {
  margin: 0;
  font-size: 1rem;
}

.timeline-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fafbfd;
}

.timeline-row.simulated {
  border-style: dashed;
  background: #f8fafc;
}

.timeline-row-main {
  display: grid;
  grid-template-columns: 88px 1fr auto 72px;
  gap: 8px;
  align-items: center;
}

@media (max-width: 720px) {
  .timeline-row-main {
    grid-template-columns: 1fr 1fr;
  }
}

.timeline-date { font-size: 0.85rem; color: var(--muted); }
.timeline-label { font-weight: 500; }
.timeline-amount.positive { color: var(--success); font-weight: 600; }
.timeline-amount.negative { color: var(--danger); font-weight: 600; }
.timeline-amount.muted { color: var(--muted); font-style: italic; }
.timeline-account { font-size: 0.85rem; color: var(--muted); text-align: right; }

.timeline-balances {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f0fdf4 0%, #eff6ff 50%, #fef2f2 100%);
  border: 1px solid #cbd5e1;
  font-size: 0.88rem;
}

.timeline-balances-label {
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.timeline-balance-item {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid transparent;
}

.timeline-balance-item.balance-bank {
  color: #15803d;
  border-color: #bbf7d0;
}

.timeline-balance-item.balance-mc {
  color: #dc2626;
  border-color: #fecaca;
}

.timeline-balance-item.balance-visa {
  color: #2563eb;
  border-color: #bfdbfe;
}

.timeline-balance-item::before {
  content: none;
}

.timeline-payment-split {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.timeline-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.timeline-edit input, .timeline-edit select {
  min-width: 100px;
}

.timeline-simulated-note {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.account-balance {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 8px 0;
}

.account-warning {
  color: var(--danger);
  font-size: 0.9rem;
}

.account-status {
  padding: 10px 12px;
  border-radius: 8px;
  margin: 8px 0;
  font-size: 0.9rem;
}

.account-status.good { background: #ecfdf5; color: #166534; }
.account-status.warn { background: #fef3c7; color: #92400e; }
.account-status.bad { background: #fee2e2; color: #991b1b; }

.sparkline {
  width: 100%;
  height: 56px;
  display: block;
}

.account-chart {
  width: 100%;
  height: auto;
  min-height: 200px;
  display: block;
  margin-top: 12px;
}

.account-chart-wide {
  width: 100%;
  height: auto;
  min-height: 240px;
  display: block;
  margin: 12px 0 16px;
}

.accounts-feature-card {
  margin-bottom: 16px;
}

.card-inset {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.what-if-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.what-if-label input {
  font-weight: 400;
}

.what-if-result {
  margin-top: 8px;
  line-height: 1.45;
}

.range-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.range-bar-track {
  position: relative;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.range-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #93c5fd, #2563eb);
  border-radius: 999px;
}

.range-bar-fill-bank {
  background: linear-gradient(90deg, #86efac, #16a34a);
}

.range-bar-fill-mc {
  background: linear-gradient(90deg, #fca5a5, #dc2626);
}

.range-bar-fill-visa {
  background: linear-gradient(90deg, #93c5fd, #2563eb);
}

.range-bar-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.monthly-ranges-table td {
  vertical-align: middle;
}

.metric-label, .metric .label {
  font-size: 0.8rem;
  color: var(--muted);
}

.metric-value, .metric .value {
  font-size: 1.1rem;
  font-weight: 600;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.9rem;
}

.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

.data-table .amount { text-align: right; }

.card-monthly-ranges { margin-top: 16px; }

.monthly-ranges-table { margin-top: 8px; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: min(100%, 420px);
  box-shadow: var(--shadow);
}

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

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(120%);
  background: #0f172a;
  color: white;
  padding: 12px 18px;
  border-radius: 999px;
  transition: transform 0.2s ease;
  z-index: 200;
  max-width: calc(100% - 32px);
}

.toast-host.show { transform: translateX(-50%) translateY(0); }
.toast-host.error { background: var(--danger); }

.app-splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 300;
}

.app-splash.hidden { display: none; }

.app-splash-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
