:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --graphite-900: #1e2329;
  --graphite-700: #3a424c;
  --graphite-500: #66707c;
  --graphite-300: #c4cad1;
  --graphite-200: #dfe3e7;
  --graphite-100: #eceef1;
  --blue: #123a86;
  --blue-dark: #0c2a63;
  --blue-soft: #e6ecf7;
  --green: #17693f;
  --green-soft: #e3f2ea;
  --red: #a32626;
  --red-soft: #f9e8e8;
  --amber: #8a5a00;
  --amber-soft: #fbf1dc;
  --radius: 6px;
  --shadow: 0 8px 28px rgb(30 35 41 / 14%);
  font-family: Inter, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
  color: var(--graphite-900);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0; }
.muted { color: var(--graphite-500); }
.small { font-size: 13px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }

/* Елементи керування */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 16px; border: 1px solid var(--graphite-300);
  border-radius: var(--radius); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--graphite-100); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--graphite-100); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn.large { min-height: 48px; font-size: 17px; }
.btn.block { width: 100%; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 7px 10px; background: var(--surface);
  border: 1px solid var(--graphite-300); border-radius: var(--radius);
}
.input:focus { border-color: var(--blue); outline: 1px solid var(--blue); }
.input.invalid { border-color: var(--red); }
textarea.input { min-height: 76px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 550; color: var(--graphite-700); }
.field > small { color: var(--graphite-500); }
.check { display: flex; align-items: center; gap: 8px; }
.form-error {
  padding: 9px 12px; border-radius: var(--radius); background: var(--red-soft); color: var(--red);
}

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--graphite-300); border-radius: var(--radius); background: var(--surface); }
.stepper button { width: 32px; height: 32px; border: 0; background: none; cursor: pointer; font-size: 17px; }
.stepper button:hover { background: var(--graphite-100); }
.stepper input { width: 46px; height: 32px; border: 0; text-align: center; background: none; }
.stepper input::-webkit-inner-spin-button { display: none; }

/* Блоки */
.panel { background: var(--surface); border: 1px solid var(--graphite-200); border-radius: var(--radius); padding: 18px; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--graphite-100); color: var(--graphite-700); white-space: nowrap;
}
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.empty { padding: 44px 16px; text-align: center; color: var(--graphite-500); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--graphite-200); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--graphite-500); padding: 10px 12px; border-bottom: 1px solid var(--graphite-200); white-space: nowrap; }
th.num { text-align: right; }
.cell { min-width: 0; }
td { padding: 10px 12px; border-bottom: 1px solid var(--graphite-100); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 0 0; }

dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: 8px; box-shadow: var(--shadow); color: inherit;
}
dialog.wide { width: min(720px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(30 35 41 / 45%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.dialog-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 15px; border-radius: var(--radius); background: var(--graphite-900); color: #fff; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }

/* Шапка персоналу */
.topbar { display: flex; align-items: center; gap: 22px; height: 56px; padding: 0 20px; background: var(--graphite-900); color: #fff; }
.brand { font-weight: 750; font-size: 17px; letter-spacing: -0.01em; color: #fff; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { color: #8fb0ee; font-weight: 750; }
.brand small { margin-left: 8px; font-weight: 450; font-size: 13px; color: var(--graphite-300); }
.tabs { display: flex; gap: 2px; align-self: stretch; }
.tabs a { display: flex; align-items: center; padding: 0 14px; color: var(--graphite-300); border-bottom: 3px solid transparent; border-top: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { color: #fff; text-decoration: none; }
.tabs a.active { color: #fff; border-bottom-color: #8fb0ee; }
.topbar .who { color: var(--graphite-300); font-size: 13px; }
.topbar .btn.ghost { color: #fff; }
.topbar .btn.ghost:hover { background: var(--graphite-700); }
.content { max-width: 1760px; margin: 0 auto; padding: 22px 20px 48px; }
.content > * + * { margin-top: 14px; }
.qty-input { width: 104px; flex: none; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { width: auto; }
.toolbar .search { flex: 1; min-width: 200px; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 170px; padding: 6px; background: var(--surface); border: 1px solid var(--graphite-200); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.menu-list a { padding: 8px 10px; border-radius: 4px; color: var(--graphite-900); }
.menu-list a:hover { background: var(--graphite-100); text-decoration: none; }
.topbar .menu summary { color: #fff; min-height: 30px; padding: 3px 10px; font-size: 13px; }
.topbar .menu summary:hover { background: var(--graphite-700); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px; }
.login-card .brand { color: var(--graphite-900); font-size: 20px; }
.login-card .brand b { color: var(--blue); }

@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tabs a { padding: 6px 12px 6px 0; margin-right: 8px; }
  .content { padding: 16px 16px 40px; }
}

.topbar-desktop { display: flex; align-items: center; gap: 8px; }
.mobile-only { display: none; }
.menu-item { padding: 8px 10px; border: 0; border-radius: 4px; background: none; text-align: left; color: var(--graphite-900); cursor: pointer; }
.menu-item:hover { background: var(--graphite-100); }
.filters-box > summary { list-style: none; }
.filters-box > summary::-webkit-details-marker { display: none; }

/* Телефони: великі цілі для пальця, рядки таблиць стають картками, діалоги виїжджають знизу. */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: clip; }
  button, a, summary, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  h1 { font-size: 22px; }
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
  .input, select.input, textarea.input, .stepper input { font-size: 16px; min-height: 44px; }
  .select-compact { min-height: 40px; }
  .stepper button { width: 44px; height: 44px; font-size: 20px; }
  .stepper input { width: 48px; height: 44px; min-height: 44px; }
  .check { min-height: 40px; }
  .check input { width: 22px; height: 22px; flex: none; }

  .topbar { position: sticky; top: 0; z-index: 25; height: auto; flex-wrap: wrap; padding: 6px 12px 0; gap: 0 8px; }
  .topbar .brand small { margin-left: 6px; }
  .tabs { order: 3; width: calc(100% + 24px); margin: 0 -12px; padding: 0 4px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { padding: 0 12px; min-height: 44px; }
  .topbar .menu summary { min-height: 44px; padding: 6px 12px; font-size: 15px; }
  .menu-list { min-width: 220px; }
  .menu-list a, .menu-item { min-height: 46px; display: flex; align-items: center; width: 100%; font-size: 16px; }
  .content { padding: 14px 12px 40px; }
  .content > .row.between { gap: 10px; }
  .toolbar { gap: 8px; }
  .toolbar .input, .toolbar .search { width: 100%; flex: 1 1 100%; min-width: 0; }

  .table-wrap { overflow: visible; background: none; border: 0; }
  .table-wrap > .empty { background: var(--surface); border: 1px solid var(--graphite-200); border-radius: var(--radius); }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { margin-bottom: 10px; padding: 6px 14px; background: var(--surface); border: 1px solid var(--graphite-200); border-radius: 8px; }
  td, td.num, td.nowrap, td.right { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--graphite-100); text-align: right; white-space: normal; }
  tr:last-child td { border-bottom: 1px solid var(--graphite-100); }
  tr td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--graphite-500); font-size: 13px; text-align: left; }
  td[data-label=""] { justify-content: flex-end; }
  td[data-label=""]::before { display: none; }
  td:has(> .cell:empty) { display: none; }
  .cell { overflow-wrap: anywhere; }
  td[data-label=""] .cell { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

  dialog, dialog.wide { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .dialog-head { position: sticky; top: 0; z-index: 2; padding: 14px 16px 10px; background: var(--surface); border-bottom: 1px solid var(--graphite-100); }
  .dialog-head h2 { font-size: 18px; }
  .dialog-body { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
  .dialog-actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); z-index: 2; margin: 0 -16px calc(-16px - env(safe-area-inset-bottom)); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--graphite-100); }
  .dialog-actions .btn { flex: 1 1 40%; }
  #toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; }
  .pager .btn { min-width: 84px; }
  .markup-panel > .grow { flex: 1 1 100%; }
  .markup-panel .btn { flex: 1 1 auto; }
}
