/* Vositachi - mobile-first, dense, numbers-forward. */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --fg: #0f172a;
  --fg-muted: #5b6b80;   /* 5.4:1 on white */
  --fg-faint: #64748b;   /* 4.8:1 on white - small text still has to pass AA */
  --border: #dbe3ec;
  --border-strong: #c3cfdd;
  --primary: #0f172a;
  --primary-fg: #ffffff;
  --accent: #1e6feb;
  --accent-soft: #e7f0ff;
  --debt: #b42318;
  --debt-soft: #fdeceb;
  --credit: #067647;
  --credit-soft: #e7f6ee;
  --warn: #b54708;
  --warn-soft: #fef4e6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 4px 16px rgba(15, 23, 42, .08);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1b2537;
    --fg: #eef2f8;
    --fg-muted: #a3b1c4;
    --fg-faint: #78899d;
    --border: #263248;
    --border-strong: #35435c;
    --primary: #eef2f8;
    --primary-fg: #0b1220;
    --accent: #5b9dff;
    --accent-soft: #14263f;
    --debt: #ff8a80;
    --debt-soft: #2c1917;
    --credit: #5fd3a0;
    --credit-soft: #12271e;
    --warn: #f0b26b;
    --warn-soft: #2a2013;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 6px 20px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

/* Any author `display` rule beats the UA's [hidden] { display: none }, and the
   conditional blocks below all carry a display-setting class. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  padding-bottom: 3rem;
}

.num, td.num, th.num, .money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-align: right;
  white-space: nowrap;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- layout ------------------------------------------------------------- */

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 12px; }

header.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.top-in {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--fg);
  font-size: 17px;
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--accent); }

nav.main {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
}
nav.main::-webkit-scrollbar { display: none; }

nav.main a {
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
}
nav.main a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
nav.main a.on { background: var(--primary); color: var(--primary-fg); }

main { padding-top: 16px; }

h1 { font-size: 21px; margin: 4px 0 14px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 22px 0 10px; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--fg-muted); font-weight: 600; }

.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mt { margin-top: 16px; }
.center { text-align: center; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.card > .card-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.card > .card-head h2, .card > .card-head h3 { margin: 0; }
.card > .card-head a:not(.btn) { display: inline-block; padding: 10px 4px; margin: -10px -4px; }
.card-body { padding: 14px; }

/* --- dashboard tiles ---------------------------------------------------- */

.ccy-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.ccy-head {
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); }
.tile {
  padding: 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.tile:nth-child(2n) { border-right: 0; }
.tile:nth-last-child(-n+2) { border-bottom: 0; }
.tile .label {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 5px;
  line-height: 1.3;
  min-height: 2.6em;
}
.tile .value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.tile .unit { font-size: 12px; font-weight: 500; color: var(--fg-faint); margin-left: 3px; }
.tile.neg .value { color: var(--debt); }
.tile.pos .value { color: var(--credit); }
.tile .hint { font-size: 11px; color: var(--fg-faint); margin-top: 4px; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile:nth-child(2n) { border-right: 1px solid var(--border); }
  .tile:nth-child(4n) { border-right: 0; }
  .tile:nth-last-child(-n+4) { border-bottom: 0; }
}

/* --- quick actions ------------------------------------------------------ */

.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
@media (min-width: 720px) { .quick { grid-template-columns: repeat(4, 1fr); } }

.quick a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
  box-shadow: var(--shadow);
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.quick a:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}
.quick a svg { width: 20px; height: 20px; stroke: var(--accent); }

/* --- tables ------------------------------------------------------------- */

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  font-weight: 600;
  padding: 9px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }

/* A 17px-tall text link is not tappable on a phone. Grow the hit area without
   moving anything: the negative margin cancels the padding. */
td a {
  display: inline-block;
  padding: 10px 4px;
  margin: -10px -4px;
}

/* A timestamp broken across two lines reads as two different values. */
td.stamp { white-space: nowrap; }

/* A table whose last column is a sentence: without a floor, the narrow
   viewport crushes that column to a sliver and every row grows ten lines tall
   with the rest of the row left blank. The wrapper scrolls instead. */
table.roomy { min-width: 780px; }
table.roomy td:last-child { min-width: 22rem; }
/* second line inside a cell: an address under a name, a note under a number */
.sub { display: block; font-size: 12px; color: var(--fg-faint); }

