:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent2: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-right {
  left: auto;
  right: 0;
  width: 260px;
  border-right: none;
  border-left: 1px solid var(--border);
}

.sidebar-right-header { padding: 0 0.5rem 1rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
.sidebar-right-header h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; margin-bottom: 0.35rem;
}
.sidebar-right-sub { font-size: 0.8rem; color: var(--text); }

.rs-panel {
  background: var(--surface2); border-radius: 8px; padding: 0.85rem;
  margin-bottom: 0.65rem;
}
.rs-panel h3 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin-bottom: 0.6rem; font-weight: 600;
}
.rs-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 0.5rem; font-size: 0.8rem; padding: 0.3rem 0;
  border-bottom: 1px solid rgba(45,58,79,0.5);
}
.rs-row:last-child { border-bottom: none; }
.rs-row .rs-val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rs-row.highlight .rs-val { font-size: 0.95rem; }
.rs-row.highlight.positive .rs-val { color: var(--accent2); }
.rs-row.highlight.negative .rs-val { color: var(--danger); }
.rs-actions { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.25rem; }
.rs-actions .btn { width: 100%; justify-content: center; }

.logo { font-weight: 700; font-size: 1.1rem; margin-bottom: 1.5rem; padding: 0 0.5rem; }
.logo span { color: var(--accent); display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); }

.nav-btn {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.75rem; border: none; background: none;
  color: var(--muted); border-radius: 8px; cursor: pointer;
  font-size: 0.875rem; text-align: left; width: 100%; transition: all 0.15s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: rgba(59,130,246,0.15); color: var(--accent); }

.nav-group-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 0.75rem 0.75rem 0.25rem; margin-top: 0.25rem;
}

