/* Системные шрифты намеренно: внешний шрифт — это внешняя зависимость,
   которая однажды не загрузится, и экран с деньгами приедет без вёрстки. */
:root {
  --ground: #eef1f3;
  --surface: #fff;
  --surface-2: #e6ebee;
  --ink: #16202a;
  --ink-2: #3f4f5b;
  --muted: #536672;
  --on-accent: #fff;
  --line: #d5dee3;
  --line-2: #bcc9d1;
  --accent: #17614f;
  --accent-soft: #dcece7;
  --ok: #17614f;
  --ok-soft: #dcece7;
  --warn: #8a4a1c;
  --warn-soft: #f6e7db;
  --bad: #97302a;
  --bad-soft: #f7e2e0;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0e1418;
    --surface: #161e24;
    --surface-2: #1e272e;
    --ink: #e4ebef;
    --ink-2: #b2c0c9;
    --muted: #8296a3;
    /* акцент в тёмной теме светлый, поэтому текст на нём тёмный:
       белым по мятному получалось 2.35:1 — нечитаемо на всех главных кнопках */
    --on-accent: #0b1114;
    --line: #27323a;
    --line-2: #3a4650;
    --accent: #5fb99f;
    --accent-soft: #143029;
    --ok: #5fb99f;
    --ok-soft: #143029;
    --warn: #d08d5f;
    --warn-soft: #2c1f16;
    --bad: #e08079;
    --bad-soft: #2e1918;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 2rem 0 .7rem; }
h2:first-child { margin-top: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── каркас ─────────────────────────────────────────── */
header.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.bar { max-width: 76rem; margin: 0 auto; padding: 0 1.1rem; display: flex; align-items: center; gap: 1.4rem; }
.brand { font-weight: 700; letter-spacing: .02em; padding: .8rem 0; text-decoration: none; color: var(--ink); }
nav.menu { display: flex; flex-wrap: wrap; gap: .1rem; flex: 1; }
nav.menu a {
  padding: .8rem .7rem; text-decoration: none; color: var(--ink-2);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.menu a:hover { color: var(--ink); }
nav.menu a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.count {
  display: inline-block; min-width: 1.2em; text-align: center;
  background: var(--warn-soft); color: var(--warn);
  border-radius: 10px; padding: 0 .4em; font-size: .78rem; font-weight: 700; margin-left: .3em;
}
.who { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .6rem; }
main { max-width: 76rem; margin: 0 auto; padding: 1.4rem 1.1rem 5rem; }

/* ── полоса состояния данных ─────────────────────────── */
.freshness {
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  font-size: .82rem; color: var(--muted);
}
.freshness .bar { padding-top: .45rem; padding-bottom: .45rem; display: block; }
.freshness b { color: var(--ink-2); font-weight: 600; }
.freshness.stale { background: var(--warn-soft); color: var(--warn); }
.freshness.stale b { color: var(--warn); }

/* ── сообщения ──────────────────────────────────────── */
.flash, .note {
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--ink); border-radius: var(--radius);
  padding: .7rem .9rem; margin: 0 0 1.2rem;
  display: flex; gap: 1rem; align-items: center; justify-content: space-between;
}
.note.warn { background: var(--warn-soft); border-color: var(--warn); }
.note.bad { background: var(--bad-soft); border-color: var(--bad); }

/* ── главный экран ──────────────────────────────────── */
.headline {
  font-size: 1.35rem; line-height: 1.35; margin: 0 0 1.6rem;
  padding: 1.1rem 1.2rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  max-width: 46rem;
}
.headline.warn { border-left-color: var(--warn); }
.headline.bad { border-left-color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile { background: var(--surface); padding: 1rem 1.1rem; }
.tile .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font-size: 1.5rem; font-weight: 650; margin: .25rem 0 .15rem; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: .82rem; }
.tile.bad .v { color: var(--bad); }
.tile.warnv .v { color: var(--warn); }

/* ── кнопки ─────────────────────────────────────────── */
.btn, button, input[type=submit] {
  font: inherit; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: .5rem .95rem; text-decoration: none; display: inline-block;
}
.btn:hover, button:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600;
}
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); color: var(--on-accent); }
/* Палец на телефоне промахивается по всему, что ниже 44 px, а «выйти»
   стоит вплотную к меню — промах уводит с рабочего экрана. */
