:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #7b8497;
  --line: #e8ecf3;
  --primary: #5a57e8;
  --primary-dark: #4642d1;
  --green: #159b72;
  --red: #df5c68;
  --radius: 18px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #aaa8ff;
  outline-offset: 2px;
}
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 245px;
  background: #111a2b; color: #fff; padding: 30px 18px;
  display: flex; flex-direction: column; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; font-weight: 800; font-size: 19px; }
.brand-icon {
  width: 43px; height: 43px; display: grid; place-items: center;
  background: linear-gradient(135deg,#7e7aff,#5049dc);
  border-radius: 14px; color: white; font-size: 23px; font-weight: 900;
}
.brand small { display: block; font-size: 9px; letter-spacing: 1.4px; opacity: .6; margin-top: 1px; }
.nav-label { margin: 43px 12px 13px; font-size: 10px; letter-spacing: 1.5px; color: #8590a5; font-weight: 800; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 13px; text-align: left;
  padding: 12px 14px; color: #b7c0d0; background: transparent; border: 0;
  border-radius: 11px; font-weight: 600;
}
.nav-item > span { width: 20px; font-size: 19px; text-align: center; }
.nav-item.active { color: white; background: #514de0; }
.nav-item:hover:not(.active) { background: #1d293d; color: white; }
.sidebar-bottom { margin-top: auto; }
.privacy-note { padding: 17px; background: #1b2940; border: 1px solid #29364b; border-radius: 14px; }
.privacy-note > span { color: #9d9aff; font-size: 23px; }
.privacy-note strong { display: block; margin-top: 7px; font-size: 13px; }
.privacy-note p { color: #a3aec1; font-size: 12px; margin: 5px 0 0; }
.logout-button { margin-top: 15px; }
.main-content { margin-left: 245px; padding: 30px 36px 20px; max-width: 1700px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 35px; }
.eyebrow { color: var(--primary); font-size: 10px; letter-spacing: 1.7px; font-weight: 800; margin: 0 0 3px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -.8px; }
h2 { font-size: 20px; margin: 0; letter-spacing: -.4px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; margin: 5px 0 0; }
.topbar-right { display: flex; align-items: center; gap: 9px; color: #596276; font-size: 13px; font-weight: 650; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #20b486; }
.menu-toggle { display: none; border: 0; background: white; padding: 9px 12px; border-radius: 10px; }
.welcome-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 22px; }
.btn { border: 0; border-radius: 11px; padding: 11px 16px; font-weight: 700; font-size: 13px; transition: .15s ease; }
.btn-primary { color: white; background: var(--primary); box-shadow: 0 5px 12px #5a57e82b; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-full { width: 100%; }
.summary-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 17px; margin-bottom: 23px; }
.summary-card { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.balance-card { background: linear-gradient(135deg,#5a57e8,#7772f5); color: white; border-color: transparent; }
.summary-top { display: flex; justify-content: space-between; align-items: center; color: #7b8497; font-size: 12px; font-weight: 650; }
.balance-card .summary-top, .balance-card .summary-foot { color: #e0dfff; }
.summary-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 11px; background: #f0efff; color: var(--primary); font-size: 20px; }
.balance-card .summary-icon { background: #ffffff25; color: white; }
.income-icon { color: var(--green); background: #e4f8ef; }
.expense-icon { color: var(--red); background: #fff0f0; }
.summary-amount { font-size: clamp(19px,2.2vw,28px); letter-spacing: -.7px; font-weight: 800; margin: 19px 0 6px; overflow-wrap: anywhere; }
.summary-foot { color: var(--muted); font-size: 11px; margin: 0; }
.content-grid { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(280px,.8fr); gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 23px; min-width: 0; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 21px; }
.text-button { border: 0; background: transparent; color: var(--primary); font-size: 12px; font-weight: 750; white-space: nowrap; }
.transaction-list { min-width: 0; }
.transaction-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid #f0f2f7; }
.transaction-row:last-child { border-bottom: 0; }
.transaction-icon { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #f0efff; color: var(--primary); font-size: 18px; }
.transaction-icon.income { color: var(--green); background: #e4f8ef; }
.transaction-icon.expense { color: var(--red); background: #fff0f0; }
.transaction-details { min-width: 0; flex: 1; }
.transaction-title { font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }
.transaction-subtitle { color: var(--muted); font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }
.transaction-right { text-align: right; flex-shrink: 0; }
.transaction-amount { font-weight: 800; font-size: 13px; white-space: nowrap; }
.transaction-amount.income { color: var(--green); }
.transaction-amount.expense { color: var(--red); }
.delete-transaction { border: 0; background: transparent; color: #a0a6b4; font-size: 12px; padding: 5px; }
.delete-transaction:hover { color: var(--red); }
.empty-state { text-align: center; padding: 38px 12px; color: var(--muted); }
.empty-state > span { display: grid; place-items: center; margin: 0 auto 12px; width: 46px; height: 46px; border-radius: 15px; background: #f0efff; color: var(--primary); font-size: 24px; }
.empty-state strong { color: var(--text); font-size: 13px; }
.empty-state p { font-size: 12px; margin: 5px 0 0; }
.transaction-form { display: grid; gap: 16px; }
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #f3f5fa; padding: 5px; border-radius: 12px; }
.type-option { cursor: pointer; position: relative; }
.type-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option span { display: block; text-align: center; padding: 10px 7px; border-radius: 9px; font-size: 12px; font-weight: 750; color: #70798c; }
.type-option input:checked + span { background: white; color: var(--primary); box-shadow: 0 2px 8px #202a4010; }
.field { display: grid; gap: 7px; }
.field label { font-size: 12px; font-weight: 750; color: #444e63; }
.optional { color: #9ba2b0; font-weight: 400; }
.field input, .field select, .filter-row input, .filter-row select {
  width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid #e3e7ef;
  border-radius: 10px; background: #fff; color: var(--text); font-size: 13px;
}
.field input::placeholder, .filter-row input::placeholder { color: #a6adbb; }
.filter-row { display: flex; gap: 12px; margin-bottom: 14px; }
.filter-row input { flex: 1; }
.filter-row select { max-width: 190px; }
.footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 38px; padding: 18px 0 8px; color: #929bad; font-size: 11px; }
.footer span:first-child { color: #5a57e8; font-weight: 800; }
.notice { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 40; width: max-content; max-width: min(92vw, 420px); padding: 12px 15px; border-radius: 11px; font-size: 13px; background: #e6f8ef; color: #137b58; box-shadow: 0 10px 30px #0002; }
.notice.error { background: #fff0f0; color: #b93d4b; }
.auth-view { min-height: 65vh; display: grid; place-items: center; }
.auth-card { width: min(100%,430px); padding: 35px; border: 1px solid var(--line); border-radius: 22px; background: white; box-shadow: 0 20px 60px #1720330b; }
.auth-brand { color: var(--text); margin-bottom: 28px; }
.auth-card h2 { font-size: 25px; }
.auth-card > .muted { margin-bottom: 25px; }
.auth-card form { display: grid; gap: 18px; }
.auth-switch { text-align: center; color: var(--muted); font-size: 12px; margin: 22px 0; }
.auth-switch button { border: 0; background: transparent; color: var(--primary); font-weight: 800; font-size: 12px; }
.auth-footnote { text-align: center; color: #a0a6b4; font-size: 11px; margin: 0; }
.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; background: #11182780; }
.modal { width: min(100%,460px); max-height: 90vh; overflow-y: auto; background: white; border-radius: 20px; padding: 25px; box-shadow: 0 25px 80px #0003; }
.modal-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 22px; }
.close-modal { border: 0; background: #f1f3f8; border-radius: 9px; width: 34px; height: 34px; font-size: 22px; color: #687185; }
@media (max-width: 1150px) {
  .main-content { padding: 25px 24px; }
  .sidebar { width: 220px; }
  .main-content { margin-left: 220px; }
  .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 260px; box-shadow: 10px 0 40px #0001; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 20px 15px; }
  .topbar { justify-content: flex-start; gap: 12px; margin-bottom: 28px; }
  .menu-toggle { display: block; flex-shrink: 0; }
  .topbar h1 { font-size: 23px; }
  .topbar-right { margin-left: auto; font-size: 11px; }
  .summary-grid { grid-template-columns: 1fr; gap: 11px; }
  .summary-card { padding: 18px; }
  .summary-amount { margin-top: 12px; }
  .welcome-row { align-items: flex-start; flex-direction: column; }
  .welcome-row > .btn { width: 100%; }
  .panel { padding: 17px; }
  .filter-row { flex-direction: column; }
  .filter-row select { max-width: none; }
  .footer { flex-direction: column; gap: 4px; }
  .auth-card { padding: 25px 20px; }
}

/* ---- Accounts, budgets, import, settings ---- */
.welcome-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.welcome-actions input[type="month"], .export-row input[type="month"] {
  padding: 9px 12px; border: 1px solid #e3e7ef; border-radius: 10px;
  background: #fff; color: var(--text); font-size: 13px;
}
.btn-secondary { color: var(--primary); background: #efeeff; }
.btn-secondary:hover { background: #e3e1ff; }
.btn-danger { color: white; background: var(--red); }
.btn-danger:hover { background: #c94955; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.category-panel { margin-top: 20px; }
.cat-row { margin-bottom: 18px; }
.cat-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; font-weight: 700; margin-bottom: 7px; }
.bar { height: 8px; background: #eef0f6; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.bar-fill.over { background: var(--red); }
.budget-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 11px; }
.negative { color: var(--red); }
.row-action { border: 0; background: transparent; color: #a0a6b4; font-size: 12px; padding: 5px; }
.row-action:hover { color: var(--primary); }
.export-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.export-row .muted { margin: 0; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.account-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.account-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.tag { font-size: 10px; font-weight: 800; color: var(--primary); background: #f0efff; padding: 3px 8px; border-radius: 99px; }
.account-balance { font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin: 14px 0 8px; overflow-wrap: anywhere; }
.account-foot { display: flex; justify-content: space-between; align-items: center; font-size: 11px; }
.account-foot .muted { margin: 0; font-size: 11px; }
.field textarea {
  width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid #e3e7ef;
  border-radius: 10px; background: #fff; color: var(--text); font-size: 13px;
  font-family: inherit; resize: vertical;
}
.section-stack { display: grid; gap: 20px; max-width: 640px; }
.import-actions { display: flex; gap: 10px; }
.import-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f0f2f7; font-size: 12px; align-items: center; }
.import-row span:nth-child(2) { overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .welcome-actions { width: 100%; }
  .welcome-actions .btn { flex: 1; }
  .import-row { grid-template-columns: 1fr auto; }
  .import-row span:first-child { grid-column: 1 / -1; color: var(--muted); }
}

/* ---- Account presets ---- */
.preset-row { margin-bottom: 16px; }
.preset-row .muted { margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-chip { border: 1px solid #e3e1ff; background: #f6f5ff; color: var(--primary); border-radius: 99px; padding: 7px 12px; font-size: 12px; font-weight: 700; }
.preset-chip:hover { background: #ebe9ff; }

/* ---- Extras: lists, charts ---- */
.sidebar { overflow-y: auto; }
.extra-label { margin-top: 22px; }
.theme-toggle { border: 0; background: transparent; color: inherit; font-size: 18px; padding: 4px 8px; border-radius: 8px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid #f0f2f7; }
.list-row:last-child { border-bottom: 0; }
.list-main { min-width: 0; display: grid; gap: 2px; }
.list-main strong { font-size: 13px; overflow-wrap: anywhere; }
.list-main .muted { margin: 0; font-size: 11px; overflow-wrap: anywhere; }
.list-right { flex-shrink: 0; text-align: right; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.bar-fill.done { background: var(--green); }
.debt-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.debt-summary > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 6px; }
.debt-summary strong { font-size: 22px; letter-spacing: -.5px; overflow-wrap: anywhere; }
.charts-grid { margin-top: 20px; }
.trend-svg, .donut { width: 100%; height: auto; display: block; }
.donut { max-width: 190px; margin: 0 auto 14px; transform: rotate(0deg); }
.bar-income { fill: var(--green); }
.bar-expense { fill: var(--red); }
.axis-line { stroke: var(--line); stroke-width: 1; }
.axis-label { font-size: 10px; fill: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }
.swatch.inc { background: var(--green); }
.swatch.exp { background: var(--red); }
.legend-list { display: grid; gap: 8px; }
.legend-row { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }

/* ---- Dark mode ---- */
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #141c2e; --text: #e8ecf5; --muted: #8f9ab0; --line: #222d44;
  color-scheme: dark;
}
[data-theme="dark"] .menu-toggle,
[data-theme="dark"] .auth-card,
[data-theme="dark"] .modal { background: var(--surface); color: var(--text); }
[data-theme="dark"] .field input,
[data-theme="dark"] .field select,
[data-theme="dark"] .field textarea,
[data-theme="dark"] .filter-row input,
[data-theme="dark"] .filter-row select,
[data-theme="dark"] .welcome-actions input[type="month"],
[data-theme="dark"] .export-row input[type="month"] { background: #0f1626; border-color: #2a3650; color: var(--text); }
[data-theme="dark"] .field label { color: #b9c3d8; }
[data-theme="dark"] .topbar-right { color: #b9c3d8; }
[data-theme="dark"] .type-toggle { background: #0f1626; }
[data-theme="dark"] .type-option span { color: #8f9ab0; }
[data-theme="dark"] .type-option input:checked + span { background: #1e2a44; color: #a9a6ff; box-shadow: none; }
[data-theme="dark"] .summary-icon,
[data-theme="dark"] .transaction-icon,
[data-theme="dark"] .empty-state > span,
[data-theme="dark"] .close-modal,
[data-theme="dark"] .tag { background: #1e2a44; color: #a9a6ff; }
[data-theme="dark"] .balance-card .summary-icon { background: #ffffff25; color: white; }
[data-theme="dark"] .income-icon,
[data-theme="dark"] .transaction-icon.income { background: #12372d; color: #38d6a0; }
[data-theme="dark"] .expense-icon,
[data-theme="dark"] .transaction-icon.expense { background: #3a1d26; color: #ff8a97; }
[data-theme="dark"] .transaction-row,
[data-theme="dark"] .list-row,
[data-theme="dark"] .import-row { border-bottom-color: var(--line); }
[data-theme="dark"] .bar { background: #1e2a44; }
[data-theme="dark"] .preset-chip,
[data-theme="dark"] .btn-secondary { background: #1e2a44; border-color: #2a3650; color: #a9a6ff; }
[data-theme="dark"] .notice { background: #12372d; color: #6fe0b8; }
[data-theme="dark"] .notice.error { background: #3a1d26; color: #ff9aa6; }
[data-theme="dark"] .footer { color: #6f7a91; }
[data-theme="dark"] .transaction-title,
[data-theme="dark"] .empty-state strong { color: var(--text); }

/* ---- Security: lock screen, 2FA, forgot password ---- */
.lock-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.lock-card { width: min(100%, 340px); text-align: center; display: grid; gap: 14px; }
.lock-card .brand-icon { margin: 0 auto; }
.lock-card form { display: grid; gap: 12px; }
.lock-card input { width: 100%; text-align: center; font-size: 22px; letter-spacing: 8px; padding: 12px; border: 1px solid #e3e7ef; border-radius: 12px; background: #fff; color: var(--text); }
.lock-error { color: var(--red); font-size: 12px; margin: 0; }
.auth-forgot { text-align: center; margin: 14px 0 0; }
.sec-block { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.sec-block:last-child { border-bottom: 0; }
.sec-head { display: flex; justify-content: space-between; align-items: center; }
.tag.on { background: #e4f8ef; color: var(--green); }
.codes, .keybox { background: #f3f5fa; border-radius: 10px; padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; margin: 0; }
.codes { line-height: 1.8; white-space: pre-wrap; }
.keybox { word-break: break-all; }
[data-theme="dark"] .lock-card input,
[data-theme="dark"] .codes,
[data-theme="dark"] .keybox { background: #0f1626; border-color: #2a3650; color: var(--text); }
[data-theme="dark"] .tag.on { background: #12372d; color: #38d6a0; }

/* ---- Offline banner, household ---- */
.offline-banner { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 90; background: #101827; color: #fff; padding: 9px 15px; border-radius: 99px; font-size: 12px; font-weight: 600; box-shadow: 0 8px 24px #0004; max-width: 92vw; text-align: center; }
.ws-chip { border: 0; background: #efeeff; color: var(--primary); font-weight: 700; font-size: 11px; padding: 5px 10px; border-radius: 99px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ws-viewer #add-first-btn,
body.ws-viewer #add-transaction-btn,
body.ws-viewer #quick-form,
body.ws-viewer [data-edit],
body.ws-viewer [data-delete] { display: none !important; }
[data-theme="dark"] .ws-chip { background: #1e2a44; color: #a9a6ff; }

/* ---- Setup guide, CSV panel ---- */
.csv-panel { margin-top: 20px; }
.wizard-overlay { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; padding: 16px; background: #0b1220b3; }
.wizard-card { width: min(100%, 460px); max-height: 92vh; overflow-y: auto; background: var(--surface); color: var(--text); border-radius: 20px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 25px 80px #0005; }
.wizard-steps { display: flex; gap: 6px; }
.wizard-steps i { flex: 1; height: 5px; border-radius: 99px; background: var(--line); }
.wizard-steps i.on { background: var(--primary); }
.wizard-card h2 { margin: 0 0 4px; }
.wizard-card .field { margin-bottom: 12px; }
.wizard-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.wizard-add { display: flex; gap: 8px; }
.wizard-grid { display: grid; gap: 10px; margin: 12px 0; }
.preset-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Auto-sync ---- */
.as-heading { margin: 4px 0 12px; }
.as-source { margin-bottom: 16px; display: grid; gap: 10px; }
.as-source h3 { margin: 0; }
.as-guide { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.as-guide summary { cursor: pointer; font-weight: 700; font-size: 13px; }
.as-guide ol { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: 13px; }
.as-inbox-item { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.as-inbox-item:last-child { border-bottom: 0; }
.as-inbox-item .codes { font-size: 12px; }

/* ---- Auto-sync: transfers ---- */
.as-pair { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.as-pair:last-child { border-bottom: 0; }
