/* ==========================================================================
   Expense Tracking — instrument panel chrome, ledger paper data surfaces.
   ========================================================================== */

:root {
  --ink:        #131a21;
  --ink-2:      #1d2731;
  --ink-3:      #2b3844;
  --paper:      #faf9f6;
  --paper-2:    #ffffff;
  --band:       #f3f1ec;
  --rule:       #dfdcd4;
  --rule-soft:  #ece9e2;
  --text:       #1b232b;
  --text-2:     #5a6672;
  --text-3:     #8b95a0;
  --flame:      #0e6fa8;
  --flame-lift: #1189ce;
  --flame-wash: #e7f1f8;
  --ember:      #b4531a;
  --ember-wash: #fbeee3;
  --moss:       #1e7a55;
  --moss-wash:  #e6f2ec;
  --alarm:      #a32020;

  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --rail-w: 208px;
  --shadow: 0 1px 2px rgba(19, 26, 33, .06), 0 8px 24px -12px rgba(19, 26, 33, .18);
}

* { box-sizing: border-box; }

/* The hidden attribute works by applying display:none, which any explicit
   display rule overrides. Several elements here are both toggled with `hidden`
   and given a display (the sign-in panel is a grid, the app shell is a flex
   row), so without this they never actually hide — they just stack up the page.
   Declared once, before anything that sets display. */
[hidden] { display: none !important; }

/* The hidden attribute works by applying display:none, which any explicit
   display rule overrides. Several elements here are both toggled with `hidden`
   and given a display (the sign-in panel is a grid, the app shell is a flex
   row), so without this they never actually hide — they just stack up the page.
   Declared once, before anything that sets display. */


html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 400 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--flame-lift);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- sign in --- */

.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #24313d 0%, transparent 70%),
    var(--ink);
}

.signin-card {
  width: min(380px, 100%);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 34px 32px 30px;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .55);
  display: flex;
  flex-direction: column;
}

.signin-mark { color: var(--flame); margin-bottom: 10px; }

.signin-card h1 {
  font: 600 27px/1 var(--cond);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 0 0 6px;
}

.signin-sub { margin: 0 0 22px; color: var(--text-2); font-size: 13px; }

.signin-card label {
  font: 600 11px/1 var(--sans);
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}

.signin-card input {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--paper);
}

.signin-card input:focus { border-color: var(--flame); background: #fff; }

.signin-error {
  margin: 0 0 14px;
  color: var(--alarm);
  font-size: 13px;
  background: #fdecec;
  border-left: 3px solid var(--alarm);
  padding: 8px 10px;
  border-radius: 0 4px 4px 0;
}

/* --------------------------------------------------------------- shell --- */

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

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--ink);
  color: #c9d2db;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  color: var(--flame-lift);
  border-bottom: 1px solid #26323d;
}

.rail-mark span {
  font: 600 15px/1.05 var(--cond);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #eef2f6;
}

.rail-nav { list-style: none; margin: 10px 0 0; padding: 0 8px; flex: 1; overflow-y: auto; }

.rail-nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  color: #a9b5c1;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
}

