/* Склад — стилі. Спершу телефон (390 px), потім ширші екрани. */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --line: #dedbd3;
  --ink: #1d1f22;
  --ink-2: #4a4e55;
  --muted: #6b6f76;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #dfeae5;
  --bar: #3d7a68;
  --good: #2e7d4f;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --info: #2c5d8f;
  --info-soft: #e1ecf7;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c; --surface: #1f2227; --surface-2: #282c32; --line: #353a42;
    --ink: #eceae6; --ink-2: #c4c2bd; --muted: #9a9ea6;
    --accent: #7cc4ad; --accent-ink: #0f1f1a; --accent-soft: #23362f; --bar: #6fb39d;
    --good: #7fd19e; --warn: #f0b45a; --warn-soft: #3a2e17; --bad: #ff8a80; --bad-soft: #3d1f1d;
    --info: #8db9e8; --info-soft: #1c2b3b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181c; --surface: #1f2227; --surface-2: #282c32; --line: #353a42;
  --ink: #eceae6; --ink-2: #c4c2bd; --muted: #9a9ea6;
  --accent: #7cc4ad; --accent-ink: #0f1f1a; --accent-soft: #23362f; --bar: #6fb39d;
  --good: #7fd19e; --warn: #f0b45a; --warn-soft: #3a2e17; --bad: #ff8a80; --bad-soft: #3d1f1d;
  --info: #8db9e8; --info-soft: #1c2b3b;
  --shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 .25rem; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .6rem; }
h2.inline { display: inline; margin: 0; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn-text { color: var(--warn); }
.grow { flex: 1; min-width: 0; }
.pad { padding: .75rem; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: .5rem 1rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ——— каркас ——— */
#main { padding: 12px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; outline: none; }
.side { display: none; }
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a, .tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font: inherit; font-size: .72rem; background: none; border: 0; cursor: pointer; min-height: 44px;
}
.tabbar .on { color: var(--accent); font-weight: 600; }
.dot {
  font-style: normal; font-size: .68rem; font-weight: 700; line-height: 1; padding: 3px 5px; border-radius: 99px;
  background: var(--bad); color: #fff; margin-left: 4px;
}
.tabbar .dot { position: absolute; top: 6px; left: 55%; margin: 0; }

.sheet {
  border: 0; border-radius: 16px 16px 0 0; padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
  margin: auto 0 0 0; width: 100%; max-width: 100%; background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgb(0 0 0 / .35); }
.sheet nav { display: grid; }
.sheet a, .sheet button {
  display: flex; align-items: center; gap: 12px; padding: 14px 12px; min-height: 48px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font: inherit; background: none; border: 0; text-align: left; cursor: pointer;
}
.sheet a:hover, .sheet button:hover { background: var(--surface-2); }

@media (min-width: 900px) {
  body { display: grid; grid-template-columns: 220px 1fr; }
  .tabbar { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line);
  }
  .side nav { display: grid; gap: 2px; }
  .side a:not(.brand), .side .theme-btn {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2);
    text-decoration: none; min-height: 40px; justify-content: flex-start; width: 100%;
  }
  .side a.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
  .side a:not(.brand):hover { background: var(--surface-2); }
  .side .theme-btn { margin-top: auto; }
  .brand { font-weight: 800; font-size: 1.2rem; color: var(--ink); text-decoration: none; padding: 4px 10px 14px; display: flex; flex-direction: column; }
  .brand small { font-weight: 400; font-size: .78rem; color: var(--muted); }
  #main { padding: 24px 32px 48px; }
  h1 { font-size: 1.7rem; }
}

/* ——— сторінка ——— */
.page-head { margin-bottom: 14px; }
.back { display: inline-block; margin-bottom: 6px; text-decoration: none; font-size: .92rem; min-height: 32px; padding-top: 4px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); min-width: 0;
}
.card h2:first-child { margin-top: 0; }
details.card summary, details > summary { cursor: pointer; font-weight: 600; min-height: 32px; padding: 4px 0; }
.cols { display: grid; gap: 12px; }
@media (min-width: 760px) { .cols { grid-template-columns: 1fr 1fr; } }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.wrap, .wrap { flex-wrap: wrap; }
.gap-s { gap: 8px; }
.stack > * + * { margin-top: 10px; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.banner {
  display: block; padding: 12px 14px; margin-bottom: 12px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--ink); text-decoration: none; font-weight: 600;
}
.welcome { max-width: 560px; margin: 8vh auto 0; text-align: center; }
.welcome .btn { margin: 16px 0; }

