/* Інтерфейс у стилі lex.trade: Roboto, червоний акцент, «пігулки», без нативних контролів браузера */
:root {
  --ink: rgba(0, 0, 0, .8);
  --ink-strong: #111;
  --muted: #666;
  --muted-2: #999;
  --line: #e6e6e6;
  --line-input: #ccc;
  --soft: #f5f5f5;
  --soft-2: #f8f8f8;
  --accent: #ff0039;
  --accent-hover: #e60033;
  --accent-soft: #fff0f3;
  --accent-ring: rgba(255, 0, 57, .15);
  --ok: #2ab31b;
  --danger: #ee0000;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: #fff;
  color: var(--ink);
  font-family: 'Roboto', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; margin: 0; }
input, textarea, button { outline: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent); }
::selection { background: var(--accent-soft); }

/* ── Шапка ── */
.top { background: #fff; border-bottom: 1px solid #eee; position: sticky; top: 0; z-index: 30; }
.top-in { max-width: 1480px; margin: 0 auto; padding: 0 16px; height: 64px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: baseline; font-size: 28px; line-height: 1; letter-spacing: -1px; color: var(--ink-strong); white-space: nowrap; }
.brand:hover { color: var(--ink-strong); }
.brand b { font-weight: 700; color: var(--accent); }
.brand span { font-weight: 400; }
.menu { display: flex; gap: 22px; margin-left: auto; }
.menu a { color: var(--ink); font-size: 16px; line-height: 1.2; padding: 4px 0; border-bottom: 1px solid transparent; }
.menu a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.menu a.on { color: var(--accent); }

/* ── Контейнер і заголовки ── */
.container { max-width: 1480px; margin: 0 auto; padding: 0 16px; }
.page-h { text-align: center; color: var(--ink-strong); font-size: 36px; font-weight: 400; line-height: 1.2; margin: 30px 0 12px; }
.lead { text-align: center; font-size: 18px; max-width: 820px; margin: 0 auto 28px; }

/* Вкладки-«пігулки» */
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; padding: 0; list-style: none; }
.pills a, .pills button {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  color: #333; background: var(--soft); border-radius: 30px; font-size: 15px; line-height: 1.5; padding: 8px 16px; white-space: nowrap;
}
.pills a:hover, .pills button:hover { color: #111; background: #ececec; }
.pills a.on, .pills button.on { color: #fff; background: var(--accent); }
.pills svg { width: 15px; height: 15px; flex: none; }
.pills.sm a, .pills.sm button { font-size: 14px; padding: 5px 13px; }

/* ── Кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 9px 20px; border-radius: 30px; border: 1px solid var(--line-input);
  background: #fff; color: #111; font-weight: 500; font-size: 16px; line-height: 1.2; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: #111; }
.btn.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.main:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.sm { min-height: 34px; padding: 6px 14px; font-size: 14px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 14px; line-height: 1.5; border-bottom: 1px solid transparent; }
.link:hover { border-bottom-color: var(--accent); }
.link.danger { color: var(--danger); }
.link.danger:hover { border-bottom-color: var(--danger); }

/* ── Документ: форма + прев'ю ── */
.doc-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 36%); gap: 28px; align-items: start; padding-bottom: 60px; }
.ed-tools { display: flex; justify-content: flex-end; margin-top: -6px; }
.sec { text-align: left; font-size: 18px; font-weight: 500; color: var(--ink); line-height: 1.3; margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sec small { font-size: 14px; font-weight: 400; color: var(--muted); }
.sec:first-child { margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.f { display: flex; flex-direction: column; min-width: 0; grid-column: span 6; position: relative; }
.f.c3 { grid-column: span 3; } .f.c4 { grid-column: span 4; } .f.c5 { grid-column: span 5; } .f.c7 { grid-column: span 7; } .f.c8 { grid-column: span 8; }
.f.wide { grid-column: 1 / -1; }
.f > span { font-weight: 500; font-size: 15px; line-height: 1.5; margin-bottom: 4px; color: var(--ink); }
.f > span small { font-weight: 400; font-size: 14px; color: var(--muted); }

input[type="text"], input[type="search"], input[type="tel"], input[type="password"], input:not([type]), textarea {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; min-width: 0; height: 42px; padding: 8px 12px;
  background: #fff; border: 1px solid #ced4da; border-radius: 8px; box-shadow: none;
  font-size: 16px; line-height: 1.5; color: #212529;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; resize: vertical; min-height: 70px; }
input:focus, textarea:focus { border-color: #ff809c; box-shadow: 0 0 0 4px var(--accent-ring); }
input::placeholder, textarea::placeholder { color: #9aa0a6; opacity: 1; }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px #fff inset; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
input::-webkit-calendar-picker-indicator { display: none !important; }

/* Власний чекбокс */
.chk { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 15px; line-height: 1.5; user-select: none; }
.chk input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chk i { flex: none; width: 20px; height: 20px; margin-top: 1px; border: 1px solid #bbb; border-radius: 5px; background: #fff; display: grid; place-items: center; transition: background-color .15s, border-color .15s; }
.chk i::after { content: ''; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.chk input:checked + i { background: var(--accent); border-color: var(--accent); }
.chk input:checked + i::after { opacity: 1; }
.chk input:focus-visible + i { box-shadow: 0 0 0 4px var(--accent-ring); }

.fs-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.hint { font-size: 14px; color: var(--muted); line-height: 1.45; }
.hint.bad { color: var(--danger); }
.hint.good { color: var(--ok); }
.row-gap { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

/* Таблиця позицій */
.items { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.ih, .ir { display: grid; grid-template-columns: 26px minmax(0, 1fr) 70px 74px 96px 96px 28px; gap: 8px; align-items: center; padding: 8px 10px; }
.ih { background: var(--soft); font-size: 13px; font-weight: 500; color: #555; line-height: 1.3; }
.ir { border-top: 1px solid var(--line); }
.ir input { height: 38px; padding: 6px 10px; font-size: 15px; }
.ir .n { color: var(--muted-2); font-size: 13px; text-align: center; }
.ir .sum { text-align: right; font-weight: 500; font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.x { width: 28px; height: 28px; border: 0; background: none; color: #aaa; cursor: pointer; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.x:hover { color: var(--danger); background: var(--accent-soft); }
.x svg { width: 14px; height: 14px; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: #555; margin: 4px 0 12px; }
.totals b { font-weight: 600; color: #111; }

/* Рядки вантажу ТТН */
.cargo-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin-bottom: 10px; }
.cc-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; color: #555; font-weight: 500; }

/* Прев'ю */
.pv { position: sticky; top: 84px; background: var(--soft); border-radius: var(--radius); padding: 16px; }
.pv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pv-actions .btn.main { flex: 1 1 auto; }
.pv-box { position: relative; overflow: hidden; }
.sheets { display: flex; flex-direction: column; gap: 12px; transform-origin: top left; width: max-content; }
.sheets .page { box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.pv-tip { margin-top: 12px; font-size: 13px; color: #777; line-height: 1.45; }
.pv-meta { display: flex; justify-content: space-between; font-size: 13px; color: #777; margin-bottom: 8px; }

/* Вхід */
.auth { max-width: 460px; margin: 0 auto 60px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.auth-tabs { margin-bottom: 4px; }
.auth-submit { width: 100%; margin-top: 4px; }
.acc { max-width: 560px; padding: 24px; margin: 0 auto 24px; }
.acc h2 { font-size: 20px; font-weight: 500; color: #111; margin: 0 0 12px; }
.acc .grid { margin-bottom: 14px; }

/* Архів і довідники */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { max-width: 320px; }
.toolbar .pills { margin: 0; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
table.tbl th { text-align: left; font-weight: 500; font-size: 14px; color: #555; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--soft-2); }
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.45; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: #fcfcfc; }
table.tbl td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.tbl td.acts { white-space: nowrap; text-align: right; }
table.tbl td.acts .link { margin-left: 14px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 30px; font-size: 13px; font-weight: 500; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.empty-state { padding: 48px 20px; text-align: center; color: #888; }

.refs { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; padding-bottom: 20px; }
.ref-nav { display: flex; flex-direction: column; gap: 4px; }
.ref-nav button { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 9px 16px; border: 0; background: var(--soft); border-radius: 30px; cursor: pointer; color: #333; font-size: 15px; }
.ref-nav button:hover { background: #ececec; }
.ref-nav button.on { background: var(--accent); color: #fff; }
.ref-nav .cnt { font-size: 13px; opacity: .75; }
.ref-main { padding: 20px; }
.ref-main h2 { font-size: 22px; font-weight: 400; color: #111; margin: 0 0 14px; line-height: 1.2; }
.ref-form { padding: 16px; background: var(--soft-2); border-radius: 10px; margin-bottom: 18px; }
.ref-form .fs-foot { justify-content: flex-start; margin-top: 14px; }
.backup { margin: 10px 0 60px; padding: 24px 28px; border-radius: var(--radius); background: #2c2c2c; color: #ddd; }
.backup h2 { font-size: 20px; font-weight: 500; color: #fff; margin: 0 0 6px; }
.backup p { color: #bbb; font-size: 15px; margin: 0 0 14px; }
.backup .chk { color: #ddd; }
.backup .chk i { border-color: #777; background: transparent; }
.backup .row-gap { margin: 16px 0 0; }
.backup .btn { background: transparent; color: #fff; border-color: #666; }
.backup .btn:hover { border-color: #fff; }
.backup .btn.danger { color: #ff7a8f; }

/* Автодоповнення (замість нативного datalist) */
.ac {
  position: absolute; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .12); padding: 4px; max-height: 300px; overflow-y: auto; min-width: 220px;
}
.ac-i { display: flex; flex-direction: column; padding: 7px 12px; border-radius: 7px; cursor: pointer; line-height: 1.35; }
.ac-i b { font-weight: 400; font-size: 15px; color: #111; }
.ac-i small { font-size: 13px; color: #888; }
.ac-i.on, .ac-i:hover { background: var(--accent-soft); }
.ac-i mark { background: none; color: var(--accent); font-weight: 500; }

/* Модальне вікно (замість confirm) */
.modal-bg { position: fixed; inset: 0; z-index: 80; background: rgba(17, 17, 17, .45); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; max-width: 440px; width: 100%; padding: 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal h3 { margin: 0 0 8px; font-size: 20px; font-weight: 500; color: #111; line-height: 1.3; }
.modal p { margin: 0 0 20px; color: #555; font-size: 15px; white-space: pre-line; }
.modal .acts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }

/* Сповіщення */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #2c2c2c; color: #fff; padding: 11px 20px; border-radius: 30px; font-size: 15px; z-index: 90;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Футер */
.foot { border-top: 1px solid #eee; background: var(--soft-2); color: #888; font-size: 14px; padding: 22px 0; }

/* ── Адаптивність ── */
@media (max-width: 991px) {
  .doc-view { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .pv { position: static; margin-top: 16px; }
  .menu { gap: 16px; }
}
@media (max-width: 767px) {
  .top-in { height: 56px; gap: 12px; }
  .brand { font-size: 24px; }
  .menu { gap: 14px; }
  .menu a { font-size: 15px; }
  .page-h { font-size: 24px; margin: 22px 0 10px; }
  .lead { font-size: 16px; text-align: left; margin-bottom: 20px; }
  .f, .f.c3, .f.c4, .f.c5, .f.c7, .f.c8 { grid-column: span 12; }
  .f.half { grid-column: span 6; }
  .ih { display: none; }
  .ir { grid-template-columns: 1fr 1fr 1fr 28px; grid-template-areas: "name name name x" "unit qty price price" "sum sum sum sum"; }
  .ir .n { display: none; }
  .ir > :nth-child(2) { grid-area: name; }
  .ir > :nth-child(3) { grid-area: unit; }
  .ir > :nth-child(4) { grid-area: qty; }
  .ir > :nth-child(5) { grid-area: price; }
  .ir > :nth-child(6) { grid-area: sum; }
  .ir > :nth-child(7) { grid-area: x; }
  .refs { grid-template-columns: 1fr; }
  .ref-nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .ref-nav button { white-space: nowrap; gap: 8px; flex: none; }
  .ref-main { padding: 16px; }
  .backup { padding: 20px; }
  .pv-actions .btn { flex: 1 1 100%; }
}
@media (max-width: 420px) {
  .brand { font-size: 0; }
  .brand b { font-size: 24px; }
}

/* ── Друк: лише сторінки А4 ── */
@media print {
  html, body { background: #fff !important; }
  .top, .foot, .page-h, .lead, .pills, .editor, .pv-actions, .pv-tip, .pv-meta, .wide-view, .toast, .ac, .modal-bg { display: none !important; }
  .container { max-width: none; padding: 0; }
  .doc-view { display: block; padding: 0; }
  .pv { position: static; padding: 0; background: none; border-radius: 0; }
  .pv-box { overflow: visible; height: auto !important; }
  .sheets { display: block; transform: none !important; gap: 0; width: auto; }
  .sheets .page { box-shadow: none; margin: 0; page-break-after: always; break-after: page; }
  .sheets .page:last-child { page-break-after: auto; break-after: auto; }
}
