:root {
    --paper: #edf0ee;
    --surface: #ffffff;
    --ink: #16242a;
    --muted: #5c6b72;
    --line: #d5dcda;
    --teal: #0d6a63;
    --teal-d: #094b46;
    --blue: #2a4d7f;
    --kraft: #86683a;
    --slate: #4b5a62;
    --plum: #5e4070;
    --amber: #8a5a00;
    --amber-bg: #fbf0d9;
    --green: #17683a;
    --green-bg: #ddf1e4;
    --red: #b3261e;
    --red-bg: #fbe4e2;
    --radius: 8px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 16px/1.45 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
}
a { color: var(--teal); }
:focus-visible { outline: 3px solid #f2b84b; outline-offset: 2px; }
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 4px 0 28px; }
.muted { color: var(--muted); font-size: .85em; }
.block { display: block; }
.ico { width: 28px; height: 28px; flex: none; }

/* ---------- Верхня панель ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 56px; padding: 0 20px;
    background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand i { width: 18px; height: 18px; border-radius: 3px; background: var(--teal); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .28); }
.who { display: flex; align-items: center; gap: 16px; font-size: .9rem; text-align: right; }
.who small { display: block; color: #a9b8be; font-size: .75rem; line-height: 1.2; }
.who a { color: #fff; opacity: .85; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- Плитки дашборда ---------- */
.tile-group { margin-bottom: 32px; }
.tile-group h2 { color: var(--muted); font-weight: 500; font-size: .95rem; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile {
    position: relative; display: flex; flex-direction: column; gap: 6px;
    min-height: 150px; padding: 18px 18px 22px;
    border-radius: var(--radius); color: #fff; text-decoration: none;
    box-shadow: inset 0 -7px 0 rgba(0, 0, 0, .2);   /* «дошка піддона» знизу */
}
.tile .ico { width: 34px; height: 34px; margin-bottom: auto; }
.tile-title { font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.tile-text { font-size: .85rem; opacity: .88; }
a.tile:hover { filter: brightness(1.08); }
.g-move  { background: var(--teal); }
.g-stock { background: var(--kraft); }
.g-ref   { background: var(--slate); }
.g-admin { background: var(--plum); }
.tile.is-soon { background: transparent; color: var(--muted); border: 1.5px dashed #b6c0bd; box-shadow: none; }
.tile.is-soon .ico { color: var(--slate); }
.tile-soon { position: absolute; top: 14px; right: 14px; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: #dfe5e3; color: var(--muted); }

/* ---------- Картки, поля, кнопки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
input, select, textarea {
    width: 100%; height: 42px; padding: 0 12px;
    font: inherit; color: var(--ink);
    background: #fff; border: 1px solid #b9c4c1; border-radius: 6px;
}
input:disabled, select:disabled { background: #f0f3f2; color: #55656c; }
input:focus, select:focus { border-color: var(--teal); outline: 2px solid rgba(13, 106, 99, .25); outline-offset: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: 6px;
    font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--teal-d); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.12); }
.btn-ghost { background: #fff; color: var(--ink); border-color: #b9c4c1; }
.btn-ghost:hover:not(:disabled) { background: #f3f6f5; }
.btn-block { width: 100%; }
.btn-icon { width: 46px; padding: 0; }
.btn-icon .ico { width: 22px; height: 22px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .82rem; font-weight: 500; }
.badge-draft { background: var(--amber-bg); color: var(--amber); }
.badge-posted { background: var(--green-bg); color: var(--green); }
.alert { background: var(--red-bg); color: var(--red); border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; font-size: .92rem; }

/* ---------- Таблиці ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 720px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .82rem; font-weight: 500; color: var(--muted); background: #f6f8f7; }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { font-weight: 700; border-bottom: 0; background: #f6f8f7; }
.table tr.empty td { text-align: center; color: var(--muted); padding: 28px 14px; }
.cell { width: 100%; min-width: 70px; height: 34px; padding: 0 8px; }
.cell.num { width: 96px; text-align: right; }
.btn-del { width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--red); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.btn-del:hover { background: var(--red-bg); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { min-width: 180px; }

/* ---------- Накладна ---------- */
.doc { display: grid; grid-template-columns: 1fr 250px; gap: 16px; align-items: start; }
.doc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin-bottom: 0; }
.field-wide { grid-column: 1 / -1; }
.doc-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 0; }
.doc + .card, .doc + section { margin-top: 16px; }

.picker { position: relative; }
.picker-row { display: flex; gap: 8px; }
.results {
    position: absolute; left: 0; right: 54px; top: 46px; z-index: 10; list-style: none; margin: 0; padding: 4px;
    background: #fff; border: 1px solid #b9c4c1; border-radius: 6px; box-shadow: 0 8px 24px rgba(22, 36, 42, .18);
    max-height: 340px; overflow: auto;
}
.results li.empty { padding: 12px; color: var(--muted); }
.results button {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
    padding: 9px 10px; text-align: left; background: none; border: 0; border-radius: 4px; font: inherit; cursor: pointer;
}
.results button:hover, .results button:focus-visible { background: #eaf3f1; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); }
.entry { margin-top: 16px; padding: 14px; background: #eef6f5; border: 1px solid #bcd9d5; border-radius: var(--radius); }
.entry-name { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.entry-fields { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.entry-btns { display: flex; gap: 8px; }

/* ---------- Сканер, повідомлення ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(22, 36, 42, .72); }
.modal-box { width: 100%; max-width: 460px; background: #fff; border-radius: var(--radius); padding: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
#reader { width: 100%; min-height: 220px; background: #000; border-radius: 6px; overflow: hidden; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { padding: 11px 16px; border-radius: 6px; color: #fff; font-size: .92rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 420px; }
.toast-ok { background: var(--teal-d); }
.toast-err { background: var(--red); }

/* ---------- Сторінка входу ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art {
    display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; color: #fff;
    background:
        repeating-linear-gradient(to bottom, transparent 0 118px, rgba(255, 255, 255, .16) 118px 124px),
        repeating-linear-gradient(to right, transparent 0 158px, rgba(255, 255, 255, .07) 158px 160px),
        var(--teal-d);
}
.auth-art-title { margin: 0; font-size: 2.2rem; font-weight: 700; line-height: 1.15; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.auth-card .sub { margin: -8px 0 4px; }

/* ---------- Мобільні ---------- */
@media (max-width: 900px) {
    .doc { grid-template-columns: 1fr; }
    .doc-actions { flex-direction: row; flex-wrap: wrap; }
    .doc-actions .btn { flex: 1 1 200px; }
    .entry-fields { grid-template-columns: 1fr 1fr; }
    .entry-fields .field:first-child, .entry-btns { grid-column: 1 / -1; }
    .entry-btns .btn { flex: 1; }
    .auth { grid-template-columns: 1fr; }
    .auth-art { min-height: 150px; padding: 24px; }
    .auth-art-title { font-size: 1.5rem; }
}
@media (max-width: 560px) {
    .doc-fields { grid-template-columns: 1fr; }
    .container { padding: 16px 12px 80px; }
    .who span small { display: none; }
}