td.debt, .debt-t { color: var(--debt); font-weight: 600; }
td.credit, .credit-t { color: var(--credit); font-weight: 600; }

.empty { padding: 30px 14px; text-align: center; color: var(--fg-faint); }

/* --- pager -------------------------------------------------------------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.pager-count { color: var(--fg-muted); }
.pager-nav { display: flex; align-items: center; gap: 10px; }

/* --- badges ------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--fg-muted);
}
.badge.debt { background: var(--debt-soft); color: var(--debt); }
.badge.credit { background: var(--credit-soft); color: var(--credit); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* --- forms -------------------------------------------------------------- */

form.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--fg-muted); }
.field .help { font-size: 12px; color: var(--fg-faint); }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .grid2 { grid-template-columns: 1fr 1fr; } }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=file], input[type=search], select, textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  font-family: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  transition: border-color .15s, box-shadow .15s;
}
/* Safari gives a search field its own rounded chrome and its own height,
   which puts the label out of line with every other control in the row */
input[type=search] { -webkit-appearance: none; appearance: none; }
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input.money-in { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

input[type=checkbox] {
  width: 22px;
  height: 22px;
  min-height: 0;
  accent-color: var(--accent);
  flex: none;
  margin: 0;
}

/* label wrapping a checkbox - the whole thing is the tap target */
label.check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 2px;
  min-height: var(--tap);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
textarea { min-height: 72px; resize: vertical; }

.seg { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
/* visually hidden but still focusable and exposed to screen readers */
.seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  min-height: 0;
}
.seg label {
  flex: 1;
  text-align: center;
  padding: 11px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--surface);
  cursor: pointer;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  transition: background .15s, color .15s;
}
.seg label:last-of-type { border-right: 0; }
.seg input:checked + label { background: var(--primary); color: var(--primary-fg); }
.seg input:focus-visible + label { box-shadow: inset 0 0 0 3px var(--accent-soft); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  min-height: var(--tap);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary, button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover, button.primary:hover { background: #1559c4; border-color: #1559c4; }

.btn-danger { color: var(--debt); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--debt-soft); }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }

/* --- filters ------------------------------------------------------------ */

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}
.filters .field > label { font-size: 12px; }
/* the search box earns more room than a date input; on a phone the grid
   collapses to one column and this is a no-op */
.filters .field.grow { grid-column: span 2; }
@media (max-width: 640px) { .filters .field.grow { grid-column: span 1; } }

/* --- flash -------------------------------------------------------------- */

.flash { border-radius: var(--radius-sm); padding: 11px 14px; margin-bottom: 12px; font-size: 14px; font-weight: 500; }
.flash.ok { background: var(--credit-soft); color: var(--credit); }
.flash.error { background: var(--debt-soft); color: var(--debt); }

/* --- split rows --------------------------------------------------------- */

.split-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.split-row .kill { min-height: 40px; padding: 6px 10px; }

/* --- allocating an advance into a supplier bucket ----------------------- */

.alloc-open { display: flex; margin-top: 8px; }

.alloc-row > td { background: var(--surface-2); padding: 14px; }
tbody tr.alloc-row:hover > td { background: var(--surface-2); }

/* The row lives inside a table that may scroll sideways on a phone, so the
   panel is capped to what is actually on screen and never needs that scroll. */
.alloc-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: min(900px, calc(100vw - 56px));
}
.alloc-form .help { grid-column: 1 / -1; font-size: 12px; color: var(--fg-faint); margin-top: -4px; }
.alloc-actions { display: flex; gap: 8px; }
.alloc-actions button { flex: 1; }

@media (min-width: 720px) {
  .alloc-form { grid-template-columns: 1.3fr 1fr 1.3fr auto; align-items: end; }
  .alloc-actions button { flex: none; }
}

/* --- balance hint ------------------------------------------------------- */

.hintbox {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.hintbox:empty { display: none; }
.hintbox b { font-variant-numeric: tabular-nums; }

/* --- auth --------------------------------------------------------------- */

.auth { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.auth .card-body { padding: 22px; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--fg-muted); font-size: 14px; margin-bottom: 20px; }

/* --- misc --------------------------------------------------------------- */

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs a {
  display: block;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; font-weight: 600; }

.sep { height: 1px; background: var(--border); margin: 16px 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