/* ——— кнопки й поля ——— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn.icon { width: 48px; padding: 0; flex: none; }
.btn.wide { width: 100%; margin: 8px 0; }
.btn.big { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.file-btn { position: relative; }
.row.wrap .btn { white-space: normal; max-width: 100%; text-align: center; overflow-wrap: anywhere; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.check-line { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .span2 { grid-column: 1 / -1; } }
fieldset.chips { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
fieldset.chips legend { font-size: .85rem; color: var(--muted); margin-bottom: 6px; padding: 0; }
fieldset.chips label {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 99px; cursor: pointer;
}
fieldset.chips label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.chips-line { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: .85rem; padding: 6px 10px; min-height: 36px; border-radius: 99px;
  border: 1px dashed var(--line); background: transparent; color: var(--ink-2); cursor: pointer; text-align: left;
}

/* ——— фільтри й список ——— */
.filters { display: grid; gap: 8px; margin-bottom: 8px; }
.search-line { display: flex; gap: 8px; }
.search-line.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 900px) { .filter-row { grid-template-columns: repeat(4, 1fr); } }
.list-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; margin: 8px 0; }

.items { list-style: none; margin: 0 0 12px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.item-row { display: flex; align-items: center; gap: 8px; padding: 0 12px 0 4px; border-top: 1px solid var(--line); min-width: 0; }
.item-row:first-child { border-top: 0; }
.item-row.dim { opacity: .6; }
.item-row .check { display: flex; align-items: center; justify-content: center; width: 40px; min-height: 44px; flex: none; cursor: pointer; }
.item-main {
  flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 2px;
  padding: 10px 0 10px 8px; color: var(--ink); text-decoration: none;
}
.item-row:not(:has(.check)) .item-main { padding-left: 8px; }
.item-inv { grid-row: span 3; font-variant-numeric: tabular-nums; font-weight: 700; font-size: .9rem; color: var(--ink-2); min-width: 2.6em; padding-top: 1px; }
.item-inv.big { font-size: 1.05rem; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.item-meta { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.item-meta b { color: var(--ink-2); font-weight: 600; }
.item-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.item-badges:empty { display: none; }
.item-cost { flex: none; text-align: right; font-variant-numeric: tabular-nums; font-size: .88rem; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2);
}
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--accent-soft); color: var(--good); }

.bulk {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--tab-h) + 8px + env(safe-area-inset-bottom)); z-index: 15;
  display: none; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px;
  background: var(--ink); color: var(--bg); border-radius: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}
.bulk.on { display: flex; }
.bulk > span { margin-right: auto; }
.bulk .btn { background: transparent; color: var(--bg); border-color: rgb(255 255 255 / .3); }
.bulk .btn.ghost { border-color: transparent; }
@media (min-width: 900px) { .bulk { left: 252px; right: 32px; bottom: 16px; max-width: 1040px; } }

/* ——— плитки й «увага» ——— */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; min-width: 0;
}
.tile-label { font-size: .8rem; color: var(--muted); }
.tile-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-sub { font-size: .78rem; color: var(--muted); }

