:root {
  --ink: #17181c;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --line: #e3e6ea;
  --line-strong: #c6ccd4;
  --bg: #ffffff;
  --panel: #f7f8fa;
  --accent: #1f4fd8;
  --danger: #b42318;
  --total: #f2f4f7;
  --radius: 6px;
  --tap: 40px;
}

* { box-sizing: border-box; }

/* `hidden` must beat every layout rule below, including display:flex. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
body.modal-open { overflow: hidden; }

button {
  font: inherit; padding: 9px 16px; border: 1px solid var(--line-strong);
  background: #fff; border-radius: var(--radius); cursor: pointer;
  min-height: var(--tap); color: var(--ink);
}
button:hover { border-color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
button.primary:hover { background: #000; }
button.link {
  border: 0; background: none; color: var(--muted); padding: 6px 2px;
  text-decoration: underline; min-height: 32px;
}
button.link:hover { color: var(--ink); }

input, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 9px 11px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* ---------- gate ---------- */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--panel); padding: 24px; }
.panel { width: 360px; max-width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px; }
.panel h1 { font-size: 20px; margin: 0 0 6px; }
.panel label { display: block; margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.panel input { display: block; width: 100%; margin-top: 5px; min-height: var(--tap); }
.panel button { margin-top: 20px; width: 100%; }

/* ---------- shell ---------- */
header {
  display: flex; justify-content: space-between; align-items: center; gap: 20px;
  padding: 16px 24px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.identity strong { font-size: 17px; letter-spacing: -.01em; }
.meta { color: var(--muted); font-size: 13px; }
.identity .meta { margin-left: 10px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.period { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.period > .period-label { margin-right: 2px; }
.period select {
  font: inherit; font-size: 14px; color: var(--ink); background: #fff;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 8px 9px; min-height: var(--tap); cursor: pointer;
}
.period select:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.period select:disabled { opacity: .45; cursor: not-allowed; }
/* One month at a time, so crossing a year boundary is one tap and not a trip
   through two dropdowns. Square to the tap target: these sit next to the month
   dropdown, and a mis-tap here changes the month the Owner is working in. */
.period button.step {
  padding: 8px 0; width: var(--tap); min-width: var(--tap); min-height: var(--tap);
  line-height: 1; font-size: 12px; color: var(--muted);
}
.period button.step:hover { color: var(--ink); }

/* The Pi's own screen is 800x480. Four controls where there used to be one
   pushed .header-right onto a second row there, costing 45px of a 480px screen
   for the whole life of the session. Below 900px the header stacks on purpose,
   tightly, instead of wrapping by accident. */
@media (max-width: 900px) {
  header { padding: 8px 14px; gap: 8px; }
  .period > .period-label { display: none; }
  /* The business id and type are also on Review and on every document. On a
     small screen they are the first thing that can go to keep the header on
     one row. */
  .identity .meta { display: none; }
  .header-right { gap: 4px; }
  .header-right button.link { padding: 8px 6px; }
}

/* Labels that a screen reader needs and the eye does not: the dropdowns say
   "January" and "2026", which is already unambiguous on screen. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.header-right button.link { padding: 8px 10px; min-height: var(--tap); text-decoration: none; }
.header-right button.link:hover { background: var(--panel); border-radius: var(--radius); }

.tabs { display: flex; gap: 2px; padding: 12px 24px 0; border-bottom: 1px solid var(--line); }
.tab {
  border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0;
  margin-bottom: -1px; color: var(--muted); padding: 10px 18px;
}
.tab[aria-selected="true"] {
  border-color: var(--line); border-bottom-color: #fff; background: #fff;
  color: var(--ink); font-weight: 600;
}

.surface { padding: 24px; }

/* Expense / Income switch - the only new navigation, used in two places. */
.sides {
  display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.side-tab {
  border: 1px solid transparent; border-radius: 6px; padding: 8px 22px;
  color: var(--muted); min-height: var(--tap); background: transparent;
}
.side-tab:hover { border-color: transparent; color: var(--ink); }
.side-tab[aria-selected="true"] {
  background: #fff; border-color: var(--line-strong); color: var(--ink);
  font-weight: 600;
}
.hint { color: var(--muted); margin: 0 0 16px; }
.micro { color: var(--faint); font-size: 13px; margin: 8px 0 0; }
.empty { color: var(--muted); }
.status { color: var(--muted); min-height: 20px; margin-top: 12px; }
.error { color: var(--danger); min-height: 20px; margin: 10px 0 0; font-size: 14px; }
.error:empty, .status:empty { min-height: 0; }

/* ---------- grid ---------- */
.grid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th, .grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
.grid thead th {
  position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: right;
  font-size: 13px; font-weight: 600; padding: 11px 12px; white-space: nowrap;
}
.grid thead th.date-col, .grid tbody td.date-col { text-align: left; padding: 8px 12px; white-space: nowrap; }
.grid tbody td.date-col { color: var(--muted); font-size: 13px; }
.grid tbody tr.weekend td.date-col { color: var(--ink); }
.grid td.value { text-align: right; padding: 8px 12px; height: 42px; }
.grid td.clickable { cursor: pointer; }
.grid td.clickable:hover { background: #eef3fd; box-shadow: inset 0 0 0 1px var(--accent); }
.grid td.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td .count {
  display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 9px;
  background: var(--line); color: var(--muted); font-size: 11px; vertical-align: 1px;
}
.grid .total, .grid tfoot td, .grid tfoot th {
  background: var(--total); font-weight: 600; text-align: right; padding: 8px 12px;
}
.grid tfoot th.date-col { text-align: left; }
.grid .grand-cell { background: #e7eaf0; }
.grid th.archived { color: var(--muted); font-style: italic; font-weight: 500; }
.grid tr:last-child td { border-bottom: 0; }
.grid th:last-child, .grid td:last-child { border-right: 0; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(23, 24, 28, .42);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; z-index: 20;
}
.modal-card {
  background: #fff; border-radius: 10px; width: 420px; max-width: 100%;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  box-shadow: 0 16px 44px rgba(0, 0, 0, .22);
}
.modal-card.wide { width: 680px; }
/* The Profile panel keeps one height across its three sections, so switching
   section never moves the tab bar or the Save button under the reader. */
#modal-profile .modal-card { height: min(760px, calc(100vh - 48px)); }

.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: 20px 24px 14px;
}
.modal-head h2 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.modal-sub { color: var(--muted); margin: 3px 0 0; }
.modal-body { padding: 0 24px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-body h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); margin: 4px 0 10px; font-weight: 600;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 20px; border-top: 1px solid var(--line); margin-top: 4px;
}
.modal-actions button { min-width: 104px; }

/* cell popup */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry-row { display: flex; align-items: center; gap: 10px; }
.entry-row .currency { color: var(--faint); width: 10px; }
.entry-row input.amount {
  flex: 1; font-variant-numeric: tabular-nums; text-align: right;
  min-height: var(--tap); font-size: 16px;
}
.entry-row .remove { padding: 8px 12px; font-size: 14px; color: var(--muted); min-height: var(--tap); }
.entry-row .remove:hover { color: var(--danger); border-color: var(--danger); }
.add-amount {
  margin-top: 12px; width: 100%; color: var(--accent); border-style: dashed;
  border-color: var(--line-strong); background: #fbfcfe;
}
.add-amount:hover { border-color: var(--accent); }
.cell-total-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}
.cell-total-row span:first-child {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint);
}
.cell-total-row #cell-total {
  font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---------- Business Profile ---------- */
.subtabs {
  display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #fff; z-index: 1;
}
.subtab {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 10px 14px; color: var(--muted); margin-bottom: -1px; min-height: 44px;
}
.subtab:hover { border-color: transparent; color: var(--ink); }
.subtab[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.ptab { padding: 20px 0 4px; }

.locked-rows { margin-bottom: 22px; }
.locked-rows > div {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.locked-rows span:first-child { width: 130px; color: var(--muted); font-size: 14px; flex: none; }
.locked-rows strong { flex: 1; font-weight: 600; }
.locked-rows .locked {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); border: 1px solid var(--line); border-radius: 10px; padding: 2px 9px;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field-grid label { font-size: 13px; color: var(--muted); }
.field-grid .wide-field { grid-column: 1 / -1; }
.field-grid input { display: block; width: 100%; margin-top: 5px; min-height: var(--tap); }

.tab-actions {
  display: flex; justify-content: flex-end; align-items: center; gap: 14px;
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
}
.tab-actions .status { margin: 0; }
.tab-actions button { min-width: 104px; }

/* columns */
.add-row { display: flex; gap: 10px; margin-bottom: 6px; }
.add-row input { flex: 1; min-height: var(--tap); }
.add-row button { flex: none; }

.labels { width: 100%; border-collapse: collapse; }
.labels td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.labels td.name { font-weight: 500; }
.labels td.name.archived { color: var(--muted); font-weight: 400; }
.labels td.actions { text-align: right; white-space: nowrap; width: 1%; }
.labels td.actions button { padding: 7px 12px; font-size: 14px; margin-left: 8px; min-height: 36px; }
.labels input.rename { width: 100%; max-width: 320px; min-height: 36px; padding: 6px 9px; }
.labels tr:last-child td { border-bottom: 0; }

.archived-block { margin-top: 14px; }
.archived-table { margin-top: 4px; }
.archived-table td { border-bottom-color: #eef0f3; }

#profile-policy { width: 100%; resize: vertical; min-height: 200px; line-height: 1.55; }

/* ---------- review document ---------- */
.document { border: 1px solid var(--line); border-radius: 8px; padding: 32px; }
.doc-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 32px; padding-bottom: 22px; margin-bottom: 26px; border-bottom: 2px solid var(--ink);
  flex-wrap: wrap;
}
.doc-name { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.doc-lines { color: var(--muted); margin-top: 6px; max-width: 62ch; }
.doc-ids { text-align: right; color: var(--muted); font-size: 13px; }
.doc-ids div:last-child { color: var(--ink); font-size: 17px; font-weight: 600; margin-top: 6px; }

.summary-block {
  margin: 4px 0 30px; max-width: 420px;
}
.summary-line {
  display: flex; justify-content: space-between; gap: 24px; padding: 9px 0;
  border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.summary-line strong { font-weight: 600; }
.summary-line.difference {
  border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 4px;
  padding-top: 13px; font-size: 19px;
}
.summary-line.difference strong { font-weight: 700; }
.summary-line.difference strong.negative { color: var(--danger); }

.side-heading {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 600; margin: 30px 0 10px;
}
.document .side-heading:first-of-type { margin-top: 0; }

.doc-totals { margin-top: 20px; max-width: 400px; }
.doc-totals div {
  display: flex; justify-content: space-between; gap: 24px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.doc-totals .grand-line {
  border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 6px;
  padding-top: 12px; font-size: 17px;
}

.confirmation { margin-top: 36px; }
.confirmation h3, .policy-block h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); margin: 0 0 16px; font-weight: 600;
}
.sign-lines { display: flex; gap: 40px; flex-wrap: wrap; }
.sign-lines > div { display: flex; align-items: baseline; gap: 12px; min-width: 240px; flex: 1; }
.sign-label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.sign-rule { flex: 1; border-bottom: 1px solid var(--line-strong); height: 26px; min-width: 140px; }
.confirmation .hint { margin: 16px 0 0; font-size: 13px; color: var(--faint); }
.policy-block { margin-top: 32px; padding-top: 22px; border-top: 1px solid var(--line); }
.policy-block p { margin: 0; white-space: pre-wrap; max-width: 80ch; }

/* ---------- emit ---------- */
.surface h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); margin: 32px 0 10px; font-weight: 600;
}

/* ---------- review: one primary action ---------- */
.review-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 24px; padding: 18px 20px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap;
}
.review-actions .meta { font-size: 14px; }
#confirm-continue { padding: 13px 30px; font-size: 15px; }

/* the year view inside Review */
.months { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.months th, .months td {
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.months thead th { background: var(--panel); color: var(--muted); font-weight: 600; }
.months td.total { text-align: right; font-variant-numeric: tabular-nums; }
.months td.month-status { color: var(--muted); }

/* ---------- documents surface ---------- */
.documents-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.documents-period { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.documents-business { color: var(--muted); margin-top: 4px; }
.badge {
  align-self: center; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  padding: 6px 12px; border-radius: 999px; background: var(--total);
  color: var(--muted); white-space: nowrap;
}
#surface-documents .summary-block { max-width: 520px; }
#documents-reference { margin-top: 10px; }
.documents-actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line);
}
#generate-documents { padding: 12px 24px; }

/* ---------- document rows ---------- */
.doc-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc-actions button { padding: 10px 18px; }
.doc-actions .micro { margin: 0; }

.documents, .documents th, .documents td {
  text-align: left; padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top;
}
.documents th { color: var(--muted); font-weight: 600; }
.documents td:last-child { text-align: right; }
.documents button {
  padding: 7px 14px; font-size: 13px; min-height: var(--tap);
}
.file-link {
  display: inline-block; margin-right: 8px; padding: 5px 12px; min-height: 34px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 600;
}
.file-link:hover { border-color: var(--ink); }
.documents td.ready { color: var(--ink); font-weight: 600; }

/* ---------- narrow screens / tablets in portrait ---------- */
@media (max-width: 720px) {
  header, .surface { padding-left: 16px; padding-right: 16px; }
  .tabs { padding-left: 16px; padding-right: 16px; }
  .modal { padding: 12px; }
  .modal-card, .modal-card.wide { width: 100%; max-height: calc(100vh - 24px); }
  #modal-profile .modal-card { height: calc(100vh - 24px); }
  .modal-head, .modal-actions { padding-left: 18px; padding-right: 18px; }
  .modal-body, .subtabs { padding-left: 18px; padding-right: 18px; }
  .field-grid { grid-template-columns: 1fr; }
  .document { padding: 20px; }
  .locked-rows span:first-child { width: 104px; }
}