.rail-nav button:hover { background: #1f2a34; color: #e9eef3; }

.rail-nav button[aria-current="page"] {
  background: #223b4e;
  color: #fff;
  box-shadow: inset 2px 0 0 var(--flame-lift);
}

.rail-nav .badge {
  margin-left: auto;
  font: 500 11px/1 var(--mono);
  background: var(--ember);
  color: #fff;
  border-radius: 9px;
  padding: 3px 6px;
}

.rail-foot { padding: 10px 12px 14px; border-top: 1px solid #26323d; }

.rail-user {
  width: 100%;
  background: #1f2a34;
  border: 0;
  color: #cdd6de;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12.5px;
  text-align: left;
}

.rail-user:hover { background: #26333f; color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* -------------------------------------------------------------- topbar --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 30;
}

/* Signature element: a stamped selector plate carrying the entity code. */
.plate {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, #22303c, var(--ink));
  border: 1px solid #0b1015;
  border-radius: 7px;
  padding: 7px 12px 7px 10px;
  cursor: pointer;
  color: #e8edf2;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}

.plate:hover { background: linear-gradient(180deg, #2a3945, #182129); }

.plate-code {
  font: 700 25px/1 var(--mono);
  letter-spacing: -.02em;
  color: var(--flame-lift);
  padding-right: 12px;
  border-right: 1px solid #3a4854;
}

.plate-body { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }

.plate-eyebrow {
  font: 600 9.5px/1 var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #7f8d9a;
}

.plate-name {
  font: 600 14px/1.1 var(--cond);
  letter-spacing: .05em;
  text-transform: uppercase;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plate-caret { color: #7f8d9a; margin-left: 2px; }

.plate-menu {
  position: absolute;
  top: 62px;
  left: 22px;
  z-index: 40;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 296px;
}

.plate-menu button {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: none;
  border: 0;
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
}

.plate-menu button:hover { background: var(--flame-wash); }
.plate-menu button[aria-selected="true"] { background: var(--band); font-weight: 600; }
.plate-menu .code { font: 600 13px/1 var(--mono); color: var(--flame); min-width: 42px; }
.plate-menu .sep { border-top: 1px solid var(--rule-soft); margin: 5px 2px; }

.year-select { display: flex; align-items: center; gap: 7px; }

.year-select span {
  font: 600 10px/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.year-select select,
.field select,
.field input,
.field textarea {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 7px 9px;
  background: var(--paper-2);
}

.year-select select { font-family: var(--mono); font-size: 13px; padding: 6px 8px; }

.topbar-gauge { margin-left: auto; display: flex; gap: 20px; align-items: center; }

.gauge-item { text-align: right; }

.gauge-item .k {
  display: block;
  font: 600 9.5px/1 var(--sans);
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 3px;
}

.gauge-item .v { font: 500 16px/1 var(--mono); }
.gauge-item.warn .v { color: var(--ember); }
.gauge-item.good .v { color: var(--moss); }

/* ---------------------------------------------------------------- view --- */

.view { padding: 22px; flex: 1; min-width: 0; outline: none; }

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-head h2 {
  font: 600 24px/1 var(--cond);
  letter-spacing: .05em;
  text-transform: uppercase;
  margin: 0;
}

.page-head .sub { color: var(--text-2); font-size: 13px; margin: 4px 0 0; }
.page-head .spacer { flex: 1; }

.eyebrow {
  font: 600 10px/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* --------------------------------------------------------------- cards --- */

.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 9px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule-soft);
}

.card-head h3 {
  font: 600 15px/1 var(--cond);
  letter-spacing: .07em;
  text-transform: uppercase;
  margin: 0;
}

.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 12px; }

.tile {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--flame);
  border-radius: 7px;
  padding: 13px 15px;
}

.tile.warn { border-left-color: var(--ember); }
.tile.good { border-left-color: var(--moss); }

.tile .k {
  font: 600 10px/1 var(--sans);
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-3);
}

.tile .v { font: 500 25px/1.1 var(--mono); margin-top: 7px; }
.tile .n { font-size: 12px; color: var(--text-2); margin-top: 5px; }

/* -------------------------------------------------------------- button --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover { background: var(--band); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--flame);
  border-color: var(--flame);
  color: #fff;
}

.btn-primary:hover { background: var(--flame-lift); border-color: var(--flame-lift); }

.btn-danger { color: var(--alarm); border-color: #e5c6c6; }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }
.btn-ghost { background: none; border-color: transparent; }
.btn-ghost:hover { background: var(--band); }

/* -------------------------------------------------------------- fields --- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.field > span {
  font: 600 10px/1 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-2);
}

.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--flame); }
.field.num input { font-family: var(--mono); text-align: right; }
.field.wide { grid-column: span 2; }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.field input[readonly] { background: var(--band); color: var(--text-2); font-family: var(--mono); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--flame); }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.form-note { font-size: 12px; color: var(--text-2); }

/* ---------------------------------------------------------------- grid --- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule-soft);
  flex-wrap: wrap;
}

.search {
  position: relative;
  flex: 1 1 220px;
  min-width: 180px;
  max-width: 360px;
}

.search input {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 7px 9px 7px 30px;
  background: var(--paper);
}

.search svg { position: absolute; left: 9px; top: 8px; color: var(--text-3); }
.search input:focus { background: #fff; border-color: var(--flame); }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }

.seg button {
  background: var(--paper-2);
  border: 0;
  border-right: 1px solid var(--rule);
  padding: 7px 11px;
  font-size: 12.5px;
  cursor: pointer;
}

.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--band); }
.seg button[aria-pressed="true"] { background: var(--ink-2); color: #fff; }

.grid-wrap { overflow: auto; max-height: calc(100vh - 300px); }

table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }

table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ink-2);
  color: #dfe6ec;
  text-align: left;
  font: 600 10.5px/1.2 var(--sans);
  letter-spacing: .09em;
  text-transform: uppercase;
  padding: 9px 10px;
  white-space: nowrap;
  border-bottom: 1px solid var(--ink);
  cursor: pointer;
  user-select: none;
}

table.grid thead th:hover { background: var(--ink-3); }
table.grid thead th.num { text-align: right; }
table.grid thead th .arrow { color: var(--flame-lift); margin-left: 4px; }

table.grid tr.filters th {
  position: sticky;
  top: 31px;
  z-index: 4;
  background: var(--band);
  padding: 4px 5px;
  border-bottom: 1px solid var(--rule);
  cursor: default;
}

/* These inputs live inside <thead>, which is light-on-dark, so the text colour
   has to be set back or what you type looks washed out. */
table.grid tr.filters input,
table.grid tr.filters select {
  width: 100%;
  min-width: 64px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: #fff;
}

table.grid tr.filters input::placeholder {
  color: var(--text-3);
  font-weight: 400;
}

table.grid tr.filters input:focus,
table.grid tr.filters select:focus {
  border-color: var(--flame);
  box-shadow: 0 0 0 2px rgba(14, 111, 168, .15);
}

/* A column that is filtering right now, so it is obvious at a glance. */
table.grid tr.filters th.filtered {
  background: var(--flame-wash);
  box-shadow: inset 0 -2px 0 var(--flame);
}

table.grid tr.filters th.filtered input,
table.grid tr.filters th.filtered select {
  border-color: var(--flame);
  background: #fff;
  color: var(--flame);
  font-weight: 600;
}

table.grid thead th.filtered {
  background: var(--flame);
  color: #fff;
}

table.grid thead th.filtered::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  margin-left: 6px;
  vertical-align: middle;
}

/* Summary of what is filtering, shown in the toolbar. */
.filter-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--flame-wash);
  border: 1px solid var(--flame);
  color: var(--flame);
  font-size: 12.5px;
  font-weight: 600;
}

.filter-state .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--flame);
}

