:root {
  --ink: #32495c;
  --muted: #6f8191;
  --line: #d8e6f0;
  --surface: #ffffff;
  --canvas: #f4f8fb;
  --green: #6f9fbe;
  --green-dark: #5685a5;
  --green-soft: #e4f0f7;
  --red: #b66d82;
  --amber: #a78256;
  --blue: #7199c1;
  --radius: 6px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  min-height: 84px; padding: 16px clamp(18px, 4vw, 48px); display: flex;
  align-items: center; justify-content: space-between; background: #8eb7d5; color: white;
}
.topbar h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: 0; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 700; color: #edf6fb; }
.icon-button { width: 42px; height: 42px; border: 1px solid #d7e8f2; color: white; background: transparent; border-radius: var(--radius); font-size: 24px; }
.icon-button:hover { background: #7aa8c7; }

.tabs { padding: 0 clamp(18px, 4vw, 48px); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; gap: 4px; overflow-x: auto; }
.tab { min-width: 76px; min-height: 48px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 650; }
.tab.active { color: var(--green); border-bottom-color: var(--green); }

main { max-width: 1360px; margin: 0 auto; padding: 28px clamp(18px, 4vw, 48px) 64px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { margin: 2px 0 0; font-size: 24px; letter-spacing: 0; }
.kicker { margin: 0; color: var(--green); font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.count { color: var(--muted); font-size: 13px; }

.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); }
.summary-strip div { padding: 20px; border-right: 1px solid var(--line); }
.summary-strip div:last-child { border-right: 0; }
.summary-strip span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.summary-strip strong { font-size: 25px; font-variant-numeric: tabular-nums; }

.dashboard-grid { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 18px; }
.panel { padding: 20px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); }
.account-panel { grid-column: 1 / -1; }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-title h3 { margin: 0; font-size: 16px; }
.account-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
.account-row { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #eaf1f6; }
.account-row span { min-width: 0; overflow-wrap: anywhere; }
.account-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 14px; }
.currency { margin-left: 5px; color: var(--muted); font-size: 11px; }
.bar-row { margin: 12px 0; }
.bar-label { margin-bottom: 6px; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.bar-track { height: 8px; background: #e4eef5; overflow: hidden; border-radius: 2px; }
.bar-fill { height: 100%; background: var(--bar-color, var(--green)); }
.category-list { display: grid; gap: 6px; }
.category-row { width: 100%; padding: 10px 0; border: 0; border-bottom: 1px solid #eaf1f6; background: transparent; text-align: left; }
.category-row:hover, .category-row.active { background: #f7f9f8; }
.category-row .bar-label { margin-bottom: 7px; }
.category-details { min-height: 106px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.detail-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.detail-heading h4 { margin: 0; font-size: 14px; }
.detail-heading span { color: var(--muted); font-size: 12px; }
.category-details .bar-track { height: 6px; }

.filter-bar { display: grid; grid-template-columns: minmax(180px, 1.4fr) repeat(3, minmax(130px, 1fr)) auto auto; gap: 10px; align-items: end; margin-bottom: 16px; }
label { display: grid; gap: 6px; min-width: 0; color: var(--muted); font-size: 12px; font-weight: 650; }
input, select { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #bfd2df; border-radius: 4px; background: white; color: var(--ink); }
input:focus, select:focus { outline: 2px solid #a8c8dc; outline-offset: 1px; border-color: var(--green); }
button.primary, button.secondary { min-height: 42px; padding: 0 18px; border-radius: 4px; font-weight: 700; }
button.primary { border: 1px solid var(--green); background: var(--green); color: white; }
button.primary:hover { background: var(--green-dark); }
button.secondary { border: 1px solid #b5cbd9; background: white; color: var(--ink); }
button.compact { padding: 0 14px; }
button:disabled { opacity: .55; cursor: not-allowed; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 14px; background: #edf4f8; color: var(--muted); text-align: left; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid #e5eef4; vertical-align: top; }
td.number, th.number { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-action { min-height: 30px; padding: 0 9px; border: 1px solid #b5cbd9; border-radius: 4px; background: white; color: var(--green); font-size: 12px; font-weight: 700; }
.protected-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.type-pill { display: inline-block; min-width: 46px; padding: 3px 6px; border-radius: 3px; background: #e7eeeb; text-align: center; white-space: nowrap; }
.type-expense { color: var(--red); background: #f5e8e6; }
.type-income { color: var(--green); background: var(--green-soft); }
.transaction-cards { display: none; }
.filter-total { margin-top: 14px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 2px solid var(--green); background: white; }
.filter-total div { display: flex; align-items: baseline; gap: 12px; }
.filter-total span, .filter-total p { color: var(--muted); font-size: 12px; }
.filter-total strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.filter-total p { margin: 0; text-align: right; }

.segmented { width: fit-content; display: grid; grid-template-columns: repeat(4, 86px); margin-bottom: 18px; border: 1px solid #b8cedc; border-radius: 5px; overflow: hidden; }
.segmented button { height: 40px; border: 0; border-right: 1px solid #b8cedc; background: white; color: var(--muted); }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--green); color: white; }
.entry-form { display: grid; grid-template-columns: repeat(2, minmax(0, 300px)); gap: 16px; padding: 22px; border: 1px solid var(--line); background: white; border-radius: var(--radius); }
.entry-form.narrow { max-width: 760px; }
.entry-form .wide { grid-column: 1 / -1; }
.field-group { display: contents; }
.hidden { display: none !important; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; padding-top: 4px; }
.preview-panel { max-width: 760px; margin-top: 16px; padding: 20px; border-left: 4px solid var(--amber); background: white; box-shadow: 0 1px 0 var(--line); }
.preview-panel h3 { margin: 0 0 14px; font-size: 16px; }
.preview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
.preview-grid div { min-width: 0; }
.preview-grid span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 12px; }
.preview-grid strong { overflow-wrap: anywhere; font-size: 14px; }
.preview-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: flex-end; }
.edit-dialog { width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 7px; background: var(--canvas); box-shadow: 0 18px 60px #0005; }
.edit-dialog::backdrop { background: #10201b99; }
.dialog-header { padding: 18px 20px; display: flex; align-items: start; justify-content: space-between; border-bottom: 1px solid var(--line); background: white; }
.dialog-header h2 { margin: 2px 0; font-size: 20px; }
.dialog-close { width: 38px; height: 38px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 26px; line-height: 1; }
.dialog-close:hover { background: #eaf1f6; }
.dialog-form { border: 0; border-radius: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dialog-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px; padding-top: 4px; }
button.danger { min-height: 42px; padding: 0 16px; border: 1px solid #b76a65; border-radius: 4px; background: white; color: var(--red); font-weight: 700; }
.edit-dialog .preview-panel { margin: 0 22px 22px; }
.warning { margin: 12px 0 0; color: var(--amber); font-size: 13px; }
.status-badge { padding: 5px 8px; border: 1px solid #9db9ae; border-radius: 4px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 700; }
.status-badge.offline { border-color: #d2b384; color: #7b510e; background: #fff3df; }
.data-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.data-panel { display: flex; min-height: 218px; flex-direction: column; align-items: flex-start; }
.data-panel h3, .integrity-panel h3 { margin: 0 0 10px; font-size: 16px; }
.data-panel p { flex: 1; margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.data-panel button { width: 100%; }
.file-input { height: auto; margin: 0 0 10px; padding: 9px; font-size: 12px; }
.integrity-panel { margin-top: 16px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
#integritySummary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--line); }
#integritySummary div { min-width: 0; padding: 13px; background: white; }
#integritySummary span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
#integritySummary strong { display: block; overflow-wrap: anywhere; font-size: 14px; font-variant-numeric: tabular-nums; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; border-radius: 5px; background: #32495c; color: white; box-shadow: 0 8px 28px #0003; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #7b2d29; }
.empty { padding: 32px 16px; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar .search-field { grid-column: 1 / -1; }
  .data-grid { grid-template-columns: 1fr; }
  .data-panel { min-height: 0; }
  #integritySummary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .topbar { min-height: 72px; padding: 12px 16px; }
  .topbar h1 { font-size: 20px; }
  .tabs { padding: 0 8px; justify-content: space-between; }
  .tab { min-width: 60px; font-size: 13px; }
  main { padding: 20px 14px 48px; }
  .section-heading { align-items: start; }
  .section-heading h2 { font-size: 21px; }
  .summary-strip { grid-template-columns: 1fr; }
  .summary-strip div { padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-strip div:last-child { border-bottom: 0; }
  .summary-strip strong { font-size: 21px; }
  .panel { padding: 16px; }
  .account-list { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar label { grid-column: 1 / -1; }
  .table-wrap { display: none; }
  .transaction-cards { display: grid; gap: 8px; }
  .transaction-card { padding: 13px; border: 1px solid var(--line); background: white; border-radius: 5px; }
  .transaction-card header, .transaction-card footer { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
  .transaction-card h3 { margin: 9px 0 4px; font-size: 15px; overflow-wrap: anywhere; }
  .transaction-card p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
  .transaction-card strong { white-space: nowrap; }
  .transaction-card .row-action { margin-left: auto; }
  .filter-total { align-items: start; flex-direction: column; gap: 6px; }
  .filter-total div { width: 100%; justify-content: space-between; }
  .filter-total p { text-align: left; }
  .segmented { width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .segmented button { min-width: 0; font-size: 13px; }
  .entry-form { grid-template-columns: 1fr; padding: 16px; }
  .entry-form .wide, .form-actions { grid-column: auto; }
  .form-actions button { width: 100%; }
  .preview-grid { grid-template-columns: 1fr; }
  .preview-actions { flex-direction: column-reverse; }
  .preview-actions button { width: 100%; }
  .edit-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .dialog-form { grid-template-columns: 1fr; }
  .dialog-actions { grid-column: auto; flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
  .edit-dialog .preview-panel { margin: 0 16px 16px; }
  #integritySummary { grid-template-columns: 1fr; }
}

/* Romantic milk-blue refresh */
body { background: radial-gradient(circle at top right, #fff4f8 0, transparent 28%), var(--canvas); }
.topbar { background: linear-gradient(135deg,#89b5d2,#a9cce1 58%,#d7c5df); }
.panel,.summary-strip,.entry-form,.table-wrap,.transaction-card,.integrity-panel { box-shadow: 0 8px 24px rgba(102,143,173,.09); border-radius: 14px; }
button.primary,button.secondary,button.danger,input,select,.status-badge { border-radius: 10px; }
.category-title { gap:8px; }
.period-picker { display:flex; align-items:center; gap:4px; }
.period-picker button { min-height:32px; padding:0 9px; border:1px solid var(--line); border-radius:10px; background:#f8fbfd; color:var(--ink); }
.period-picker .period-label { min-width:92px; font-weight:700; }
.category-block { border-bottom:1px solid var(--line); }
.inline-children { margin:0 0 10px 14px; padding:8px 10px; border-left:3px solid #bfd9e9; background:#f7fbfd; border-radius:0 12px 12px 0; }
.child-category { width:100%; display:flex; justify-content:space-between; gap:10px; padding:9px 6px; border:0; border-bottom:1px dashed var(--line); background:transparent; color:var(--ink); text-align:left; }
.child-category:last-child { border-bottom:0; } .child-category strong { font-size:12px; color:var(--muted); white-space:nowrap; }
.compact-empty { padding:12px 4px; }
.backup-preview { margin-top:14px; padding:14px; border:1px solid var(--line); border-radius:12px; background:#f9fcfe; }
.backup-preview h4 { margin:0 0 12px; } .spaced { margin-top:8px; }
@media(max-width:620px){ .category-title{align-items:center}.period-picker .period-label{min-width:78px;padding:0 5px}.filter-bar{grid-template-columns:1fr 1fr}.filter-bar label{grid-column:auto}.filter-bar .search-field{grid-column:1/-1}.child-category{font-size:13px}.child-category strong{white-space:normal;text-align:right}.data-panel button.spaced{margin-top:8px} }

/* V5 compact overview and expandable currency balances */
.summary-strip div { padding: 13px 14px; }
.summary-strip span { margin-bottom: 4px; font-size: 11px; }
.summary-strip strong { font-size: clamp(14px, 2.1vw, 19px); white-space: nowrap; }
.currency-section { margin-top: 14px; }
.currency-section-title { margin-bottom: 8px; padding: 0 2px; }
.currency-section-title h3 { margin: 0; font-size: 15px; }
.currency-balance-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.currency-balance-card { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.92); box-shadow: 0 7px 20px rgba(102,143,173,.08); }
.currency-toggle { width: 100%; min-height: 66px; display: grid; grid-template-columns: minmax(0,1fr) auto 16px; align-items: center; gap: 8px; padding: 11px 12px; border: 0; background: linear-gradient(145deg,#fbfdff,#eef7fc); color: var(--ink); text-align: left; }
.currency-toggle span { display: flex; flex-direction: column; gap: 2px; font-size: 13px; font-weight: 700; }
.currency-toggle small { color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.currency-toggle strong { font-size: clamp(13px, 1.8vw, 17px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.currency-toggle i { color: #789db7; font-style: normal; text-align: center; }
.currency-balance-card.expanded { grid-column: 1 / -1; }
.currency-account-list { padding: 3px 12px 10px; border-top: 1px solid var(--line); background: #fbfdff; }
.currency-account-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px dashed var(--line); font-size: 13px; }
.currency-account-row:last-child { border-bottom: 0; }
.currency-account-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.category-dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 14px; }
@media (max-width: 620px) {
  .summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary-strip div { min-width: 0; padding: 10px 7px; border-right: 1px solid var(--line); border-bottom: 0; text-align: center; }
  .summary-strip div:last-child { border-right: 0; }
  .summary-strip span { font-size: 10px; }
  .summary-strip strong { font-size: 13px; letter-spacing: -.02em; }
  .currency-balance-grid { grid-template-columns: 1fr; gap: 8px; }
  .currency-balance-card.expanded { grid-column: auto; }
  .currency-toggle { min-height: 56px; }
  .category-dashboard-grid { grid-template-columns: 1fr; }
}

.period-total {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.category-title > div:first-child { min-width: 0; }
@media (max-width: 430px) {
  .period-total { font-size: .76rem; }
}
