/* ==========================================================================
   7Store — дизайн-система портала
   Токены: светлая тема на :root, тёмная — по prefers-color-scheme.
   Статусные цвета фиксированы (good/warning/serious/critical) и всегда идут
   вместе с текстовой подписью: цвет никогда не несёт смысл в одиночку.
   ========================================================================== */

:root {
  color-scheme: light;

  --plane: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --surface-3: #ebe8e2;
  --border: #e5e2db;
  --border-strong: #d5d1c8;

  --ink: #1a1917;
  --ink-2: #5c5a54;
  --ink-muted: #78756d;

  --brand: #712727;
  --brand-hover: #5b1f1f;
  --brand-bar: #712727;
  --brand-ink: #ffffff;
  --brand-btn: #712727;
  --brand-btn-hover: #5b1f1f;
  --brand-wash: #f7ecec;
  --link: #1d5fb8;
  --focus: #8c4141;

  --good: #0ca30c;    --good-ink: #086b08;    --good-wash: #e7f7e7;
  --warn: #fab219;    --warn-ink: #7a4b00;    --warn-wash: #fdf3d9;
  --serious: #ec835a; --serious-ink: #9c3d10; --serious-wash: #fdeee6;
  --crit: #d03b3b;    --crit-ink: #a8241f;    --crit-wash: #fdeceb;
  --info: #1d5fb8;    --info-ink: #17518f;    --info-wash: #e8f1fd;
  --neutral-wash: #f0eeea;

  --track: #e8e5de;
  --ring: inset 0 0 0 1px rgba(26, 25, 23, .16);
  --shadow-1: 0 1px 2px rgba(26, 25, 23, .05), 0 1px 3px rgba(26, 25, 23, .06);
  --shadow-2: 0 6px 18px rgba(26, 25, 23, .10);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --bar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --plane: #121212;
    --surface: #1c1c1b;
    --surface-2: #232322;
    --surface-3: #2c2c2a;
    --border: #302f2d;
    --border-strong: #3d3c39;

    --ink: #f5f4f0;
    --ink-2: #c3c2b7;
    --ink-muted: #96938b;

    --brand: #c96a6a;
    --brand-hover: #d98080;
    --brand-bar: #401818;
    --brand-ink: #ffffff;
    --brand-btn: #8f2f2f;
    --brand-btn-hover: #a13636;
    --brand-wash: #2a1919;
    --link: #79b0f2;
    --focus: #c96a6a;

    --good: #0ca30c;    --good-ink: #5ddb5d;    --good-wash: #16261a;
    --warn: #fab219;    --warn-ink: #f7c95e;    --warn-wash: #2a2314;
    --serious: #ec835a; --serious-ink: #f2a884; --serious-wash: #2b1d17;
    --crit: #d03b3b;    --crit-ink: #f08a8a;    --crit-wash: #2c1817;
    --info: #79b0f2;    --info-ink: #9cc6f7;    --info-wash: #14202e;
    --neutral-wash: #262625;

    --track: #34332f;
    --ring: inset 0 0 0 1px rgba(255, 255, 255, .16);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-2: 0 6px 18px rgba(0, 0, 0, .45);
  }
}

/* ---------- Основа ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: proportional-nums;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--ink); padding: 10px 16px;
  border-radius: var(--r-sm); box-shadow: var(--shadow-2);
  transition: top .12s ease;
}
.skip-link:focus { top: 12px; }

.ic { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ic-lg { width: 20px; height: 20px; }
.ic-xl { width: 28px; height: 28px; }

.muted { color: var(--ink-muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono-num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good-ink); }
.neg { color: var(--crit-ink); }
.strong { font-weight: 650; }

/* ---------- Оболочка ---------- */

.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand-bar);
  color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .18), var(--shadow-1);
}
.appbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 8px; min-height: var(--bar-h);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  color: #fff; font-weight: 700; font-size: 17px; letter-spacing: -.02em;
  padding: 6px 8px 6px 0; border-radius: var(--r-sm);
}
.brand:hover { text-decoration: none; opacity: .92; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: rgba(255, 255, 255, .16);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}

.nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
.nav-link {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 11px; border-radius: var(--r-sm);
  color: rgba(255, 255, 255, .86); font-size: 14px; font-weight: 500;
  white-space: nowrap; transition: background .12s ease, color .12s ease;
}
.nav-link:hover { background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none; }
.nav-link[aria-current="page"] { background: rgba(255, 255, 255, .2); color: #fff; }
.nav-link .ic { opacity: .9; }

.appbar-user { display: flex; align-items: center; gap: 4px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: rgba(255, 255, 255, .18); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
  text-transform: uppercase;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border: 0; border-radius: var(--r-sm);
  background: none; color: rgba(255, 255, 255, .86); cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- Заголовок страницы ---------- */

.page-head {
  display: flex; align-items: flex-start; gap: 12px 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-head-text { flex: 1 1 320px; min-width: 0; }
.page-head-text .sub { color: var(--ink-muted); font-size: 14px; margin-top: 4px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--ink-muted); }
.breadcrumb a:hover { color: var(--ink-2); }
.breadcrumb > * + *::before { content: "/"; margin-right: 7px; color: var(--border-strong); }

.section {
  display: flex; align-items: baseline; gap: 10px;
  margin: 28px 0 12px; flex-wrap: wrap;
}
.section h2 { flex: none; }
.section .hint { color: var(--ink-muted); font-size: 13px; flex: 1 1 200px; }
.section .section-action { margin-left: auto; }

/* ---------- Карточки и сетки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h3 { flex: 1 1 auto; font-size: 14px; }
.card-head .card-action { margin-left: auto; }
.card-body { padding: 16px; }
.card-body > * + * { margin-top: 14px; }
.card-foot {
  padding: 11px 16px; border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md);
  font-size: 13px; color: var(--ink-muted);
}

.grid { display: grid; gap: 16px; align-items: start; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.divide > * + * { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }

/* ---------- Плитки показателей ---------- */

.stat-grid {
  display: grid; gap: 12px; margin-bottom: 8px;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 14px 16px; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat .stat-label {
  font-size: 12px; font-weight: 600; color: var(--ink-muted);
  letter-spacing: .03em; text-transform: uppercase;
  display: flex; align-items: center; gap: 6px;
}
.stat .stat-value { font-size: 28px; font-weight: 680; line-height: 1.15; letter-spacing: -.02em; }
.stat .stat-sub { font-size: 12px; color: var(--ink-muted); }
.stat.hero .stat-value { font-size: 40px; }
@media (min-width: 1000px) { .stat.hero { grid-column: span 2; } }
.stat-value.is-good { color: var(--good-ink); }
.stat-value.is-warn { color: var(--warn-ink); }
.stat-value.is-crit { color: var(--crit-ink); }

/* ---------- Индикатор доли (meter) ---------- */

.meter {
  --meter-fill: var(--good);
  display: block; height: 8px; border-radius: 4px;
  background: var(--track); box-shadow: var(--ring);
  overflow: hidden; min-width: 60px;
}
.meter > span {
  display: block; height: 100%; border-radius: 4px;
  background: var(--meter-fill); transition: width .18s ease;
}
.meter.is-good { --meter-fill: var(--good); }
.meter.is-warn { --meter-fill: var(--warn); }
.meter.is-serious { --meter-fill: var(--serious); }
.meter.is-crit { --meter-fill: var(--crit); }
.meter.is-info { --meter-fill: var(--info); }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row .meter { flex: 1 1 auto; }
.meter-row .meter-value { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2); flex: none; }
.meter-label { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-muted); margin-bottom: 5px; }

/* ---------- Бейджи ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 19px;
  background: var(--neutral-wash); color: var(--ink-2);
  white-space: nowrap; max-width: 100%;
}
.badge .dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: currentColor; box-shadow: var(--ring);
}
.badge.ok { background: var(--good-wash); color: var(--good-ink); }
.badge.ok .dot { background: var(--good); }
.badge.warn { background: var(--warn-wash); color: var(--warn-ink); }
.badge.warn .dot { background: var(--warn); }
.badge.serious { background: var(--serious-wash); color: var(--serious-ink); }
.badge.serious .dot { background: var(--serious); }
.badge.err { background: var(--crit-wash); color: var(--crit-ink); }
.badge.err .dot { background: var(--crit); }
.badge.info { background: var(--info-wash); color: var(--info-ink); }
.badge.info .dot { background: var(--info); }
.badge.muted .dot { background: var(--ink-muted); }
.badge-group { display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; }

/* ---------- Сообщения ---------- */

.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--r-sm); margin-bottom: 12px;
  border: 1px solid transparent; font-size: 14px;
}
.flash .ic { margin-top: 2px; }
.flash.success { background: var(--good-wash); color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.flash.error { background: var(--crit-wash); color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 32%, transparent); }
.flash.warning { background: var(--warn-wash); color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 38%, transparent); }
.flash.info { background: var(--info-wash); color: var(--info-ink); border-color: color-mix(in srgb, var(--info) 28%, transparent); }