.sidebar-primary { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.sidebar-settings {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-settings .nav-group-label { margin-top: 0; padding-top: 0; }
.sidebar-version {
  margin-top: 0.75rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

textarea.input { resize: vertical; min-height: 120px; font-family: inherit; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; margin-left: 240px; margin-right: 260px; }

.topbar {
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface);
}

.content { flex: 1; overflow-y: auto; padding: 1.5rem; }

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

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

.card h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 1rem; }

.hero-balance {
  text-align: center; padding: 2rem;
  background: linear-gradient(135deg, #1a2332 0%, #1e3a5f 100%);
  border-radius: var(--radius); margin-bottom: 1.5rem; border: 1px solid var(--border);
}
.hero-balance .label { color: var(--muted); font-size: 0.85rem; }
.hero-balance .amount { font-size: 2.5rem; font-weight: 700; margin: 0.25rem 0; }
.hero-balance .amount.positive { color: var(--accent2); }
.hero-balance .amount.negative { color: var(--danger); }

.budget-sheet .wf-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.875rem; }
.budget-sheet .wf-table th {
  text-align: left; padding: 0.5rem 0.75rem; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--border);
}
.budget-sheet .wf-table th.wf-amt,
.budget-sheet .wf-table th.wf-bal { text-align: right; width: 8.5rem; }
.budget-sheet .wf-table td {
  padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.budget-sheet .wf-table td.wf-amt,
.budget-sheet .wf-table td.wf-bal {
  text-align: right; font-variant-numeric: tabular-nums; width: 8.5rem;
  border-left: 1px solid var(--border);
}
.budget-sheet .wf-table td.wf-amt { font-weight: 600; }
.budget-sheet .wf-table td.wf-bal { color: var(--muted); font-size: 0.82rem; }
.budget-sheet .wf-table tr.wf-section td {
  background: transparent; border-bottom: none; padding-top: 1rem; padding-bottom: 0.25rem;
  color: var(--muted); font-size: 0.82rem;
}
.budget-sheet .wf-table tr.wf-section .wf-section-title {
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72rem; font-weight: 600; color: var(--muted);
}
.budget-sheet .wf-table tr.wf-section .wf-section-link { color: var(--accent); text-decoration: none; }
.budget-sheet .wf-table tr.wf-section .wf-section-link:hover { text-decoration: underline; }
.wf-add-row td {
  padding: 0.4rem 0.75rem 0.55rem;
  border-bottom: none;
  background: rgba(0,0,0,0.1);
  text-align: right;
}
.wf-add-wrap { position: relative; display: inline-block; }
.wf-add-btn {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.wf-add-btn:hover:not(:disabled) {
  background: rgba(59,130,246,0.15);
  border-color: var(--accent);
}
.wf-add-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.wf-add-picker {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  left: auto;
  min-width: 14rem;
  max-width: 18rem;
  max-height: 12rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  z-index: 30;
  padding: 0.25rem 0;
}
.wf-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}
.wf-picker-item:hover { background: var(--surface2); }
.wf-picker-amt { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wf-picker-empty {
  margin: 0;
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}
.budget-sheet .wf-table tr.wf-section td.wf-amt,
.budget-sheet .wf-table tr.wf-section td.wf-bal,
.budget-sheet .wf-table tr.wf-empty td.wf-amt,
.budget-sheet .wf-table tr.wf-empty td.wf-bal { border-left: 1px solid var(--border); }
.budget-sheet .wf-table tr:hover td { background: inherit; }
.budget-sheet .wf-table tr.wf-item:hover td { background: rgba(0,0,0,0.16); }
.budget-sheet .wf-table tr.wf-total:hover td { background: rgba(59,130,246,0.08); }
.budget-sheet .wf-table tr.wf-section:first-child td { padding-top: 0.25rem; }
.budget-sheet .wf-table tr.wf-item td { background: rgba(0,0,0,0.1); font-size: 0.82rem; }
.budget-sheet .wf-table tr.wf-item td.wf-desc { padding-left: 1.5rem; }
.budget-sheet .wf-table tr.wf-empty td { color: var(--muted); font-style: italic; font-size: 0.8rem; padding-left: 1.5rem; border-bottom: none; }
.budget-sheet .wf-table tr.wf-income td.wf-amt,
.budget-sheet .wf-table tr.wf-income td.wf-bal { color: var(--accent2); font-weight: 600; }
.budget-sheet .wf-table tr.wf-deduction td.wf-amt { color: var(--danger); }
.budget-sheet .wf-table tr.wf-total td { background: rgba(59,130,246,0.08); font-weight: 600; border-top: 2px solid var(--border); }
.budget-sheet .wf-table tr.wf-grand-total td { background: rgba(16,185,129,0.1); font-weight: 700; border-top: 2px solid var(--border); }
.budget-sheet .wf-table tr.wf-grand-total td.wf-bal { color: var(--text); font-size: 0.9rem; }
.budget-sheet .wf-meta { color: var(--muted); font-size: 0.75rem; margin-left: 0.35rem; }
.budget-sheet .wf-actions { display: inline-flex; gap: 0.25rem; margin-left: 0.5rem; }

.input.inline-num {
  width: 5.5rem; padding: 0.3rem 0.45rem; font-size: 0.8rem;
  display: inline-block;
}
.master-edit-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(59,130,246,0.2); }

.slide-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.5rem;
}
.slide-toggle-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  transition: color 0.2s;
}
.slide-toggle-label.active { color: var(--accent); }
.slide-toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.slide-toggle-track {
  position: relative;
  width: 2.6rem;
  height: 1.4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.slide-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1rem;
  height: 1rem;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.slide-toggle-input:checked + .slide-toggle-track {
  background: rgba(59,130,246,0.25);
  border-color: var(--accent);
}
.slide-toggle-input:checked + .slide-toggle-track .slide-toggle-thumb {
  transform: translateX(1.2rem);
  background: var(--accent);
}
.slide-toggle-input:focus-visible + .slide-toggle-track {
  box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
}

.slide-toggle-wide .slide-toggle-label {
  font-size: 0.7rem;
  max-width: 9rem;
  text-align: center;
  line-height: 1.2;
}

.funds-base-setting {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.02);
}

.funds-base-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 12rem;
}

.funds-base-label strong {
  font-size: 0.85rem;
}

.funds-base-label span {
  font-size: 0.75rem;
  color: var(--muted);
}

.funds-table .wf-actions-cell { width: 8.5rem; text-align: right; white-space: nowrap; }
.funds-table .wf-actions-cell .btn { margin-left: 0.25rem; }
.funds-row-label { font-weight: 500; margin-bottom: 0.35rem; }
.funds-row-toggle { margin-bottom: 0; }
.funds-amount-input { display: flex; align-items: center; justify-content: flex-end; gap: 0.35rem; }
.funds-amount-input .input { width: 6.5rem; text-align: right; }
.funds-amount-suffix { font-size: 0.75rem; color: var(--muted); min-width: 1.75rem; }
.funds-save-row td { border-bottom: none; padding-top: 0.35rem; padding-bottom: 1rem; }
.funds-section-header td { vertical-align: middle; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 1100px) {
  .sidebar-right { display: none; }
  .main { margin-right: 0; }
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar:not(.sidebar-right) { display: none; }
  .main { margin-left: 0; }
}

.btn {
  padding: 0.5rem 1rem; border-radius: 8px; border: none; cursor: pointer;
  font-size: 0.875rem; font-weight: 500; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); }