.filter-state button {
  background: var(--flame);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.filter-state button:hover { background: var(--flame-lift); }

.search input.active {
  border-color: var(--flame);
  background: #fff;
  font-weight: 500;
}

table.grid tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.grid tbody tr:nth-child(even) { background: #fbfaf7; }
table.grid tbody tr:hover { background: var(--flame-wash); }
table.grid tbody tr.selected { background: #dceaf5; }
table.grid td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.grid td.mono { font-family: var(--mono); }
table.grid td.neg { color: var(--alarm); }
table.grid td.editable { cursor: text; }
table.grid td.editable:hover { box-shadow: inset 0 0 0 1px var(--flame); border-radius: 3px; }
table.grid td.saving { background: #fff8e1 !important; }

table.grid td .cell-input {
  width: 100%;
  border: 1px solid var(--flame);
  border-radius: 3px;
  padding: 4px 6px;
  font: inherit;
  background: #fff;
}

table.grid td .cell-input.num { text-align: right; font-family: var(--mono); }

table.grid tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--ink-2);
  color: #eef2f6;
  font: 500 13px/1 var(--mono);
  padding: 10px;
  border-top: 2px solid var(--flame);
  text-align: right;
  white-space: nowrap;
}

table.grid tfoot td.label {
  text-align: left;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #a9b5c1;
}

.chip {
  display: inline-block;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 4px 7px;
  border-radius: 4px;
}

.chip.paid { background: var(--moss-wash); color: var(--moss); }
.chip.open { background: var(--ember-wash); color: var(--ember); }
.chip.late { background: #fdecec; color: var(--alarm); }
.chip.mute { background: var(--band); color: var(--text-2); }

.grid-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--rule-soft);
  font-size: 12.5px;
  color: var(--text-2);
  flex-wrap: wrap;
}

.grid-foot .spacer { flex: 1; }
.rowcount { font-family: var(--mono); }

.empty { padding: 46px 20px; text-align: center; color: var(--text-2); }
.empty h4 { font: 600 17px/1 var(--cond); letter-spacing: .06em; text-transform: uppercase; margin: 0 0 8px; color: var(--text); }
.empty p { margin: 0 0 14px; font-size: 13px; }

/* ------------------------------------------------------------- reports --- */

.report-controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }

table.pivot { border-collapse: collapse; width: 100%; font-size: 12.5px; }

