:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --border: #dcdad3;
  --text: #0b0b0b;
  --muted: #52514e;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --err-bg: #fbe4e4;
  --err: #a32121;
  --ok-bg: #e2f3ea;
  --ok: #17603f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e6e4de;
  --warn-bg: #fdf0dc;
  --warn: #8a4b00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #34332f;
    --text: #ffffff;
    --muted: #c3c2b7;
    --accent: #3987e5;
    --err-bg: #3b1d1d;
    --err: #ff9d9d;
    --ok-bg: #173226;
    --ok: #8fdcb4;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2a28;
    --warn-bg: #3a2a12;
    --warn: #ffc27a;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
header.top {
  display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .brand { font-weight: 700; margin-right: 8px; }
header.top nav { display: flex; flex-wrap: wrap; gap: 2px 4px; }
header.top nav a {
  padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted);
}
header.top nav a.on { background: var(--bg); color: var(--text); font-weight: 600; }
header.top .logout { margin-left: auto; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  margin-bottom: 14px;
}
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row > label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
textarea { width: 100%; min-height: 70px; }
button, .btn {
  cursor: pointer; display: inline-block; text-decoration: none; background: var(--accent);
  color: var(--accent-ink); border-color: var(--accent); font-weight: 600; white-space: nowrap;
}
button.ghost, .btn.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
button.danger { background: transparent; color: var(--err); border-color: var(--err); }
button.small, .btn.small { padding: 4px 8px; font-size: 13px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
table.data tbody tr:hover { background: var(--bg); }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); }
.pill.draft { color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
svg.chart { width: 100%; min-width: 560px; max-height: 320px; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .given { fill: var(--series-1); }
svg.chart .received { fill: var(--series-2); }
svg.chart rect.bar:hover { opacity: .8; }
.login { max-width: 360px; margin: 12vh auto; }
.login input { width: 100%; margin: 8px 0 12px; }

/* Форма накладної як на паперовому бланку */
.blank { max-width: 760px; }
.blank .fields { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; align-items: center; }
.blank .fields label { font-weight: 600; }
.blank table.sheet { width: 100%; border-collapse: collapse; margin-top: 14px; }
.blank table.sheet th, .blank table.sheet td { border: 1px solid var(--text); padding: 4px 6px; }
.blank table.sheet th { font-size: 12px; text-transform: uppercase; }
.blank table.sheet td input { width: 100%; min-width: 56px; border: 0; background: transparent; text-align: center; padding: 6px 2px; }
.blank table.sheet td.sum { font-size: 11px; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.photos figcaption { display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }
.combo { position: relative; }
.combo input { width: 100%; }
.combo .list {
  position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin-top: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow: auto;
}
.combo .list div { padding: 8px 10px; cursor: pointer; }
.combo .list div:hover, .combo .list div.active { background: var(--bg); }
.combo.ok input { border-color: var(--ok); }
@media (max-width: 560px) {
  .blank .fields { grid-template-columns: 1fr; }
  .tile .value { font-size: 22px; }
}

/* Звірка */
.st { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.st.overdue { background: var(--err-bg); color: var(--err); }
.st.surplus { background: var(--warn-bg); color: var(--warn); }
.st.in_laundry { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.st.returned { color: var(--ok); background: var(--ok-bg); }
.tile.alert .value { color: var(--err); }
.tile.warn .value { color: var(--warn); }
tr.issue td:first-child { box-shadow: inset 3px 0 0 var(--err); }
.legend-row { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.cellstack { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