.input, .select {
  padding: 0.5rem 0.75rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.875rem; width: 100%;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); }
.label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.form-row { margin-bottom: 0.85rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.6rem 0.75rem; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface2); }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 500; }
.badge-draft { background: rgba(245,158,11,0.15); color: var(--warn); }
.badge-final { background: rgba(16,185,129,0.15); color: var(--accent2); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 440px;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1.25rem; justify-content: flex-end; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab { padding: 0.5rem 1rem; border-radius: 8px; border: none; background: none; color: var(--muted); cursor: pointer; font-size: 0.875rem; }
.tab.active { background: var(--surface2); color: var(--text); }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; padding: 0.75rem 1.25rem;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  font-size: 0.875rem; opacity: 0; transform: translateY(1rem); transition: all 0.3s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat { background: var(--surface2); border-radius: 8px; padding: 1rem; }
.stat .val { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .val.positive { color: var(--accent2); }
.stat .val.negative { color: var(--danger); }
.stat.stat-net { background: rgba(16,185,129,0.08); border: 1px solid rgba(16,185,129,0.2); }
.stat .lbl { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.budget-sheet .wf-income-link { color: var(--accent2); text-decoration: none; font-weight: 600; }
.budget-sheet .wf-income-link:hover { text-decoration: underline; }

.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.cal-header h3 { margin: 0; font-size: 1rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: 96px;
  gap: 4px;
}
.cal-dow { text-align: center; font-size: 0.7rem; color: var(--muted); padding: 0.35rem 0; text-transform: uppercase; }
.cal-day {
  height: 96px;
  min-height: 96px;
  max-height: 96px;
  overflow: hidden;
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.35rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.cal-day:hover { border-color: var(--accent); }
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(59,130,246,0.3); }
.cal-day.in-week { background: rgba(59,130,246,0.08); }
.cal-day-num { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 0.25rem; }
.cal-chip {
  display: block; font-size: 0.65rem; padding: 0.15rem 0.3rem; border-radius: 4px;
  background: rgba(239,68,68,0.15); color: var(--danger); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-chip.monthly { background: rgba(245,158,11,0.15); color: var(--warn); }
.cal-chip.in-week { border-color: var(--ok); color: var(--ok); background: rgba(34,197,94,0.15); }
.cal-chip.deferred-out { opacity: 0.45; text-decoration: line-through; border-color: rgba(239,68,68,0.35); }
.cal-chip.deferred-in { border-color: var(--warn); color: var(--warn); background: rgba(245,158,11,0.2); }
.cal-chip.more { background: transparent; color: var(--muted); }

.balance-complete {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.25rem; margin-bottom: 1.25rem;
  background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.35);
  border-radius: 10px;
}
.balance-complete-icon {
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--ok); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.balance-complete p { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--muted); }
.balance-status-tag {
  display: inline-block; margin-left: 0.5rem; font-size: 0.75rem;
  padding: 0.15rem 0.45rem; border-radius: 4px; font-weight: 600;
}
.balance-status-tag.ok { background: rgba(34,197,94,0.2); color: var(--ok); }
.balance-status-tag.warn { background: rgba(245,158,11,0.2); color: var(--warn); }
.balance-transfer-note {
  display: block; font-size: 0.7rem; color: var(--warn); margin-top: 0.15rem;
}
.balance-warn {
  font-size: 0.85rem; color: var(--warn); margin-bottom: 1rem;
  padding: 0.5rem 0.75rem; background: rgba(245,158,11,0.1); border-radius: 6px;
}
.input-sm { max-width: 120px; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
th.num, td.num { text-align: right; white-space: nowrap; }
.history-actions { white-space: nowrap; }
.history-actions .btn + .btn { margin-left: 0.35rem; }

.hidden { display: none !important; }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.auth-card h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.auth-sub { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.25rem; }
.auth-footer { margin-top: 1rem; font-size: 0.8rem; color: var(--muted); }
.auth-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.75rem; }

.account-summary {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.account-name { color: var(--text); font-weight: 600; }
.account-meta { line-height: 1.35; }
.workspace-switcher { padding: 0 0.75rem 0.5rem; }
.workspace-switcher .select { width: 100%; font-size: 0.8rem; }
.nav-btn-logout { color: var(--muted); margin-top: 0.25rem; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.dev-tools-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  font-size: 0.8rem;
}
.dev-tools-bar.hidden { display: none; }
.dev-tools-label {
  color: var(--warn);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dev-tools-bar .select {
  width: auto;
  min-width: 11rem;
  font-size: 0.8rem;
}
.dev-tools-hint { color: var(--muted); }