.att { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.att a {
  display: grid; grid-template-columns: 3.2em 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; min-height: 52px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
.att a:hover { border-color: var(--accent); }
.att-n { font-size: 1.2rem; font-weight: 700; text-align: center; color: var(--warn); font-variant-numeric: tabular-nums; }
.att li.ok .att-n { color: var(--good); }
.att b { display: block; }
.att small { color: var(--muted); }
.att-sum { font-size: .88rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.bars-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 10px; margin-bottom: 12px; min-width: 0; }
.bars { list-style: none; margin: 0; padding: 0; }
.bars a {
  display: grid; grid-template-columns: minmax(0, 9em) 1fr auto; align-items: center; gap: 10px;
  padding: 7px 0; min-height: 40px; color: var(--ink); text-decoration: none;
}
.bars a:hover .bar-fill { filter: brightness(1.12); }
.bar-name { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar-val { font-size: .85rem; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-val small { display: block; color: var(--muted); font-size: .74rem; }

/* ——— люди / місця ——— */
.holders { list-style: none; margin: 0 0 12px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.holders li + li { border-top: 1px solid var(--line); }
.holders a {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "n s" "m s"; gap: 0 12px;
  padding: 10px 14px; min-height: 52px; color: var(--ink); text-decoration: none;
}
.holders a:hover { background: var(--surface-2); }
.h-name { grid-area: n; font-weight: 600; overflow-wrap: anywhere; }
.h-meta { grid-area: m; font-size: .85rem; color: var(--muted); }
.h-sum { grid-area: s; align-self: center; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ——— картка предмета ——— */
.item-head-meta { color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.where { display: grid; gap: 12px; }
.where-val { font-size: 1.15rem; font-weight: 700; margin: 2px 0; overflow-wrap: anywhere; }
.where .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.where .actions .primary { grid-column: 1 / -1; }
@media (min-width: 760px) {
  .where { grid-template-columns: 1fr auto; align-items: center; }
  .where .actions { display: flex; }
}
.facts { display: grid; grid-template-columns: 1fr; margin: 0 0 8px; }
.fact { display: grid; grid-template-columns: 11em 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.fact:first-child { border-top: 0; }
.fact dt { color: var(--muted); font-size: .88rem; }
.fact dd { margin: 0; overflow-wrap: anywhere; }
.qr-card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.qr-big { width: 160px; height: 160px; padding: 8px; background: #fff; border-radius: 8px; }
.qr-big svg { width: 100%; height: 100%; display: block; }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { display: grid; grid-template-columns: 8.5em 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.timeline time { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sig-thumb { display: block; max-width: 180px; max-height: 54px; margin-top: 4px; background: #fff; border-radius: 4px; }

/* ——— обхід ——— */
.progress { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.progress span { display: block; height: 100%; background: var(--accent); }
.plan { margin: 0; padding-left: 1.2em; }

/* ——— вхідні, довідник ——— */
.notes, .dict { list-style: none; padding: 0; margin: 0; }
.note-card.dim { opacity: .6; }
.dict-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dict-raw, .dict-row .btn { grid-column: 1 / -1; }
.dict-raw { display: flex; flex-direction: column; overflow-wrap: anywhere; }
.dict-raw small { color: var(--muted); }
@media (min-width: 900px) {
  .dict-row { grid-template-columns: 1.3fr 1fr 1fr auto auto; align-items: end; }
  .dict-raw, .dict-row .btn { grid-column: auto; }
}
.ok-box { padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.bad-box { padding: 12px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); }

/* ——— діалоги ——— */
.modal {
  border: 0; border-radius: 16px; padding: 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
.modal.wide { width: min(720px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(0 0 0 / .4); }
.modal h2 { margin-top: 0; }
.sigpad { width: 100%; height: 120px; background: #fff; border: 1px dashed var(--line); border-radius: 10px; touch-action: none; }
.scan-view { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18%; border: 3px solid rgb(255 255 255 / .85); border-radius: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 100; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-weight: 600; transition: opacity .3s;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ——— таблиці (Розподіл) ——— */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin: 0 0 12px; }
.tbl { border-collapse: collapse; width: 100%; font-size: .9rem; }
.tbl th, .tbl td { padding: 8px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl thead th { border-top: 0; background: var(--surface-2); font-size: .8rem; color: var(--ink-2); white-space: nowrap; position: sticky; top: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td small { color: var(--muted); }
.tbl td:first-child { min-width: 9em; }
.tbl td:first-child a { font-weight: 600; }
.tbl .rule { min-width: 16em; color: var(--ink-2); font-size: .82rem; }
@media (max-width: 700px) {
  .tbl-wrap:has(.tbl.stack) { border: 0; background: none; overflow: visible; }
  .tbl.stack thead { display: none; }
  .tbl.stack, .tbl.stack tbody { display: block; }
  .tbl.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px; margin-bottom: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  .tbl.stack td { border: 0; padding: 2px 0; min-width: 0; text-align: left; white-space: normal; }
  .tbl.stack td:first-child, .tbl.stack td.rule { grid-column: 1 / -1; }
  .tbl.stack td:first-child { font-size: 1rem; }
  .tbl.stack td[data-l]::before { content: attr(data-l); display: block; font-size: .74rem; color: var(--muted); font-weight: 400; }
}
.banner code, .tbl code { font-size: .85em; overflow-wrap: anywhere; }
h3 { font-size: .98rem; margin: 1rem 0 .5rem; }
.proposal { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.proposal:first-of-type { border-top: 0; }
.merge-list { margin: 6px 0 0; padding-left: 1.1em; max-height: 320px; overflow: auto; overflow-wrap: anywhere; }
.counts { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.counts td, .counts th { padding: 3px 10px 3px 0; text-align: left; }

/* ——— документи й етикетки ——— */
.print-view { position: fixed; inset: 0; z-index: 50; overflow: auto; background: var(--surface-2); }
.print-bar { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.print-page { background: #fff; color: #000; margin: 16px auto; padding: 16px; max-width: 1050px; box-shadow: var(--shadow); overflow-x: auto; }
.doc { font: 12px/1.4 "Times New Roman", Times, serif; }
.doc h1 { font-size: 16px; text-align: center; margin: 8px 0; }
.doc h2 { font-size: 13px; }
.doc-org { font-size: 12px; }
.doc-sub { text-align: center; }
.doc-note { font-size: 11px; }
.doc-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.doc-table th, .doc-table td { border: 1px solid #000; padding: 3px 4px; vertical-align: top; }
.doc-table th { font-weight: 600; text-align: center; }
.doc-table .num { text-align: right; white-space: nowrap; }
.doc-table tfoot td { font-weight: 700; }
.doc-signs { display: grid; gap: 10px; margin: 14px 0; }
.sign { display: grid; grid-template-columns: 14em 12em 1fr; gap: 10px; align-items: end; }
.sign .line { border-bottom: 1px solid #000; min-height: 24px; display: flex; align-items: end; }
.sign .line img { max-height: 40px; }
.sign .who { font-style: italic; }
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(62mm, 1fr)); gap: 3mm; }
.label { display: flex; gap: 3mm; align-items: center; border: 1px dashed #999; padding: 2.5mm; break-inside: avoid; color: #000; }
.label-qr { width: 22mm; height: 22mm; flex: none; }
.label-qr svg { width: 100%; height: 100%; display: block; }
.label-text { display: flex; flex-direction: column; font: 9pt/1.2 -apple-system, Arial, sans-serif; min-width: 0; }
.label-text b { font-size: 12pt; }
.label-text span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.label-text small { color: #555; font-size: 7pt; }

/* ——— голосовий помічник ——— */
:root { --ai-1: #2f5d50; --ai-2: #3b6fb0; --ai-3: #8a5cc2; --ai-glow: rgb(59 111 176 / .18); }
:root[data-theme="dark"] { --ai-1: #7cc4ad; --ai-2: #8db9e8; --ai-3: #c3a3f0; --ai-glow: rgb(141 185 232 / .16); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ai-1: #7cc4ad; --ai-2: #8db9e8; --ai-3: #c3a3f0; --ai-glow: rgb(141 185 232 / .16); } }
@property --ai-angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

.ai { display: grid; gap: 8px; min-width: 0; }
.ai[hidden] { display: none; }
.ai-thread { display: flex; flex-direction: column; gap: 6px; }
.ai-thread:empty { display: none; }
.ai-bubble {
  max-width: 88%; padding: 9px 13px; border-radius: 16px; font-size: .95rem; line-height: 1.35; overflow-wrap: anywhere;
  animation: ai-pop .22s cubic-bezier(.2, .9, .3, 1.2) both;
}
.ai-bubble.me { align-self: flex-end; background: var(--surface-2); color: var(--ink-2); border-bottom-right-radius: 5px; }
.ai-bubble.bot {
  align-self: flex-start; color: var(--ink); font-weight: 600; border-bottom-left-radius: 5px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--ai-1) 16%, var(--surface)), color-mix(in srgb, var(--ai-3) 14%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--ai-2) 30%, transparent);
}
.ai-composer {
  position: relative; display: flex; align-items: center; gap: 4px; padding: 4px; min-width: 0;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  transition: box-shadow .25s, border-color .25s;
}
.ai-composer:focus-within { border-color: var(--ai-2); box-shadow: 0 0 0 4px var(--ai-glow); }
.ai[data-mode="think"] .ai-composer, .ai[data-mode="listen"] .ai-composer {
  border-color: transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box,
    conic-gradient(from var(--ai-angle), var(--ai-1), var(--ai-2), var(--ai-3), var(--ai-1)) border-box;
  border: 2px solid transparent; animation: ai-spin 1.6s linear infinite; box-shadow: 0 0 0 5px var(--ai-glow);
}
.ai-input { flex: 1; border: 0; background: transparent; min-height: 44px; padding: 0 8px; border-radius: 999px; }
.ai-input:focus { outline: none; }
.ai-input.interim { color: var(--muted); font-style: italic; }
.ai-btn {
  flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; transition: background .2s, color .2s, transform .15s;
}
.ai-btn:hover { background: var(--surface-2); }
.ai-btn:active { transform: scale(.94); }
.ai-btn[hidden] { display: none; }
.ai-btn:focus-visible, .ai-voice:focus-visible, .ai-undo:focus-visible { outline: 2px solid var(--ai-2); outline-offset: 2px; }
.ai-mic { background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); color: #fff; }
.ai-mic:hover { background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); filter: brightness(1.08); }
:root[data-theme="dark"] .ai-mic { color: #0f1f1a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ai-mic { color: #0f1f1a; } }
.ai-mic.on { animation: ai-pulse 1.3s ease-out infinite; background: var(--bad); color: #fff; }
.ai-send[disabled] { opacity: .4; cursor: default; }
.ai-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; padding: 0 6px; }
.ai-status { font-size: .82rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.ai-status.good { color: var(--good); }
.ai-status.warn { color: var(--warn); }
.ai-status.bad { color: var(--bad); }
.ai[data-mode="think"] .ai-status {
  background: linear-gradient(90deg, var(--muted) 30%, var(--ai-2) 50%, var(--muted) 70%) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: ai-shimmer 1.4s linear infinite;
}
.ai-voice {
  flex: none; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 8px; border-radius: 99px;
  border: 1px solid transparent; background: transparent; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer;
}
.ai-voice svg { width: 16px; height: 16px; }
.ai-voice[aria-pressed="true"] { color: var(--ai-2); border-color: color-mix(in srgb, var(--ai-2) 40%, transparent); }
.ai-voice[hidden] { display: none; }

/* поле, яке заповнив помічник */
.ai-filled > input, .ai-filled > select, .ai-filled > textarea {
  border-color: var(--ai-2); background: color-mix(in srgb, var(--ai-2) 8%, var(--surface));
  animation: ai-flash .9s ease-out;
}
.ai-unsure > input, .ai-unsure > select, .ai-unsure > textarea { border-color: var(--warn); }
.ai-diff {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: .8rem; color: var(--muted);
  animation: ai-pop .25s ease-out both; min-width: 0;
}
.ai-diff s { opacity: .8; overflow-wrap: anywhere; }
.ai-diff b { color: var(--ai-2); overflow-wrap: anywhere; }
.ai-diff em { font-style: normal; color: var(--warn); font-weight: 600; }
.ai-undo {
  margin-left: auto; min-width: 32px; min-height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); font: inherit; cursor: pointer;
}
.btn.ai-open svg { color: var(--ai-2); }
.btn.ai-open[hidden] { display: none; }
.btn.ai-open.off { color: var(--muted); white-space: normal; flex-wrap: wrap; row-gap: 0; padding-block: 6px; }
.btn.ai-open.off svg { color: var(--muted); }
.btn.ai-open small { font-weight: 400; font-size: .8rem; flex-basis: 100%; text-align: center; }
.ai[data-mode="off"] .ai-composer { background: var(--surface-2); }
.where .actions .btn.ai-open { grid-column: 1 / -1; }
@media (min-width: 760px) { .where .actions { flex-wrap: wrap; justify-content: flex-end; } }
.ai-form .form-grid { margin-top: 4px; }
.dictate { position: relative; }
.dictate textarea { padding-right: 56px; }
.dictate .ai-mic { position: absolute; right: 6px; top: 6px; }

@keyframes ai-spin { to { --ai-angle: 360deg; } }
@keyframes ai-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 55%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
@keyframes ai-shimmer { to { background-position: -300% 0; } }
@keyframes ai-pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes ai-flash { 0% { box-shadow: 0 0 0 6px var(--ai-glow); } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) {
  .ai *, .ai-diff, .ai-filled > * { animation: none !important; transition: none !important; }
}

@media print {
  body.printing > *:not(.print-view) { display: none !important; }
  body.printing { display: block; background: #fff; }
  .print-view { position: static; overflow: visible; background: #fff; }
  .no-print { display: none !important; }
  .print-page { margin: 0; padding: 0; box-shadow: none; max-width: none; overflow: visible; }
  @page { size: A4 landscape; margin: 10mm; }
}

/* ——— вхід ——— */
.auth-body { display: block; }
.auth { max-width: 420px; margin: 0 auto; padding: 32px 16px; }
.auth-card h1 { margin: 0; }
.auth-card .field input { width: 100%; }
.qr-box { width: 200px; max-width: 100%; margin: 10px 0; background: #fff; padding: 6px; border-radius: 8px; }
.qr-box svg { display: block; width: 100%; height: auto; }
.secret { display: block; word-break: break-all; padding: 8px; background: var(--surface-2); border-radius: 6px; }
.bad-text { color: var(--bad, #b42318); min-height: 1.2em; margin: 0; }
.userbox { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .9em; }
.log-entry { border-top: 1px solid var(--line, #0001); padding: 10px 0; }
.log-entry:first-child { border-top: 0; }
.log-entry ul { margin: 6px 0 0; padding-left: 18px; }
.log-entry li { overflow-wrap: anywhere; }
