/* Торговый дом Kaifa
   Палитра — из брендбука Kaifa (brandbook.dostavkakaifa.ru): синий #225def
   как основной акцент, малиново-розовый #dd3157 под ошибки/предупреждения,
   зелёный #47bf52 (затемнён для контраста текста) под "ок". Структура
   осталась прежней: чёрно-белый костяк + моноширинные цифры — корзина и
   история заказов должны читаться как накладная, а не как витрина маркетплейса. */

:root {
    --ink: #111111;
    --ink-2: #5c5c5a;
    --ink-3: #8f8f8b;
    --paper: #ffffff;
    --surface: #f6f5f3;
    --line: #e3e2de;
    --line-strong: #111111;
    --brand: #225def;
    --brand-warm: #a6dd2f;
    --danger: #dd3157;
    --ok: #1f8a3d;
    --warn: #a35a00;
    --warn-bg: #fff6e6;
    --radius: 4px;
    --font: 'Onest', -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

.mono { font-family: var(--mono); font-feature-settings: 'tnum' 1; }
.muted { color: var(--ink-3); }
.center { text-align: center; }
.right { text-align: right; }

/* ---------------------------------------------------------------- шапка */

.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 20px;
    padding: 0 24px; height: 64px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
}

.logo {
    font-weight: 800; font-size: 17px; letter-spacing: -0.02em;
    text-decoration: none; white-space: nowrap;
}
.logo span { color: var(--brand); }

.topbar-search { flex: 1; max-width: 420px; }
.topbar-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.cart-btn { position: relative; }
.cart-count {
    position: absolute; top: -6px; right: -6px;
    min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--brand); color: #fff;
    border-radius: 9px;
    font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* ------------------------------------------------------------- элементы */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--paper); color: var(--ink);
    font-weight: 600; font-size: 14px;
    transition: background .12s, color .12s;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand); border-color: var(--brand); }

.btn-ghost { border-color: transparent; font-weight: 500; }
.btn-ghost:hover { background: var(--surface); }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: var(--line); }

.input, .select, .textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper); color: var(--ink);
    font-family: inherit; font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--ink); outline: none;
}
.textarea { min-height: 76px; resize: vertical; }