table.pivot th, table.pivot td { padding: 6px 9px; border-bottom: 1px solid var(--rule-soft); white-space: nowrap; }

table.pivot thead th {
  position: sticky;
  top: 0;
  background: var(--ink-2);
  color: #dfe6ec;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: right;
}

table.pivot thead th:first-child { text-align: left; }
table.pivot td { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.pivot td:first-child { text-align: left; font-family: var(--sans); }
table.pivot td.zero { color: #c3c9cf; }
table.pivot td.link { cursor: pointer; }
table.pivot td.link:hover { background: var(--flame-wash); color: var(--flame); }
table.pivot tbody tr:hover { background: #fbfaf7; }
table.pivot tr.total td { border-top: 2px solid var(--flame); font-weight: 600; background: var(--band); }
table.pivot td.col-total, table.pivot th.col-total { background: rgba(14, 111, 168, .06); font-weight: 600; }

/* -------------------------------------------------------------- sheets --- */

.sheet {
  border: 0;
  border-radius: 10px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 88vh;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5);
}

.sheet::backdrop { background: rgba(19, 26, 33, .5); }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--rule);
}

.sheet-head h3 {
  font: 600 18px/1 var(--cond);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 0;
}

.sheet-head .spacer { flex: 1; }
.sheet-body { padding: 18px; overflow: auto; max-height: calc(88vh - 130px); }

.sheet-foot {
  display: flex;
  gap: 10px;
  padding: 13px 18px;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.sheet-foot .spacer { flex: 1; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; }
.kv dd { margin: 0; }
.kv dd.mono { font-family: var(--mono); }

/* -------------------------------------------------------------- toasts --- */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--ink);
  color: #eef2f6;
  border-radius: 7px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--flame-lift);
  max-width: 380px;
  animation: rise .18s ease-out;
}