.note {
  padding: 11px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--ink-2);
}
.note-inline { display: flex; gap: 8px; align-items: flex-start; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 550; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand-btn); border-color: var(--brand-btn); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-btn-hover); border-color: var(--brand-btn-hover); }
.btn.danger { color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 38%, var(--border)); }
.btn.danger:hover { background: var(--crit-wash); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-actions form { display: inline-flex; gap: 6px; align-items: center; }
table.data td.actions-cell { white-space: nowrap; }

/* ---------- Фильтры-чипы ---------- */

.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink-2); font-size: 13px; font-weight: 550; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.chip[aria-current="true"] { background: var(--brand-wash); border-color: color-mix(in srgb, var(--brand) 40%, transparent); color: var(--brand); }

/* ---------- Формы ---------- */

.field { min-width: 0; }
.field > label, .label {
  display: block; font-size: 13px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--ink-muted); margin-top: 5px; }

input[type=text], input[type=password], input[type=number], input[type=search],
input[type=date], select, textarea {
  width: 100%; padding: 9px 11px; min-height: 38px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-muted); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--ink-muted); }
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
input[type=number] { font-variant-numeric: tabular-nums; }

.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row > .field { flex: 1 1 150px; }
.form-row > .field.narrow { flex: 0 1 110px; }
.form-row > .field.wide { flex: 3 1 220px; }
.form-row > .btn { flex: 0 0 auto; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

.check {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 14px; color: var(--ink); font-weight: 400;
  padding: 7px 0; cursor: pointer;
}
.check input { width: 18px; height: 18px; min-height: 0; margin: 1px 0 0; flex: none; accent-color: var(--brand); }
.check .check-text { min-width: 0; }
.check .check-text .hint { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.check-list { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 12px; }
.check-list > .check + .check { border-top: 1px solid var(--border); }

.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-form input[type=number] { width: 74px; min-height: 30px; padding: 4px 8px; font-size: 13px; }

/* ---------- Дерево состава ---------- */

.tree-cell { display: flex; align-items: baseline; gap: 8px; padding-left: calc(var(--tree-level, 0) * 22px); }
.tree-branch {
  flex: none; width: 10px; height: 10px; margin-right: -2px;
  border-left: 1px solid var(--border-strong, var(--border));
  border-bottom: 1px solid var(--border-strong, var(--border));
  border-bottom-left-radius: 4px; transform: translateY(-2px);
}
.tree-cell .badge { vertical-align: middle; }
table.data tr.is-sub > td { background: var(--surface-2); }
table.data tr.is-sub .cell-title { font-weight: 500; }

/* ---------- Карта связей ---------- */

.map-frame {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1); overflow: hidden;
}
.map-viewport {
  overflow-x: auto; overflow-y: hidden; padding: 16px;
  /* тень у правого края подсказывает, что схема шире экрана */
  background-image: linear-gradient(to left, rgba(26, 25, 23, .09), rgba(26, 25, 23, 0) 24px);
  background-repeat: no-repeat; background-position: 100% 0; background-size: 24px 100%;
  background-attachment: local;
}
.map-canvas { position: relative; }
.map-links { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.map-link { fill: none; stroke: var(--ink-muted); stroke-width: 1.5; opacity: .5; }
.map-link.is-on { stroke: var(--brand); stroke-width: 2.4; opacity: 1; }
#map-arrow path { fill: var(--ink-muted); stroke: none; }

.map-col-head {
  position: absolute; top: 0; width: 210px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-node {
  position: absolute; width: 210px; height: 48px; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 6px 12px 6px 16px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-left: 4px solid var(--ink-muted);
  border-radius: var(--r-sm); box-shadow: var(--shadow-1);
  text-decoration: none; overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.map-node:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-2); }
.map-node-name {
  font-size: 13.5px; font-weight: 650; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-node-sub {
  font-size: 11.5px; color: var(--ink-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-node.is-assembly { border-left-color: var(--info); background: var(--info-wash); }
.map-node.is-assembly .map-node-sub { color: var(--info-ink); }
.map-node.is-project { border-left-color: var(--brand); background: var(--brand-wash); }
.map-node.is-focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-wash), var(--shadow-1); }

.map-legend {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--border);
  background: var(--surface-2); font-size: 12px; color: var(--ink-muted);
}
.map-legend-hint { flex: 1 1 200px; }
.map-key {
  width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid var(--border-strong); border-left-width: 4px; background: var(--surface);
}
.map-key.is-assembly { background: var(--info-wash); border-left-color: var(--info); }
.map-key.is-project { background: var(--brand-wash); border-left-color: var(--brand); }

/* ---------- Таблицы ---------- */

.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
  overflow: hidden;
}
.table-scroll {
  overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  /* тень у правого края подсказывает, что таблица прокручивается */
  background-image: linear-gradient(to left, rgba(26, 25, 23, .09), rgba(26, 25, 23, 0) 22px);
  background-repeat: no-repeat; background-position: 100% 0; background-size: 22px 100%;
  background-attachment: local;
}
.table-scroll:focus-visible { outline-offset: -2px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  padding: 10px 14px; text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data thead th {
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  letter-spacing: .02em; text-transform: uppercase;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.wrap { white-space: normal; min-width: 160px; }
table.data td.tight { padding-top: 6px; padding-bottom: 6px; }
table.data td.cell-main { white-space: normal; min-width: 230px; max-width: 340px; }
table.data .cell-title { font-weight: 600; color: var(--ink); }
table.data .cell-sub { display: block; font-size: 12px; color: var(--ink-muted); font-weight: 400; margin-top: 1px; }
.table-foot {
  padding: 10px 14px; border-top: 1px solid var(--border);
  background: var(--surface-2); font-size: 12px; color: var(--ink-muted);
}
.rownum { color: var(--ink-muted); font-variant-numeric: tabular-nums; width: 1%; }
.shortage {
  display: block; max-width: 210px; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.empty { padding: 36px 20px; text-align: center; color: var(--ink-muted); }
.empty .ic { width: 26px; height: 26px; margin-bottom: 8px; opacity: .5; }
.empty .empty-title { color: var(--ink-2); font-weight: 600; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }
td.empty { white-space: normal; }

/* ---------- Списки «ключ — значение» ---------- */

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 9px 18px; margin: 0; font-size: 14px; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; min-width: 0; }
.kv.wide { grid-template-columns: 1fr auto; }
.kv.wide dd { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Комментарии ---------- */

.comments { display: flex; flex-direction: column; gap: 14px; }
.comment { display: flex; gap: 11px; }
.comment-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--brand-wash); color: var(--brand);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  box-shadow: var(--ring); text-transform: uppercase;
}
.comment-body { min-width: 0; flex: 1; }
.comment-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.comment-meta .who { font-weight: 650; }
.comment-meta .when { color: var(--ink-muted); font-size: 12px; }
.comment-meta form { margin-left: auto; }
.comment-text {
  margin-top: 3px; white-space: pre-line; overflow-wrap: anywhere;
  font-size: 14px; color: var(--ink);
}

/* ---------- Вход ---------- */

.auth-wrap { max-width: 400px; margin: 8vh auto 0; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; text-align: center; }
.auth-brand .brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; font-size: 19px; box-shadow: var(--shadow-1); }
.auth-brand h1 { font-size: 22px; }
.auth-brand .sub { color: var(--ink-muted); font-size: 14px; }

/* ---------- Индикатор загрузки HTMX ---------- */

.htmx-request, .htmx-request * { cursor: progress; }
.htmx-request main { opacity: .65; transition: opacity .1s ease; }

/* ---------- Мобильные экраны ---------- */

@media (max-width: 900px) {
  .appbar-inner { flex-wrap: wrap; padding: 0 12px; row-gap: 0; }
  .brand { flex: 1 1 auto; min-height: 48px; }
  .nav {
    order: 3; flex-basis: 100%;
    margin: 0 -12px; padding: 0 12px 8px;
    overflow-x: auto; scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { scroll-snap-align: start; padding: 8px 12px; }
  main { padding: 16px 12px 56px; }
  h1 { font-size: 22px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat { padding: 12px 13px; }
  .stat .stat-value { font-size: 24px; }
  .stat.hero .stat-value { font-size: 32px; }
}

@media (max-width: 780px) {
  /* Таблицы превращаются в карточки: заголовок колонки подставляется из data-label */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  .table-wrap { background: none; border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
  .table-scroll { overflow: visible; }
  table.data tbody tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); box-shadow: var(--shadow-1);
    padding: 6px 14px 10px; margin-bottom: 10px;
  }
  table.data tbody tr:hover { background: var(--surface); }
  table.data td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
    padding: 6px 0; border-bottom: 1px dashed var(--border);
    white-space: normal; text-align: right;
  }
  table.data td:last-child { border-bottom: 0; }
  /* Значение ячейки бывает из нескольких бейджей (статус, приёмка, назначение,
     комплектация): переносим их на новую строку, иначе карточка распирает экран */
  table.data td { flex-wrap: wrap; }
  table.data td > * { min-width: 0; }
  table.data td::before {
    content: attr(data-label);
    flex: 0 1 auto; text-align: left;
    font-size: 12px; font-weight: 600; color: var(--ink-muted);
    letter-spacing: .02em; text-transform: uppercase;
  }
  table.data td.cell-main {
    padding: 8px 0; border-bottom: 1px solid var(--border);
    text-align: left; display: block; font-size: 15px;
  }
  table.data td.cell-main::before { content: none; }
  table.data td.no-label::before { content: none; }
  table.data td.no-label { text-align: left; }
  table.data td.actions-cell { justify-content: flex-start; padding-top: 10px; }
  table.data td.actions-cell::before { content: none; }
  table.data td.hide-sm { display: none; }
  .shortage { max-width: none; white-space: normal; text-align: right; }
  table.data .rownum { display: none; }
  table.data td.num { justify-content: space-between; }
  .table-foot { padding: 0 2px 6px; background: none; border: 0; }
  .empty, td.empty {
    display: block; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); padding: 28px 16px;
  }
  .kv { grid-template-columns: 1fr; gap: 3px; }
  .kv dd { margin-bottom: 8px; font-weight: 550; }
  .page-head { margin-bottom: 16px; }
  .section { margin: 22px 0 10px; flex-direction: column; align-items: flex-start; gap: 3px; }
  .section .hint { flex: none; }
  .section .section-action { margin-left: 0; }
  /* 16px в полях ввода — чтобы iOS не зумил страницу при фокусе */
  input[type=text], input[type=password], input[type=number], input[type=search],
  input[type=date], select, textarea { font-size: 16px; min-height: 42px; }
  .btn { min-height: 42px; }
  .btn.sm { min-height: 34px; }
  .form-row > .field { flex: 1 1 100%; }
  .form-row > .field.narrow, .form-row > .field.wide { flex: 1 1 100%; }
  .form-row > .btn { width: 100%; }
  .card-body { padding: 14px; }
}

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

@media print {
  .appbar, .page-head-actions, .row-actions, form { display: none !important; }
  body { background: #fff; }
  .card, .table-wrap { box-shadow: none; }
}
