:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #697386;
  --line: #e3e6ec;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e4f5ec;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --err: #c0352b;
  --err-bg: #fde8e6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1a1f26;
    --text: #e8ecf2;
    --muted: #93a0b4;
    --line: #2a313b;
    --brand: #4c8dff;
    --brand-ink: #0b1220;
    --ok: #55d28f;
    --ok-bg: #12301f;
    --warn: #f0c050;
    --warn-bg: #3a2f10;
    --err: #ff8b80;
    --err-bg: #3b1816;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* шапка */
header.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 16px 0;
}
.top-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.brand { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--muted);
  white-space: nowrap; font-weight: 500;
}
nav.tabs a.active { background: var(--brand); color: var(--brand-ink); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

.banner { padding: 10px 16px; font-size: 14px; text-align: center; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .l { color: var(--muted); font-size: 13px; }

/* формы */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=time], input[type=url], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
textarea { min-height: 70px; resize: vertical; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 12px; }
.row.tight { align-items: end; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 0; }
.check input { width: 18px; height: 18px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; font-weight: 500; text-decoration: none;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--err); }
button.small { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
td.items { min-width: 220px; max-width: 380px; white-space: pre-wrap; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.err { background: var(--err-bg); color: var(--err); border-color: transparent; }

.err-text { color: var(--err); font-size: 14px; margin: 8px 0 0; min-height: 1.2em; }

.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; background: var(--bg); display: block; }
.thumbs.edit { margin-bottom: 8px; }
.thumbs.edit:empty { display: none; }
.thumbs.edit img { width: 84px; height: 84px; }
.thumb { position: relative; }
.thumb.pending img { opacity: .75; outline: 2px dashed var(--brand); outline-offset: -2px; }
.thumb .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; line-height: 1; background: var(--card); color: var(--err); font-size: 15px; }
dialog.lightbox { padding: 0; background: transparent; border: 0; width: auto; max-width: 100vw; max-height: 100vh; overflow: visible; }
dialog.lightbox img { max-width: 96vw; max-height: 92vh; display: block; border-radius: 10px; }
.order { display: flex; flex-direction: column; gap: 6px; }
.card.order { padding: 12px 14px; margin-bottom: 10px; }
.order + .order { border-top: 1px solid var(--line); padding-top: 12px; }
.order-head, .order-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.order-foot select { width: auto; min-width: 130px; }
.order .items { white-space: pre-wrap; min-width: 0; max-width: none; }
.grow { flex: 1; min-width: 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.kv:first-of-type { border-top: 0; }
.shift { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.shift-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.shift-head b { flex: 1; }
.sale { display: flex; gap: 10px; align-items: center; padding: 4px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.sale .grow { flex: 1; min-width: 0; }

dialog { width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border: 1px solid var(--line); border-radius: 14px; padding: 18px; background: var(--card); color: var(--text); overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }

.auth { max-width: 400px; margin: 8vh auto; padding: 0 16px; }
.auth .card { padding: 22px; }
.auth h1 { text-align: center; margin-bottom: 16px; }
.auth .switch { text-align: center; margin-top: 14px; font-size: 14px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }
.help { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pill-list .chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; font-size: 13px; }
.pill-list .chip button { padding: 0 6px; border: 0; background: transparent; color: var(--err); font-size: 16px; line-height: 1; }

@media (max-width: 560px) {
  main { padding: 12px; }
  .card { padding: 12px; }
  .stat .v { font-size: 19px; }
}

/* роли и доступы */
.who { font-weight: 400; color: var(--muted, #6b7280); margin-left: 6px; font-size: 12px; }
.perm-group { margin: 14px 0 0; }
.perm-group h3 { margin: 0 0 6px; font-size: 14px; }
.perm { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(128,128,128,.15); }
.perm select { width: auto; min-width: 130px; }
.perm.check { cursor: pointer; }

.code { background: rgba(128,128,128,.12); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 12px; margin: 4px 0 10px; white-space: pre-wrap; word-break: break-all; user-select: all; }
a.button { display: inline-block; text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-size: 13px; color: inherit; background: var(--card); }
a.button:hover { border-color: var(--brand); }
