:root {
  --bg: #f3f5f1;
  --panel: #ffffff;
  --ink: #17231d;
  --muted: #6e7772;
  --line: #dfe5df;
  --brand: #183f30;
  --brand-2: #256048;
  --accent: #d7a54b;
  --soft: #edf2ee;
  --danger: #a74242;
  --positive: #20744e;
  --negative: #a74242;
  --shadow: 0 10px 30px rgba(20, 50, 38, .07);
  --radius: 18px;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: rgba(15, 38, 29, .97); color: #fff; box-shadow: 0 8px 24px rgba(15,38,29,.18); }
.topbar h1 { margin: 1px 0 0; font-size: 18px; letter-spacing: -.02em; }
.eyebrow, .section-kicker { font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.eyebrow { color: #d7c59d; }
.section-kicker { color: var(--brand-2); }
main { width: min(1440px, 100%); margin: 0 auto; padding: 18px; }
.toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.toolbar-actions { display: flex; gap: 8px; }
.toolbar-actions .btn { flex: 1; }
.demo-warning { padding: 11px 13px; border: 1px solid #d8c49d; background: #fff9ea; border-radius: 12px; color: #665328; font-size: 12px; margin-bottom: 14px; }
.btn, .icon-btn, .text-btn { border: 0; }
.btn { min-height: 42px; border-radius: 12px; padding: 0 14px; font-weight: 750; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.btn.save { width: 100%; background: var(--brand); color: #fff; margin-top: 14px; }
.btn.small { min-height: 34px; padding: 0 10px; border-radius: 9px; font-size: 12px; }
.icon-btn { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: rgba(255,255,255,.12); color: inherit; }
.text-btn { background: transparent; color: var(--brand-2); font-weight: 750; padding: 6px; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 13px; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.kpi strong { display: block; margin: 5px 0 2px; font-size: clamp(19px, 5vw, 30px); line-height: 1; letter-spacing: -.04em; overflow: hidden; text-overflow: ellipsis; }
.kpi small { display: block; color: #89918d; font-size: 9px; line-height: 1.3; }
.kpi.emphasis { border-color: #d9c6a0; background: #fffaf0; }
.kpi.result { grid-column: 1 / -1; color: #fff; background: var(--brand); border-color: var(--brand); }
.kpi.result span, .kpi.result small { color: rgba(255,255,255,.72); }
.layout-grid, .breakdown-grid { display: grid; gap: 12px; margin-bottom: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.panel-head h2, .dialog-head h2 { margin: 2px 0 0; font-size: 17px; letter-spacing: -.025em; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--soft); border-radius: 12px; margin-bottom: 14px; }
.seg { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 750; font-size: 12px; }
.seg.active { background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.form-grid { display: grid; gap: 11px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field span { color: #53605a; font-size: 11px; font-weight: 750; }
.field em { font-style: normal; font-weight: 500; color: #929995; }
.field input, .field select, .filters select, .filters input, .add-row input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 11px; padding: 0 11px; color: var(--ink); background: #fff; outline: none; }
.field input:focus, .field select:focus, .filters select:focus, .filters input:focus, .add-row input:focus { border-color: #7fa490; box-shadow: 0 0 0 3px rgba(37,96,72,.09); }
.field.compact { width: 100%; }
.money-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; min-height: 42px; }
.money-input:focus-within { border-color: #7fa490; box-shadow: 0 0 0 3px rgba(37,96,72,.09); }
.money-input b { padding-left: 11px; color: var(--brand-2); }
.money-input input { border: 0; box-shadow: none !important; min-height: 40px; }
.hidden { display: none !important; }
.chart-panel { min-height: 290px; }
.pill { padding: 5px 8px; border-radius: 999px; background: var(--soft); color: var(--brand); font-size: 10px; font-weight: 800; white-space: nowrap; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 10px; margin-bottom: 12px; }
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.revenue { background: var(--brand-2); }
.dot.cost { background: var(--accent); }
.chart { height: 215px; display: flex; align-items: stretch; gap: 3px; overflow-x: auto; padding: 7px 2px 0; border-bottom: 1px solid var(--line); }
.day-col { flex: 0 0 20px; min-width: 20px; display: grid; grid-template-rows: 1fr 16px; gap: 4px; }
.bars { display: flex; align-items: end; justify-content: center; gap: 2px; min-height: 0; }
.bar { width: 7px; border-radius: 4px 4px 1px 1px; min-height: 1px; }
.bar.revenue { background: var(--brand-2); }
.bar.cost { background: var(--accent); }
.day-label { text-align: center; font-size: 8px; color: #909893; }
.rank-list { display: grid; gap: 11px; }
.rank-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; }
.rank-name { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-size: 12px; font-weight: 800; }
.rank-track { grid-column: 1 / -1; height: 6px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.rank-fill { height: 100%; background: var(--brand-2); border-radius: 999px; }
.rank-row.cost .rank-fill { background: var(--accent); }
.entries-head { align-items: flex-start; }
.filters { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; width: 100%; }
.filters select, .filters input { min-height: 36px; font-size: 11px; padding: 0 7px; }
.entries-list { display: grid; gap: 7px; }
.entry-row { display: grid; grid-template-columns: 43px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid #edf0ed; }
.entry-row:last-child { border-bottom: 0; }
.entry-date { text-align: center; padding: 7px 3px; border-radius: 9px; background: var(--soft); color: var(--brand); font-size: 10px; font-weight: 800; }
.entry-main { min-width: 0; }
.entry-main strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-main small { display: block; color: var(--muted); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.entry-value { text-align: right; font-size: 12px; font-weight: 850; white-space: nowrap; }
.entry-value.revenue { color: var(--positive); }
.delete-btn { width: 28px; height: 28px; border: 0; border-radius: 8px; background: #f8eeee; color: var(--danger); }
.empty { text-align: center; padding: 28px; color: var(--muted); font-size: 12px; }
dialog { width: min(900px, calc(100% - 20px)); border: 0; border-radius: 20px; padding: 0; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(10,25,19,.58); backdrop-filter: blur(2px); }
.dialog-card { padding: 16px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog-head .icon-btn { background: var(--soft); color: var(--brand); }
.manager-cols { display: grid; gap: 18px; }
.manager-title { display: flex; justify-content: space-between; align-items: center; }
.manager-title h3 { margin: 0 0 8px; font-size: 14px; }
.manager-title span { color: var(--muted); font-size: 10px; }
.manager-list { display: grid; gap: 5px; max-height: 250px; overflow: auto; }
.manager-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 9px; border: 1px solid var(--line); border-radius: 9px; font-size: 11px; }
.manager-item.inactive { opacity: .55; text-decoration: line-through; }
.toggle-btn { border: 0; background: var(--soft); color: var(--brand); border-radius: 8px; padding: 5px 8px; font-size: 10px; font-weight: 800; }
.add-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px; margin-top: 8px; }
.dialog-note { margin: 16px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #102b20; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 11px; box-shadow: 0 12px 30px rgba(0,0,0,.22); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.print-only { display: none; }

@media (min-width: 720px) {
  main { padding: 24px; }
  .topbar { padding: 16px 24px; }
  .toolbar { flex-direction: row; justify-content: space-between; align-items: end; }
  .toolbar-actions .btn { flex: initial; }
  .field.compact { width: 190px; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi.result { grid-column: auto; }
  .layout-grid { grid-template-columns: minmax(340px, .8fr) minmax(420px, 1.2fr); }
  .breakdown-grid { grid-template-columns: 1fr 1fr; }
  .breakdown-grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
  .manager-cols { grid-template-columns: 1fr 1fr; }
  .entries-head { align-items: center; }
  .filters { width: auto; }
}

@media (min-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpi strong { font-size: 27px; }
}

@media print {
  @page { size: Letter portrait; margin: 10mm; }
  body { background: #fff; font-size: 10pt; }
  .no-print, dialog, .toast, .delete-btn, .text-btn { display: none !important; }
  .print-only { display: block; }
  main { width: 100%; max-width: none; padding: 0; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .kpi { box-shadow: none; break-inside: avoid; padding: 8px; }
  .kpi strong { font-size: 17pt; }
  .kpi.result { grid-column: auto; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .layout-grid { display: block; }
  .quick-entry { display: none; }
  .panel { box-shadow: none; border-radius: 10px; margin-bottom: 8px; padding: 10px; break-inside: avoid; }
  .chart-panel { min-height: 220px; }
  .chart { height: 150px; overflow: hidden; }
  .breakdown-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .entries-panel { break-inside: auto; }
  .entry-row { grid-template-columns: 42px minmax(0,1fr) auto; }
  .report-footer { margin-top: 10px; border-top: 1px solid #ddd; padding-top: 6px; color: #666; font-size: 8pt; }
  .report-footer p { margin: 2px 0; }
}

/* VS1 official-history additions */
.brand-lockup { display:flex; align-items:center; gap:12px; min-width:0; }
.brand-logo { display:block; width:84px; height:48px; object-fit:contain; object-position:left center; flex:0 0 auto; }
.brand-fallback h1 { margin:1px 0 0; }
.brand-title { display:none; border-left:1px solid rgba(255,255,255,.18); padding-left:12px; }
.brand-title span { display:block; font-size:12px; font-weight:850; letter-spacing:.06em; }
.brand-title small { display:block; margin-top:2px; color:rgba(255,255,255,.62); font-size:9px; }
.audit-note { padding:12px 14px; border:1px solid #d8c49d; background:#fffaf0; border-radius:12px; color:#5f4d26; font-size:11px; line-height:1.5; margin-bottom:12px; }
.audit-note strong { display:block; margin-bottom:3px; color:#4c3b18; }
.official-badge { display:inline-block; vertical-align:1px; margin-left:5px; padding:2px 5px; border-radius:999px; background:#e7f0ea; color:#256048; font-size:7px; letter-spacing:.06em; }
.locked-entry { width:28px; height:28px; display:grid; place-items:center; opacity:.58; font-size:12px; }
.chart-legend b { font-weight:700; }
.print-brand { display:flex; align-items:center; gap:10px; margin-bottom:5px; }
.print-brand img { width:78px; height:44px; object-fit:contain; object-position:left center; }

@media (min-width: 720px) {
  .brand-logo { width:102px; height:54px; }
  .brand-title { display:block; }
}

@media print {
  .audit-note { background:#fff; border-color:#bbb; color:#333; break-inside:avoid; }
  .audit-note strong { color:#222; }
  .official-badge { border:1px solid #bbb; background:#fff; color:#333; }
  .print-brand img { display:block; }
}


/* VS2 centered brand + 4-type finance model */
.topbar { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; min-height:78px; }
.topbar-side { min-width:0; }
.topbar-left strong { display:block; font-size:11px; letter-spacing:.08em; }
.topbar-left small { display:block; margin-top:3px; color:rgba(255,255,255,.62); font-size:9px; }
.topbar-right { display:flex; justify-content:flex-end; }
.brand-center { display:grid; place-items:center; }
.brand-center .brand-logo { width:64px; height:64px; object-fit:contain; object-position:center; border-radius:50%; }
.breakdown-grid.three { grid-template-columns:1fr; }
.rank-row.beverage .rank-fill { background:#7b5b92; }
.entry-value.beverage { color:#7b5b92; }
@media (max-width:719px) { .topbar-left strong, .topbar-left small { display:none; } .topbar { min-height:74px; } .brand-center .brand-logo { width:58px; height:58px; } }
@media (min-width:720px) { .brand-center .brand-logo { width:70px; height:70px; } .breakdown-grid.three { grid-template-columns:repeat(3,minmax(0,1fr)); } }
@media print { .breakdown-grid.three { grid-template-columns:repeat(3,1fr); } .print-brand { justify-content:center; text-align:center; } .print-brand img { width:60px; height:60px; object-position:center; } }


/* VS3 selection subtotals + progressive history */
.rank-row.selectable { grid-template-columns: 18px minmax(0, 1fr) auto; column-gap: 8px; }
.rank-row.no-check { grid-template-columns: minmax(0, 1fr) auto; }
.rank-check { width: 16px; height: 16px; margin: 0; accent-color: var(--brand-2); cursor: pointer; }
.rank-subtotal { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:5px; padding:12px 0 1px; border-top:2px solid var(--line); color:var(--brand); }
.rank-subtotal span { font-size:11px; font-weight:850; text-transform:uppercase; letter-spacing:.06em; }
.rank-subtotal strong { font-size:15px; font-weight:900; white-space:nowrap; }
.history-controls { display:flex; justify-content:center; gap:8px; padding-top:12px; }
.history-controls .btn { min-width:120px; }
@media (max-width: 719px) {
  .rank-row.selectable { grid-template-columns: 20px minmax(0,1fr) auto; }
  .rank-check { width:18px; height:18px; }
  .history-controls { display:grid; grid-template-columns:1fr 1fr; }
  .history-controls .btn:only-child { grid-column:1 / -1; }
}
@media print {
  .rank-row.selectable { grid-template-columns:minmax(0,1fr) auto; }
  .selectable-subtotal { display:none !important; }
}

/* VS5 — VS1-style full-width bars + anchored subtotal footer */
.breakdown-grid.three { align-items: stretch; }
.breakdown-panel {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  overflow: hidden;
}
.breakdown-panel > .panel-head { flex: 0 0 auto; }
.breakdown-panel .rank-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-height: 0;
}
.breakdown-panel .rank-row {
  width: 100%;
  align-items: center;
  column-gap: 8px;
  row-gap: 7px;
}
.breakdown-panel .rank-row.selectable {
  grid-template-columns: 18px minmax(0, 1fr) auto;
}
.breakdown-panel .rank-row.no-check {
  grid-template-columns: minmax(0, 1fr) auto;
}
.breakdown-panel .rank-check {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  justify-self: start;
}
.breakdown-panel .rank-name {
  min-width: 0;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breakdown-panel .rank-row.selectable .rank-name {
  grid-column: 2;
  grid-row: 1;
}
.breakdown-panel .rank-row.no-check .rank-name {
  grid-column: 1;
  grid-row: 1;
}
.breakdown-panel .rank-value {
  grid-column: -2 / -1;
  grid-row: 1;
  min-width: 74px;
  text-align: right;
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
  white-space: nowrap;
}
.breakdown-panel .rank-track {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  height: 6px;
  margin: 0;
  background: var(--soft);
  border-radius: 999px;
  overflow: hidden;
}
.breakdown-panel .rank-subtotal {
  flex: 0 0 auto;
  margin: auto -15px 0;
  padding: 14px 15px;
  min-height: 52px;
  border-top: 1px solid #d7e2da;
  background: #edf4ef;
  color: var(--brand);
  border-radius: 0;
}
.breakdown-panel.beverage-panel .rank-subtotal {
  background: #f2edf5;
  border-top-color: #dfd2e6;
  color: #5e416f;
}
.breakdown-panel .rank-subtotal span {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .09em;
}
.breakdown-panel .rank-subtotal strong {
  font-size: 16px;
  font-weight: 900;
}
.breakdown-panel .empty { flex: 0 0 auto; }

@media (max-width: 719px) {
  .breakdown-panel .rank-row.selectable {
    grid-template-columns: 20px minmax(0, 1fr) auto;
  }
  .breakdown-panel .rank-row.no-check {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .breakdown-panel .rank-value { min-width: 70px; }
  .breakdown-panel .rank-subtotal { min-height: 50px; }
}

@media print {
  .breakdown-panel { padding-bottom: 0; }
  .breakdown-panel .rank-row.selectable {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .breakdown-panel .rank-row.selectable .rank-name { grid-column: 1; }
  .breakdown-panel .rank-track { grid-column: 1 / -1; }
  .breakdown-panel .rank-subtotal {
    margin-left: -10px;
    margin-right: -10px;
    margin-bottom: -10px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}


/* VS6 — verified-import status + dark subtotal footers */
.verification-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  margin-bottom: 14px;
  padding: 7px 12px;
  border: 1px solid #7cad8d;
  border-radius: 10px;
  background: #eaf5ed;
  color: #174c31;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .01em;
}
.verification-strip.hidden { display: none; }
.verification-check {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 50%;
  background: #1d6a43;
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.breakdown-panel .rank-subtotal {
  background: #143c2d;
  border-top-color: #143c2d;
  color: #fff;
}
.breakdown-panel.expense-panel .rank-subtotal {
  background: #1d4b38;
  border-top-color: #1d4b38;
  color: #fff;
}
.breakdown-panel.beverage-panel .rank-subtotal {
  background: #4d365e;
  border-top-color: #4d365e;
  color: #fff;
}
.breakdown-panel .rank-subtotal span,
.breakdown-panel .rank-subtotal strong { color: #fff; }

@media print {
  .verification-strip { display: none !important; }
  .breakdown-panel .rank-subtotal,
  .breakdown-panel.beverage-panel .rank-subtotal,
  .breakdown-panel.expense-panel .rank-subtotal {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* VS7 — mobile stability / responsive hardening */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
@supports (overflow: clip) {
  html,
  body { overflow-x: clip; }
}
body { -webkit-text-size-adjust: 100%; }
.app-shell,
main,
.toolbar,
.kpi-grid,
.layout-grid,
.breakdown-grid,
.entries-panel,
.panel,
.panel-head,
.form-grid,
.segmented,
.filters,
.entries-list {
  min-width: 0;
  max-width: 100%;
}
.panel-head > div,
.toolbar-actions,
.topbar-side,
.entry-main,
.rank-name { min-width: 0; }
button,
input,
select { max-width: 100%; }

@media (max-width: 719px) {
  :root { --radius: 15px; }

  body { overscroll-behavior-x: none; }

  /* Stable mobile header: logo stays optically centered regardless of right-side controls. */
  .topbar {
    position: sticky;
    top: 0;
    width: 100%;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: 8px;
    padding-left: max(12px, env(safe-area-inset-left));
    contain: layout paint;
  }
  .topbar-left { display: none; }
  .brand-center {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
  }
  .brand-center .brand-logo {
    display: block;
    width: 58px;
    height: 58px;
    max-width: 58px;
    max-height: 58px;
  }
  .topbar-right {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
  }

  main {
    width: 100%;
    padding-top: 12px;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .toolbar { gap: 9px; margin-bottom: 10px; }
  .toolbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
    gap: 7px;
  }
  .toolbar-actions .btn {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
    font-size: 11px;
    white-space: normal;
    line-height: 1.15;
  }

  .verification-strip {
    width: 100%;
    min-height: 32px;
    margin-bottom: 10px;
    padding: 6px 9px;
    font-size: 10px;
    line-height: 1.25;
    text-align: center;
  }

  .kpi-grid { gap: 8px; margin-bottom: 10px; }
  .kpi { padding: 11px; border-radius: 13px; }
  .kpi strong {
    font-size: clamp(18px, 6.2vw, 24px);
    white-space: nowrap;
  }
  .kpi span { font-size: 10px; }
  .kpi small { font-size: 8px; }

  .layout-grid,
  .breakdown-grid { gap: 10px; margin-bottom: 10px; }
  .panel { padding: 13px; border-radius: 15px; }
  .panel-head { gap: 8px; margin-bottom: 11px; }
  .panel-head > div { overflow: hidden; }
  .panel-head h2,
  .dialog-head h2 {
    font-size: 16px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }
  .text-btn {
    flex: 0 0 auto;
    font-size: 12px;
    padding: 5px 2px 5px 6px;
    white-space: nowrap;
  }

  /* Two rows is materially more stable than four squeezed tabs on narrow phones. */
  .segmented {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }
  .seg {
    min-width: 0;
    min-height: 36px;
    padding-inline: 4px;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .form-grid { gap: 9px; }
  .field,
  .field input,
  .field select,
  .money-input,
  .money-input input {
    min-width: 0;
    width: 100%;
  }
  .field input[type="date"],
  .field input[type="month"],
  .filters input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }

  .chart-panel { min-height: 270px; }
  .chart { width: 100%; max-width: 100%; -webkit-overflow-scrolling: touch; }
  .pill { flex: 0 0 auto; max-width: 46%; overflow: hidden; text-overflow: ellipsis; }

  .breakdown-panel { padding-bottom: 0; }
  .breakdown-panel .rank-list { gap: 10px; }
  .breakdown-panel .rank-row.selectable {
    grid-template-columns: 20px minmax(0, 1fr) auto;
    column-gap: 7px;
  }
  .breakdown-panel .rank-name { font-size: 11px; }
  .breakdown-panel .rank-value { min-width: 66px; font-size: 11px; }
  .breakdown-panel .rank-track { height: 6px; }
  .breakdown-panel .rank-subtotal {
    margin-left: -13px;
    margin-right: -13px;
    padding-left: 13px;
    padding-right: 13px;
  }

  .entries-head { display: block; }
  .filters {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
    margin-top: 10px;
  }
  .filters select,
  .filters input { min-width: 0; width: 100%; }
  #clearFilters { grid-column: 1 / -1; width: 100%; }

  .entry-row {
    grid-template-columns: 38px minmax(0, 1fr) auto 28px;
    gap: 6px;
    padding: 9px 0;
  }
  .entry-date { padding-inline: 2px; font-size: 9px; }
  .entry-main strong { font-size: 11px; }
  .entry-value { font-size: 11px; }

  .history-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }
  .history-controls .btn { min-width: 0; width: 100%; }

  dialog {
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    max-height: calc(100dvh - 16px);
    margin: auto;
    border-radius: 16px;
  }
  .dialog-card { padding: 13px; max-width: 100%; overflow-x: hidden; }
  .manager-cols { min-width: 0; }
  .add-row { grid-template-columns: minmax(0, 1fr) auto; }
  .add-row .btn { padding-inline: 9px; }

  .toast {
    width: max-content;
    max-width: calc(100% - 24px);
    bottom: max(14px, env(safe-area-inset-bottom));
    text-align: center;
  }
}

@media (max-width: 374px) {
  main {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }
  .toolbar-actions { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .kpi { padding: 10px; }
  .kpi strong { font-size: 18px; }
  .panel { padding: 11px; }
  .breakdown-panel .rank-subtotal {
    margin-left: -11px;
    margin-right: -11px;
    padding-left: 11px;
    padding-right: 11px;
  }
  .filters { grid-template-columns: 1fr; }
  #clearFilters { grid-column: auto; }
  .entry-row {
    grid-template-columns: 36px minmax(0, 1fr) auto 26px;
    gap: 5px;
  }
}