.toast.err { border-left-color: #e06060; }
.toast.ok { border-left-color: #3fb37f; }

@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.spin {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--rule);
  border-top-color: var(--flame);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading { padding: 40px; text-align: center; color: var(--text-2); }

/* ------------------------------------------------------------ narrower --- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }

  .rail {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .rail-mark { border-bottom: 0; border-right: 1px solid #26323d; padding: 12px 14px; }
  .rail-mark span { display: none; }
  .rail-nav { display: flex; gap: 4px; padding: 8px; margin: 0; }
  .rail-nav button { white-space: nowrap; }
  .rail-foot { border-top: 0; padding: 8px 10px; }
  .rail-user { width: auto; }
  .topbar { flex-wrap: wrap; }
  .topbar-gauge { width: 100%; margin-left: 0; justify-content: space-between; gap: 10px; }
  .view { padding: 14px; }
  .grid-wrap { max-height: none; }
  .field.wide { grid-column: span 1; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .rail, .topbar, .toolbar, .grid-foot, .toasts, .report-controls { display: none !important; }
  .view { padding: 0; }
  .card { border: 0; box-shadow: none; }
  .grid-wrap { max-height: none; overflow: visible; }
  table.pivot thead th, table.grid thead th { background: #eee !important; color: #000 !important; }
}


/* =========================================================== density ===== */
/* Three sizes for the data tables. "Compact" trades whitespace for rows on
   screen; the controls stay full size so they remain easy to hit. */

body.density-compact table.grid tbody td { padding: 4px 8px; font-size: 12.5px; }
body.density-compact table.grid thead th { padding: 6px 8px; font-size: 10px; }
body.density-compact table.grid tr.filters th { padding: 3px 4px; }
body.density-compact table.grid tr.filters input,
body.density-compact table.grid tr.filters select { padding: 3px 5px; font-size: 11.5px; }
body.density-compact table.grid tfoot td { padding: 7px 8px; font-size: 12px; }
body.density-compact table.grid tr.filters th { top: 26px; }
body.density-compact table.pivot th,
body.density-compact table.pivot td { padding: 4px 7px; font-size: 12px; }
body.density-compact .grid-wrap { max-height: calc(100vh - 250px); }
body.density-compact .chip { padding: 2px 5px; font-size: 9.5px; }

body.density-tight table.grid tbody td { padding: 2px 6px; font-size: 12px; }
body.density-tight table.grid thead th { padding: 4px 6px; font-size: 9.5px; letter-spacing: .06em; }
body.density-tight table.grid tr.filters th { padding: 2px 3px; }
body.density-tight table.grid tr.filters input,
body.density-tight table.grid tr.filters select { padding: 2px 4px; font-size: 11px; }
body.density-tight table.grid tfoot td { padding: 5px 6px; font-size: 11.5px; }
body.density-tight table.grid tr.filters th { top: 22px; }
body.density-tight table.pivot th,
body.density-tight table.pivot td { padding: 3px 6px; font-size: 11.5px; }
body.density-tight .grid-wrap { max-height: calc(100vh - 220px); }
body.density-tight .chip { padding: 2px 4px; font-size: 9px; }
body.density-tight .card-body { padding: 12px; }

/* ====================================================== batch actions ==== */

.batch {
  position: relative;
  display: inline-flex;
}

.batch-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--flame);
  border: 1px solid var(--flame);
  color: #fff;
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.batch-trigger:hover { background: var(--flame-lift); border-color: var(--flame-lift); }
.batch-trigger .caret { font-size: 10px; opacity: .85; }

.batch-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 60;
  min-width: 290px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.batch-menu[hidden] { display: none !important; }

.batch-menu .batch-head {
  padding: 8px 10px 6px;
  font: 600 10px/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.batch-menu button {
  width: 100%;
  display: block;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13.5px;
}

.batch-menu button:hover { background: var(--flame-wash); }
.batch-menu button strong { display: block; font-weight: 600; }

.batch-menu button .why {
  display: block;
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
  line-height: 1.4;
}

.batch-menu button.danger strong { color: var(--alarm); }
.batch-menu button.danger:hover { background: #fdecec; }
.batch-menu .sep { border-top: 1px solid var(--rule-soft); margin: 5px 4px; }

/* The density picker sits with the table it resizes. */
.density-pick { display: flex; align-items: center; gap: 6px; }

.density-pick > span {
  font: 600 10px/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.density-pick select {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 7px;
  font-size: 12.5px;
  background: var(--paper-2);
}

/* ================================================= top bar page header === */

.topbar-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding-right: 4px;
  margin-right: 2px;
  border-right: 1px solid var(--rule);
  padding-right: 16px;
}

.topbar-title .eyebrow { line-height: 1; }

.topbar-title h1 {
  margin: 0;
  font: 600 21px/1 var(--cond);
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.topbar-title:empty,
.topbar-title[hidden] { display: none; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-actions:empty { display: none; }

@media (max-width: 1100px) {
  .topbar-title { border-right: 0; padding-right: 0; }
  .topbar-title h1 { font-size: 18px; }
}


/* The column chooser drops down rather than up, since it lives in the toolbar. */
.cols-picker .batch-menu {
  bottom: auto;
  top: calc(100% + 6px);
  left: auto;
  right: 0;          /* it sits near the right edge, so it opens inwards */
  min-width: 250px;
  max-height: 60vh;
  overflow-y: auto;
}

.cols-menu .cols-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.cols-menu .cols-row:hover { background: var(--flame-wash); }
.cols-picker .caret { font-size: 10px; color: var(--text-3); }


/* Required-field marker. */
.field .req,
.required-note .req {
  color: var(--alarm);
  font-weight: 700;
}

.required-note { color: var(--text-2); font-size: 12px; }

/* The per-row edit button, so the way in is visible rather than guessed at. */
td .row-edit {
  padding: 3px 9px;
  font-size: 12px;
  white-space: nowrap;
}


/* ==================================================== selection bar ====== */
/* Sits above the table so the actions are in view the moment rows are ticked,
   rather than at the foot of a long list. */

.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 12px;
  background: var(--flame-wash);
  border-bottom: 1px solid var(--flame);
  position: sticky;
  top: 0;
  z-index: 20;
}

.selection-bar[hidden] { display: none !important; }
.selection-bar .rowcount,
.selection-bar strong { color: var(--flame); }

/* The batch menu drops down from a bar at the top. */
.selection-bar .batch-menu {
  bottom: auto;
  top: calc(100% + 6px);
}

/* ==================================================== pinned columns ===== */
/* The row's own controls stay against the left edge, so they are reachable no
   matter how far the table is scrolled sideways. */

table.grid th.col-pin,
table.grid td.col-pin {
  position: sticky;
  z-index: 3;
}

table.grid thead th.col-pin { z-index: 6; background: var(--ink-2); }
table.grid tr.filters th.col-pin { z-index: 5; background: var(--band); }

/* Sticky cells need their own background or the scrolled content shows through. */
table.grid tbody td.col-pin { background: var(--paper-2); }
table.grid tbody tr:nth-child(even) td.col-pin { background: #fbfaf7; }
table.grid tbody tr:hover td.col-pin { background: var(--flame-wash); }
table.grid tbody tr.selected td.col-pin { background: #dceaf5; }

table.grid td.col-pin::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 1px;
  background: var(--rule-soft);
}

table.grid tfoot td.col-pin { background: var(--ink-2); }

/* A check-box dropdown, for filters that accept more than one answer. */
.check-picker .batch-menu {
  bottom: auto;
  top: calc(100% + 6px);
  min-width: 250px;
  max-height: 60vh;
  overflow-y: auto;
}

.check-picker .pick-label {
  font: 600 10px/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-right: 2px;
}

.check-picker .caret { font-size: 10px; color: var(--text-3); }

.check-picker .btn.active {
  border-color: var(--flame);
  background: var(--flame-wash);
  color: var(--flame);
}

.check-picker .btn.active .pick-label { color: var(--flame); }

/* View controls sit to the right of the search and filters. */
.toolbar .view-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============================================== choosing an entity ======= */
/* One tap picks the entity and moves on, so the first step never feels like a
   form to fill in. */

.entity-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.entity-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
}

.entity-choice:hover {
  border-color: var(--flame);
  background: var(--flame-wash);
}

.entity-choice-code {
  font: 700 19px/1 var(--mono);
  color: var(--flame);
  letter-spacing: -.02em;
}

.entity-choice-name { font-size: 13.5px; font-weight: 500; }

/* Which books the open dialog is writing to. */
.entity-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 16px;
  border-radius: 7px;
  background: var(--ink-2);
  color: #eef2f6;
  font-size: 13px;
}

.entity-banner .entity-choice-code { color: var(--flame-lift); font-size: 17px; }

/* Per-invoice payment details, sitting under each line of a payment run. */
.pay-line-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pay-line-field > span {
  font: 600 9.5px/1 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}

.pay-line-field input {
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 12.5px;
  background: var(--paper-2);
}

.pay-line-field input:focus { border-color: var(--flame); }

/* ================================================== receipt inbox ======== */

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.receipt-card {
  display: flex;
  gap: 11px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px;
  background: var(--paper);
}

.receipt-thumb {
  flex: 0 0 78px;
  width: 78px;
  height: 78px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--band);
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-soft);
}

.receipt-thumb img { width: 100%; height: 100%; object-fit: cover; }

.receipt-thumb-plain span {
  font: 600 11px/1 var(--sans);
  letter-spacing: .1em;
  color: var(--text-2);
}

.receipt-body { min-width: 0; flex: 1; }

/* The camera is the point of the Receipts screen, so it gets the whole width
   and a target big enough to hit without looking. */
.btn-capture {
  width: 100%;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  border-radius: 10px;
  font: 600 17px/1 var(--sans);
  letter-spacing: .01em;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
}

.btn-capture svg { width: 26px; height: 26px; }
.capture-card .card-body { padding: 16px; }

@media (max-width: 700px) {
  .btn-capture {
    padding: 26px 20px;
    font-size: 19px;
    border-radius: 12px;
  }

  .btn-capture svg { width: 32px; height: 32px; }
  .receipt-grid { grid-template-columns: 1fr; }

  /* Room for a thumb, and the card stays whole rather than splitting. */
  .receipt-card { padding: 12px; }
  .receipt-thumb { flex-basis: 92px; width: 92px; height: 92px; }
  .receipt-card .btn-sm { padding: 8px 12px; font-size: 13px; }
}

/* Where a read value came from, so a figure can be checked against the page. */
.read-source {
  display: block;
  margin-top: 3px;
  font: 400 11px/1.4 var(--mono);
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.read-source em { font-style: normal; color: var(--ember); font-weight: 600; }

.field.read-low input,
.field.read-low select {
  border-color: var(--ember);
  background: var(--ember-wash);
}

.read-dump {
  margin: 8px 0 0;
  padding: 11px 13px;
  max-height: 240px;
  overflow: auto;
  background: var(--ink-2);
  color: #dfe6ec;
  border-radius: 6px;
  font: 400 11.5px/1.55 var(--mono);
  white-space: pre-wrap;
}

/* The paperclip in a list row. */
.clip-cell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 0;
  background: none;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--flame);
  line-height: 1;
}

.clip-cell:hover { background: var(--flame-wash); }
.clip-cell span { font: 600 10.5px/1 var(--mono); }
