:root {
  color-scheme: light dark;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --text: #1c2126;
  --muted: #5b6570;
  --line: #d5dae0;
  --accent: #1f5f99;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --warning: #7a5200;
  --success: #1b6e3c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191d;
    --surface: #1f252b;
    --text: #e8ebee;
    --muted: #a3adb7;
    --line: #38414a;
    --accent: #6fb1ea;
    --accent-text: #10202e;
    --danger: #ffb4ab;
    --danger-bg: #3b1f1d;
    --warning: #f2c66d;
    --success: #7fd6a0;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, "Segoe UI", sans-serif;
}

header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

header a { color: inherit; text-decoration: none; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
a { color: var(--accent); }
.stack { display: grid; gap: 12px; max-width: 380px; }
label { display: grid; gap: 4px; color: var(--muted); }

input {
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

button {
  min-height: 40px;
  padding: 6px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#message { position: sticky; bottom: 0; min-height: 1.5em; margin-bottom: 0; padding: 4px 0; background: var(--bg); color: var(--muted); }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
select { min-height: 40px; width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
input { width: 100%; min-width: 0; }
input[type="checkbox"] { width: 18px; min-height: 18px; }
button:disabled { opacity: .5; cursor: default; }
kbd { padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font-size: .8em; }
.quick-form { margin-bottom: 16px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; margin-bottom: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.with-button { display: flex; gap: 6px; }
.with-button button { flex: none; width: 40px; padding: 0; }
.filters { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; color: var(--muted); }
.items-table td { white-space: normal; overflow-wrap: break-word; }
.items-table td.number, .items-table td button { white-space: nowrap; }
.items-table td:last-child { width: 1%; }
td.name { min-width: 220px; }
th.number, td.number { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); }
.batch-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 12px; margin-bottom: 10px; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.batch-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.batch-actions .spacer { flex: 1; }
.table-wrap { position: relative; }
.entry-table { min-width: 620px; }
.entry-table td { padding: 4px 6px; white-space: normal; vertical-align: top; }
.entry-table th { padding: 8px 6px; }
.entry-table .row-number { width: 40px; padding-top: 12px; color: var(--muted); text-align: right; }
.entry-table .cell-item { width: 50%; }
.entry-table .cell-qty { width: 130px; }
.entry-table .cell-location { width: 25%; }
.entry-table .unit { width: 44px; padding-top: 12px; color: var(--muted); }
.entry-table tr.has-error td { background: var(--danger-bg); }
.entry-table input.invalid { border: 2px solid var(--danger); }
.cell-error, .cell-warning { display: block; margin-top: 2px; font-size: .82rem; line-height: 1.3; }
.cell-error { color: var(--danger); }
.cell-warning { color: var(--warning); }
.remove-row { width: 32px; min-height: 40px; padding: 0; }
.mode-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.mode-tabs a { padding: 8px 14px; border-bottom: 3px solid transparent; color: var(--muted); text-decoration: none; }
.mode-tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.new-items-table { min-width: 1020px; }
.new-items-table .new-name { width: 28%; }
.new-items-table .new-item_type { width: 150px; }
.new-items-table .new-sku { width: 130px; }
.new-items-table .new-unit { width: 76px; }
.new-items-table .new-min_qty { width: 84px; }
.new-items-table select.invalid { border: 2px solid var(--danger); }
.count-table { min-width: 720px; }
.count-table .count-item { width: 46%; }
.count-table .count-counted { width: 150px; }
.count-table .current, .count-table .difference { padding-top: 12px; white-space: nowrap; }
.count-table input[readonly] { background: transparent; border-color: transparent; padding-left: 2px; }
.cell-name { display: block; margin-top: 2px; color: var(--muted); font-size: .82rem; line-height: 1.3; }
.diff-plus { color: var(--success); font-weight: 600; }
.diff-minus { color: var(--danger); font-weight: 600; }
.journal-filters { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.journal-table th, .journal-table td { padding: 8px 6px; }
.journal-table td.name { min-width: 150px; }
.journal-table td.note { min-width: 110px; }
.journal-table td.when { white-space: nowrap; }
.journal-table td:last-child { padding-right: 8px; }
.journal-table td button { padding: 6px 8px; }
.balance-hint { min-height: 1.4em; margin: 0 0 10px; color: var(--muted); }
.preview-panel { margin-top: 16px; }
.preview-panel .preview-name { min-width: 220px; white-space: normal; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr; }
  .items-table .optional { display: none; }
  .items-table th, .items-table td { padding: 8px 6px; }
  td.name { min-width: 120px; overflow-wrap: anywhere; }
  .journal-table th, .journal-table td { padding: 8px 4px; }
  .journal-table td.name { min-width: 70px; }
  .journal-table td.when { white-space: normal; min-width: 58px; }
}
#logout { margin-top: 16px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
.actions { display: flex; gap: 6px; }
.mac { width: 170px; }