.btn.quiet { border-color: transparent; color: var(--muted);
  padding: .85rem .5rem; line-height: 1; }
.btn.big { font-size: 1.02rem; padding: .65rem 1.4rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1.2rem; }
form.inline { display: inline; }

/* Частичная выдача — редкий случай, поэтому спрятана за раскрывашкой.
   Поле ввода рядом с кнопкой «Выдано» — приглашение промахнуться. */
details.partial { margin-top: .6rem; }
details.partial > summary {
  cursor: pointer; color: var(--muted); font-size: .88rem;
  list-style: none; display: inline-block; padding: .8rem 0;
}
details.partial > summary::-webkit-details-marker { display: none; }
details.partial > summary::before { content: "▸ "; }
details.partial[open] > summary::before { content: "▾ "; }
details.partial > summary:hover { color: var(--ink); }
details.partial .inner { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
details.partial label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }

/* ── карточки выдач ─────────────────────────────────── */
.cards { display: flex; flex-direction: column; gap: .9rem; max-width: 46rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.card .name { font-size: 1.1rem; font-weight: 650; }
.card .amount { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card .meta { color: var(--muted); font-size: .88rem; margin-top: .3rem; }
.card .basis { color: var(--ink-2); font-size: .88rem; margin-top: .45rem;
  border-left: 2px solid var(--line-2); padding-left: .6rem; }

/* ── таблицы ────────────────────────────────────────── */
.tw { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 600; padding: .6rem .8rem;
  border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.neg { color: var(--bad); }
td a { text-decoration: none; }
td a:hover { text-decoration: underline; }
.total td { font-weight: 700; border-top: 1px solid var(--line-2); background: var(--surface-2); }

/* ── состояния ──────────────────────────────────────── */
.pill {
  display: inline-block; font-size: .74rem; font-weight: 600; white-space: nowrap;
  padding: .1rem .5rem; border-radius: 10px;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.said { color: var(--muted); font-size: .8rem; }

/* ── формы ──────────────────────────────────────────── */
.form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem; max-width: 34rem; }
.form.wide { max-width: 46rem; }
.field { margin-bottom: .95rem; }
.field > label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .25rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  font: inherit; width: 100%; padding: .5rem .6rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--radius);
}
textarea { min-height: 4rem; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 8rem; }
.calcbox {
  background: var(--surface-2); border-radius: var(--radius); padding: .8rem .95rem;
  font-variant-numeric: tabular-nums; line-height: 1.8;
}
.calcbox .k { color: var(--muted); display: inline-block; min-width: 11rem; }
.calcbox .v { font-weight: 650; }

/* ── текст сводки ───────────────────────────────────── */
.report {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 1.2rem 1.4rem; max-width: 44rem;
  font-size: 1.02rem; line-height: 1.7;
}
.report p { margin: 0 0 .35rem; }
.report p:empty { height: .7rem; }
.report .last { margin-top: .8rem; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sub { color: var(--muted); font-size: .88rem; margin: 0 0 1.4rem; }
.cols2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1.6rem; align-items: start; }
footer.bottom { max-width: 76rem; margin: 0 auto; padding: 1rem 1.1rem 2rem; color: var(--muted); font-size: .78rem; }
.empty { color: var(--muted); padding: 2rem 0; }

@media (max-width: 640px) {
  /* Палец не мышь: «Выдано» бухгалтер жмёт с телефона десятки раз в день,
     и промах по нему стоит дороже пары лишних пикселей. */
  .btn, button, input[type=submit] { padding: .68rem 1rem; }
  .btn.quiet { padding: .85rem .5rem; }
  .bar { flex-wrap: wrap; gap: .4rem 1rem; }
  nav.menu { order: 3; width: 100%; overflow-x: auto; }
  .tile .v { font-size: 1.3rem; }
  .headline { font-size: 1.15rem; }
}