.field { margin-bottom: 14px; }
.field label {
    display: block; margin-bottom: 5px;
    font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.field-hint { margin-top: 4px; font-size: 12px; color: var(--ink-3); }

.tag {
    display: inline-block; padding: 2px 8px;
    border-radius: 10px; background: var(--surface);
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.tag-ok { background: #e7f5ec; color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-err { background: #ffecec; color: var(--danger); }

/* ------------------------------------------------------------- каталог */

.catalog { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }

.rail-list {
    display: flex; flex-wrap: wrap; justify-content: center;
    gap: 8px; margin-bottom: 28px;
}
.rail-item {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
    text-align: center; font-size: 14px; color: var(--ink-2);
}
.rail-item:hover { background: var(--surface); }
.rail-item.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.rail-item .num { font-family: var(--mono); font-size: 12px; opacity: .7; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px 16px; }

.card { display: flex; flex-direction: column; }
.card-photo {
    aspect-ratio: 4 / 3; margin-bottom: 10px;
    background: var(--surface) center/cover no-repeat;
    border-radius: var(--radius);
    display: grid; place-items: center;
    color: var(--ink-3); font-size: 12px;
}
.card-sku { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.card-name { font-weight: 600; font-size: 14px; margin: 2px 0 6px; }
.card-price { font-family: var(--mono); font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.card-price small { font-family: var(--font); font-weight: 400; color: var(--ink-3); }
.card-foot { margin-top: auto; display: flex; gap: 6px; }

.qty { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qty button { width: 30px; border: none; background: var(--paper); color: var(--ink-2); font-size: 15px; }
.qty button:hover { background: var(--surface); }
.qty input {
    width: 44px; border: none; text-align: center;
    font-family: var(--mono); font-size: 13px;
}
.qty input:focus { outline: none; }

/* ------------------------------- корзина: свёрстана как бумажная накладная */

.drawer-backdrop {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(17, 17, 17, .38);
}
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
    width: min(560px, 100%);
    display: flex; flex-direction: column;
    background: var(--paper);
    border-left: 1px solid var(--line-strong);
}
.drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 2px solid var(--line-strong);
}
.drawer-head h2 { font-size: 16px; letter-spacing: -0.01em; }
.drawer-body { flex: 1; overflow-y: auto; padding: 0 22px; }
.drawer-foot { padding: 16px 22px; border-top: 2px solid var(--line-strong); background: var(--paper); }

.notice {
    display: flex; gap: 10px; align-items: flex-start;
    margin: 14px 0; padding: 11px 13px;
    border-left: 3px solid var(--warn);
    background: var(--warn-bg);
    font-size: 13px; line-height: 1.45;
}
.notice-err { border-color: var(--danger); background: #ffecec; }
.notice b { display: block; margin-bottom: 2px; }

/* строки накладной */
.slip-head, .slip-row {
    display: grid;
    grid-template-columns: 1fr 68px 84px 92px 28px;
    gap: 8px; align-items: center;
}
.slip-head {
    padding: 10px 0; border-bottom: 1px solid var(--line);
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
}
.slip-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.slip-row.is-gone { opacity: .55; }
.slip-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.slip-sku { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.slip-num { font-family: var(--mono); font-size: 13px; text-align: right; }
.slip-sum { font-family: var(--mono); font-size: 13px; font-weight: 700; text-align: right; }

/* вот ради этого всё: старая цена зачёркнута, дельта подписана */
.price-was { display: block; font-size: 10px; color: var(--ink-3); text-decoration: line-through; }
.price-delta { display: block; font-size: 10px; font-weight: 600; }
.price-delta.up { color: var(--danger); }
.price-delta.down { color: var(--ok); }

.slip-total {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 14px 0 4px;
    border-top: 2px solid var(--line-strong);
}
.slip-total span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.slip-total b { font-family: var(--mono); font-size: 22px; }

.empty { padding: 64px 20px; text-align: center; color: var(--ink-3); }
.empty p { margin-bottom: 16px; font-size: 14px; }

/* ------------------------------------------------------------- страницы */

.page { max-width: 940px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; letter-spacing: -0.02em; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 14px; }

.profile-head { display: flex; gap: 20px; align-items: center; margin-bottom: 24px; }
.avatar {
    width: 76px; height: 76px; flex: none;
    border-radius: 50%; background: var(--surface) center/cover no-repeat;
    display: grid; place-items: center;
    font-size: 24px; font-weight: 700; color: var(--ink-3);
}
.stat-row { display: flex; gap: 28px; margin-top: 6px; }
.stat b { display: block; font-family: var(--mono); font-size: 18px; }
.stat span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }

.order-line {
    display: grid; grid-template-columns: 74px 1fr 130px 110px 96px;
    gap: 12px; align-items: center;
    width: 100%; padding: 14px 8px;
    border: none; border-bottom: 1px solid var(--line); background: none;
    text-align: left;
}
.order-line:hover { background: var(--surface); }
.order-id { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.order-date { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    padding: 8px; border-bottom: 1px solid var(--line);
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-3); text-align: left;
}
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr.inactive td { opacity: .5; }

/* --------------------------------------------------------------- модалка */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(17, 17, 17, .38);
}
/* .modal-backdrop и .modal в разметке — СОСЕДНИЕ элементы, не вложенные
   (см. app.js/admin.js: оба вставляются как innerHTML на один уровень).
   Поэтому центрирование через grid-родителя не работает — .modal сам себе
   назначает fixed + margin:auto, как уже делает .drawer чуть ниже. */
.modal {
    position: fixed; inset: 0; margin: auto; z-index: 61;
    width: min(520px, 100%); height: fit-content; max-height: 88vh; overflow-y: auto;
    background: var(--paper); border-radius: var(--radius);
    border: 1px solid var(--line-strong);
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- прочее */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(380px, 100%); }
.auth-card .logo { display: block; margin-bottom: 6px; font-size: 22px; }
.auth-tagline { margin-bottom: 26px; color: var(--ink-3); font-size: 14px; }
.auth-switch { margin-top: 16px; font-size: 13px; text-align: center; color: var(--ink-3); }

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 11px 15px; max-width: 380px;
    background: var(--ink); color: #fff;
    border-radius: var(--radius); font-size: 13px;
}
.toast.err { background: var(--danger); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab {
    padding: 10px 14px; border: none; background: none;
    border-bottom: 2px solid transparent;
    color: var(--ink-3); font-weight: 600; font-size: 14px;
}
.tab.active { color: var(--ink); border-bottom-color: var(--brand); }

@media (max-width: 860px) {
    .catalog { padding: 20px 16px 60px; }
    .rail-list { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding-bottom: 4px; margin-bottom: 20px; }
    .rail-item { white-space: nowrap; }
    .topbar { padding: 0 16px; gap: 12px; }
    .topbar-search { max-width: none; }
    .slip-head, .slip-row { grid-template-columns: 1fr 62px 78px 28px; }
    .slip-head .col-price, .slip-row .col-price { display: none; }
    .order-line { grid-template-columns: 1fr 96px; row-gap: 4px; }
    .order-line .col-hide { display: none; }
}
