/* =========================================================================
   АТБ · Hub — design system v4 (индиго, светлая боковая панель)
   Только визуальный слой: все селекторы, ID, data-* и классы, на которые
   опираются шаблоны и JavaScript, сохранены. Фиолетовая основа и янтарный
   акцент остались; убраны декоративная анимация и разрозненные hex-значения,
   всё сведено к токенам. Цель — спокойный рабочий интерфейс: читаемые
   таблицы, понятная иерархия, доступный фокус и мобильный вид.
   ========================================================================= */

:root {
  /* Нейтрали (холодные, спокойные) */
  --ink: #121726;
  --ink-soft: #394056;
  --muted: #667089;
  --surface: #ffffff;
  --surface-subtle: #fafbfe;
  --surface-tint: #f1f3fb;
  --canvas: #f6f7fb;
  --line: #e6e8f1;
  --line-strong: #d3d7e6;

  /* Бренд: индиго + янтарный акцент */
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-light: #6366f1;
  --brand-tint: #eef0ff;
  --brand-ink: #3730a3;
  --action-bg: #4f46e5;
  --action-hover: #4338ca;
  --action-text: #ffffff;
  --navy: #121726;
  --navy-soft: #1e2540;
  --accent: #fbbf24;
  --accent-dark: #b45309;
  --focus: #4f46e5;

  /* Семантика (пары фон/текст ≥ 4.5:1) */
  --danger: #cf2b43;
  --danger-bg: #ffe6ea;
  --danger-line: #f6c1ca;
  --success: #047857;
  --success-bg: #dcf7ea;
  --success-line: #b6e8cf;
  --warning: #a85a00;
  --warning-bg: #fff0cf;
  --warning-line: #f0d29b;

  /* Форма */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --shadow-xs: 0 1px 2px rgb(18 23 38 / 5%);
  --shadow-sm: 0 2px 8px rgb(18 23 38 / 7%);
  --shadow-md: 0 6px 20px rgb(18 23 38 / 8%);
  --shadow-lg: 0 18px 44px rgb(18 23 38 / 16%);
  --ring: 0 0 0 3px rgb(79 70 229 / 24%);

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

body { min-width: 320px; margin: 0; background: var(--canvas); font-weight: 400; }
a { color: var(--brand); text-decoration: none; transition: color 160ms var(--ease); }
a:hover { color: var(--brand-hover); }
button, input, select, textarea { font: inherit; }
::selection { background: rgb(79 70 229 / 20%); color: var(--ink); }
table, .metric strong, .line-count, .count { font-variant-numeric: tabular-nums; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cfd3e3; border: 3px solid var(--canvas); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #a3a9c4; }

/* Фокус: единый для мыши-неактивных (клавиатура) состояний */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; box-shadow: none; }

.skip-link { max-width: calc(100% - 16px); position: absolute; z-index: 100; top: 8px; left: 8px; padding: 10px 16px; border-radius: var(--radius-sm); background: #fff; color: var(--navy); font-weight: 700; transform: translateY(-200%); }
.skip-link:focus { transform: none; outline: 3px solid var(--accent); }

/* -------------------------------------------------------------------------
   Типографика
   ---------------------------------------------------------------------- */
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.75rem, 3.2vw, 2.375rem); line-height: 1.12; letter-spacing: -.03em; font-weight: 700; }
h2 { margin-bottom: 8px; font-size: 1.1875rem; line-height: 1.3; letter-spacing: -.012em; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
.eyebrow { display: block; margin-bottom: 6px; color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .12em; line-height: 1.25; text-transform: uppercase; }
.light { color: #cfc4ef; }
.lead, .muted { color: var(--muted); }
.lead { margin-bottom: 0; }
.strong { font-weight: 700; }
.field-hint { display: block; margin-top: 4px; color: var(--muted); font-size: .75rem; line-height: 1.4; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.count { display: inline-grid; min-width: 28px; min-height: 28px; margin-left: 8px; padding: 2px 9px; place-items: center; border-radius: 999px; background: var(--brand-tint); color: var(--brand-ink); font-size: .8125rem; font-weight: 700; vertical-align: middle; }

/* -------------------------------------------------------------------------
   Кнопки
   ---------------------------------------------------------------------- */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  font-weight: 600; line-height: 1.25; text-align: center;
  cursor: pointer; user-select: none;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease), color 160ms var(--ease), opacity 160ms var(--ease);
}
button:hover, .button:hover { border-color: #a3a9c4; background: var(--surface-tint); color: var(--brand-ink); }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible { box-shadow: var(--ring); outline-offset: 1px; }
button:disabled, .button[aria-disabled="true"], .busy { cursor: not-allowed; opacity: .5; pointer-events: none; transform: none; box-shadow: none; }
@media (pointer: coarse) { button, .button { min-height: 44px; } }

.ripple-dot { position: absolute; border-radius: 50%; transform: scale(0); background: rgb(255 255 255 / 30%); pointer-events: none; animation: ripple-expand 420ms var(--ease) forwards; }
@keyframes ripple-expand { to { transform: scale(2.4); opacity: 0; } }

.primary { position: relative; overflow: hidden; border-color: var(--action-bg); background: var(--action-bg); color: var(--action-text); box-shadow: 0 1px 2px rgb(18 23 38 / 18%); }
.primary:hover { border-color: var(--action-hover); background: var(--action-hover); color: var(--action-text); box-shadow: 0 4px 12px rgb(79 70 229 / 30%); }
.secondary { border-color: #b4b9d6; background: #fff; color: var(--brand-ink); }
.secondary:hover { border-color: var(--brand-light); background: var(--brand-tint); }
.wide { width: 100%; }
.quiet { min-height: auto; padding: 8px 10px; border-color: transparent; background: transparent; box-shadow: none; color: var(--brand-ink); }
.quiet:hover { border-color: transparent; background: var(--brand-tint); }
.danger { color: var(--danger) !important; }
.danger-button { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
.danger-button:hover { border-color: #e29aa6; background: #fbdde2; color: #8f1e2e; }
.compact { min-height: 36px; padding: 7px 12px; font-size: .8125rem; }

/* -------------------------------------------------------------------------
   Поля форм
   ---------------------------------------------------------------------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  display: block; width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), background-color 160ms var(--ease);
}
textarea { line-height: 1.45; }
input:not([type="checkbox"]):hover, select:hover, textarea:hover { border-color: #a3a9c4; }
input:not([type="checkbox"]):focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid var(--focus); outline-offset: 1px; box-shadow: none; }
input:disabled, select:disabled, textarea:disabled, input[readonly] { cursor: not-allowed; background: var(--surface-tint); color: var(--muted); }
input[readonly] { cursor: default; }
select:not([multiple]) {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath d='m1 1 6 6 6-6' fill='none' stroke='%2343307a' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--brand); cursor: pointer; }
label { display: block; margin-bottom: 6px; color: var(--ink-soft); font-size: .875rem; font-weight: 600; }
.errorlist { padding: 0; margin: 6px 0 0; color: var(--danger); font-size: .875rem; list-style: none; }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0; font-size: .875rem; font-weight: 500; line-height: 1.4; }
.check input { margin-top: 1px; }
input:not([type="checkbox"]):not([type="hidden"]):user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--danger); }

/* -------------------------------------------------------------------------
   Каркас: шапка, меню, main, footer
   ---------------------------------------------------------------------- */
.top {
  position: fixed; z-index: 40; inset: 0 auto 0 0; width: 264px;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 22px 16px; overflow-y: auto;
  background: var(--surface); color: var(--ink-soft);
  border-right: 1px solid var(--line);
}
.i { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 22px; color: var(--ink); font-size: 1.125rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.brand:hover { color: var(--ink); }
.mark { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 900; }
.brand-text { display: grid; gap: 3px; }
.brand-sub { color: var(--muted); font-size: .75rem; font-weight: 500; letter-spacing: 0; }
.top nav { display: flex; flex-direction: column; gap: 2px; }
.top nav > a, .admin-nav summary { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: .9375rem; font-weight: 600; transition: background-color 160ms var(--ease), color 160ms var(--ease); }
.top nav > a:hover, .admin-nav summary:hover, .admin-nav[open] summary { background: var(--surface-tint); color: var(--ink); }
.top nav > a[aria-current="page"], .admin-nav summary[aria-current="page"] { background: var(--brand-tint); color: var(--brand-ink); }
.admin-nav { align-self: stretch; }
.admin-nav summary { list-style: none; cursor: pointer; }
.admin-nav summary::-webkit-details-marker { display: none; }
.admin-nav summary::after { content: "▾"; margin-left: auto; font-size: .75em; opacity: .65; }
.admin-nav-links { display: grid; gap: 2px; padding: 4px 0 4px 36px; }
.top nav .admin-nav-links a { display: block; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: .875rem; font-weight: 500; }
.top nav .admin-nav-links a:hover { background: var(--surface-tint); color: var(--ink); }
.top nav .admin-nav-links a[aria-current="page"] { background: var(--brand-tint); color: var(--brand-ink); font-weight: 600; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding: 10px 10px 10px 14px; border-radius: var(--radius-md); background: var(--surface-tint); color: var(--ink); font-size: .875rem; font-weight: 600; }
.account form { margin: 0; }
.account .quiet { color: var(--ink-soft); }
.account .quiet:hover { background: var(--surface); color: var(--brand-ink); }

body { padding-left: 264px; }
main { max-width: 1440px; min-height: calc(100vh - 100px); margin: auto; padding: 28px max(24px, 3.5vw) 48px; }
footer { padding: 16px max(24px, 3.5vw); border-top: 1px solid var(--line); color: var(--muted); font-size: .8125rem; }

.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--ink-soft); font-size: .9375rem; font-weight: 600; }
.back:hover { color: var(--brand); }

/* -------------------------------------------------------------------------
   Карточки, таблицы, бейджи, сообщения
   ---------------------------------------------------------------------- */
.card { padding: 24px; margin-bottom: 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface-subtle); color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 16px; border-bottom: 1px solid #eceef5; font-size: .9375rem; vertical-align: middle; }
tbody tr { transition: background-color 140ms var(--ease); }
tbody tr:hover { background: #f5f6fd; }
tbody tr:last-child td { border-bottom: 0; }
td small.field-hint { margin-top: 2px; }

.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 3px 11px 3px 9px; border: 1px solid transparent; border-radius: 999px; font-size: .75rem; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor; }
.draft { background: #ebedf5; color: #3e4660; border-color: #dcdfeb; }
.correction { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-line); }
.approved { background: #e4e7ff; color: #3730a3; border-color: #c7cdfa; }
.shipped { background: var(--success-bg); color: var(--success); border-color: var(--success-line); }
.deleted { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }

.message { padding: 14px 18px; margin-bottom: 20px; border: 1px solid var(--success-line); border-left-width: 4px; border-radius: var(--radius-md); background: var(--success-bg); color: #0c5c3b; }
.message.warning { border-color: var(--warning-line); background: var(--warning-bg); color: var(--warning); }
.message.error { border-color: var(--danger-line); background: var(--danger-bg); color: #9a2133; }

.empty { padding: 44px 16px; text-align: center; }
.empty p { max-width: 440px; margin: 0 auto 20px; color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 24px 0 0; color: var(--muted); font-size: .9375rem; }

.notice { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; margin-bottom: 20px; border: 1px solid #d4d9fa; border-left: 4px solid var(--brand-light); border-radius: var(--radius-sm); background: var(--surface-tint); color: var(--ink-soft); }
.approval-card { max-width: 1040px; }
.action-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; }
.action-footer p { max-width: 600px; margin-bottom: 0; }
.ship-form td > label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.ship-form td input[type="number"], .ship-form td input[name$="quantity"] { max-width: 180px; }
.catalog-form label { margin-top: 14px; }

/* -------------------------------------------------------------------------
   Hero-блоки: единый вид для заявок, аналитики, агента, склада
   ---------------------------------------------------------------------- */
.dashboard-hero, .analytics-hero, .agent-hero, .warehouse-hero {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 28px 32px; margin-bottom: 20px; border: 1px solid var(--line); border-radius: var(--radius-xl);
  background: var(--brand-tint); color: var(--ink);
}
.dashboard-hero h1, .analytics-hero h1, .agent-hero h1, .warehouse-hero h1 { margin: 4px 0 10px; color: var(--ink); }
.dashboard-hero p, .analytics-hero p, .agent-hero p, .warehouse-hero p { max-width: 680px; margin: 0; color: var(--ink-soft); }
.dashboard-hero .eyebrow, .analytics-hero .eyebrow, .agent-hero .eyebrow, .warehouse-hero .eyebrow { color: var(--brand-ink); }
.light { color: var(--brand-ink); }
.hero-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero-action { position: relative; overflow: hidden; min-height: 46px; border-color: var(--action-bg); background: var(--action-bg); color: var(--action-text); font-weight: 700; white-space: nowrap; }
.hero-action:hover { border-color: var(--action-hover); background: var(--action-hover); color: var(--action-text); }
.hero-actions .recurring-link, .dashboard-hero .button:not(.hero-action) { border-color: var(--line-strong); background: var(--surface); color: var(--ink); white-space: nowrap; }
.hero-actions .recurring-link:hover { border-color: var(--brand-light); background: var(--surface); color: var(--brand-ink); }

.analytics-hero-note, .agent-status { display: grid; min-width: 210px; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.agent-status { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.analytics-hero-note span { color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.analytics-hero-note strong { max-width: 300px; color: var(--ink); font-size: 1rem; line-height: 1.35; }
.analytics-hero-note small, .agent-status small { color: var(--muted); font-size: .75rem; line-height: 1.35; }
.agent-status strong, .agent-status small { display: block; }
.agent-status strong { color: var(--ink); font-size: .9375rem; }
.status-dot { width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgb(16 185 129 / 20%); }

/* -------------------------------------------------------------------------
   Метрики
   ---------------------------------------------------------------------- */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric { position: relative; min-height: 96px; padding: 18px 18px 18px 22px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.metric::before { position: absolute; inset: 0 auto 0 0; width: 4px; background: #9aa1bd; content: ""; }
.metric.pending::before { background: var(--brand-light); }
.metric.editing::before { background: var(--accent-dark); }
.metric.completed::before { background: var(--success); }
.metric span { display: block; margin-bottom: 8px; color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.metric strong { font-size: 1.875rem; letter-spacing: -.04em; line-height: 1; font-weight: 700; }

/* -------------------------------------------------------------------------
   Рабочая область, фильтры, список заявок
   ---------------------------------------------------------------------- */
.workspace { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.workspace-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.workspace-title h2 { margin-bottom: 0; }
.filters { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 14px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-subtle); }
.filters label { flex: 1 1 150px; margin: 0; }
.filters .search { flex: 2 1 240px; }
.filters label span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.filters input:not([type="checkbox"]), .filters select, .filters .date-picker-trigger { min-height: 44px; box-shadow: var(--shadow-xs); }
.filters .date-filter { flex: 0 1 340px; min-width: 260px; max-width: 340px; }
.filters > button, .filters > .reset { align-self: flex-end; min-height: 44px; white-space: nowrap; }
.reset { align-self: center; }

.order-table table { min-width: 800px; }
.table-wrap:has(.empty) table { min-width: 0; width: 100%; }
.table-wrap:has(.empty) thead { display: none; }
.order-link { color: var(--ink); font-weight: 700; }
.order-link:hover { color: var(--brand); text-decoration: underline; text-underline-offset: 4px; }
.line-count { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 8px; background: var(--brand-tint); color: var(--brand-ink); font-weight: 700; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.row-actions > a { padding: 8px 10px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 600; }
.row-actions > a:hover { background: var(--brand-tint); }
.row-actions form { margin: 0; }
.row-actions .quiet.danger:hover { background: var(--danger-bg); }

/* -------------------------------------------------------------------------
   Заголовки страниц, процесс, карточка заявки
   ---------------------------------------------------------------------- */
.page-heading, .order-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-heading h1, .order-top h1 { margin-bottom: 6px; }
.order-top .lead span { padding: 0 4px; color: #a3a9c4; }

.flow-card { display: flex; align-items: center; padding: 18px 24px; margin-bottom: 20px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.flow-step { display: flex; align-items: center; gap: 12px; min-width: 184px; color: var(--muted); }
.flow-step i { display: grid; width: 32px; height: 32px; flex: 0 0 32px; place-items: center; border: 2px solid #cdd1e2; border-radius: 50%; background: #fff; font-style: normal; font-weight: 700; }
.flow-step strong, .flow-step span { display: block; font-size: .8125rem; line-height: 1.25; }
.flow-step span { margin-top: 3px; font-size: .75rem; }
.flow-step.done { color: var(--brand-ink); }
.flow-step.done i { border-color: var(--action-bg); background: var(--action-bg); color: var(--action-text); }
.flow-step.current { color: var(--warning); }
.flow-step.current i { border-color: var(--accent-dark); background: var(--warning-bg); color: var(--warning); box-shadow: 0 0 0 4px rgb(246 185 59 / 22%); }
.flow-line { min-width: 32px; height: 2px; flex: 1; background: var(--line); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; margin-bottom: 20px; }
.detail-grid .order-card { margin-bottom: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { margin-bottom: 0; }

.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 20px; }
.facts > div { min-width: 0; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-subtle); }
.facts dt { color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.facts dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 600; }

.action-panel { align-self: start; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.action-main { padding: 18px; margin-bottom: 12px; border: 1px solid #d4d9fa; border-radius: var(--radius-md); background: var(--brand-tint); }
.action-main h2 { margin-bottom: 6px; }
.action-main p { margin-bottom: 14px; color: var(--ink-soft); font-size: .875rem; }
.action-panel > form { margin-bottom: 12px; }
.action-panel > p { color: var(--muted); font-size: .9375rem; }

.secondary-action { display: flex; align-items: center; gap: 12px; padding: 14px 16px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); color: var(--ink-soft); transition: border-color 160ms var(--ease), background-color 160ms var(--ease); }
.secondary-action:hover { border-color: #a5acea; background: var(--surface-tint); color: var(--ink-soft); }
.secondary-action > span:first-child { color: var(--brand); font-size: 1.25rem; }
.secondary-action strong, .secondary-action small { display: block; }
.secondary-action small { margin-top: 3px; color: var(--muted); font-size: .75rem; line-height: 1.35; }
.secondary-arrow { margin-left: auto; color: var(--muted); transition: transform 160ms var(--ease); }
.secondary-action:hover .secondary-arrow { transform: translateX(3px); }

.return { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }
.return summary { display: flex; align-items: center; min-height: 32px; color: var(--ink-soft); font-size: .875rem; font-weight: 600; cursor: pointer; }
.return summary:hover { color: var(--brand); }
.return form { margin-top: 14px; }
.danger-area summary { color: var(--danger); }

/* Карточка «Отправка» в заявке */
.dispatch-card { display: grid; gap: 4px; }
.dispatch-card h2 { margin-bottom: 4px; }
.dispatch-card p { margin: 0 0 6px; }
.dispatch-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; align-items: end; padding-top: 14px; margin-top: 8px; border-top: 1px solid var(--line); }
.dispatch-form label { margin: 0; }
.dispatch-form button { min-height: 44px; }
.dispatch-label { display: inline-block; padding: 5px 12px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 700; }
.dispatch-early { background: #40e0d0; color: #0f3534; }
.dispatch-late { background: #17365d; color: #fff; }
.dispatch-none { background: #ebedf5; color: #3e4660; }

.history { padding: 0; list-style: none; }
.history li { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }

.tabs, .etrn-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.tabs a, .tabs span, .etrn-tabs a { display: inline-block; padding: 9px 14px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: .9375rem; font-weight: 600; text-decoration: none; transition: background-color 160ms var(--ease), color 160ms var(--ease); }
.tabs a:hover, .etrn-tabs a:hover { background: var(--brand-tint); color: var(--brand-ink); }
.tabs .active, .etrn-tabs a[aria-current="page"], .etrn-tabs a[aria-current="page"]:hover { background: var(--brand-tint); color: var(--brand-ink); cursor: default; }

.login { position: relative; max-width: 440px; margin: 40px auto; overflow: hidden; }
.login::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--brand); }
.login form p { margin: 0 0 16px; }
.login .helptext { display: block; margin-top: 4px; color: var(--muted); font-size: .75rem; }

/* -------------------------------------------------------------------------
   Формы заявок: строки товаров, сетка, панель сохранения
   ---------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: minmax(144px, 1fr) minmax(176px, 1.5fr) minmax(208px, 2fr); gap: 16px; }
.form-grid > div > label { margin-top: 0; }
.shipment-date-field { margin-top: 14px; }
.line-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(128px, 1fr) auto; gap: 16px; align-items: end; padding: 14px 0; border-top: 1px solid var(--line); }
#lines > .line-row:first-child { border-top: 0; padding-top: 0; }
#add-line { margin-top: 8px; border-style: dashed; color: var(--brand-ink); }
.remove { display: flex; align-items: center; gap: 8px; padding-bottom: 10px; margin: 0; font-size: .875rem; font-weight: 500; white-space: nowrap; }
.locked-leaf-cell { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; padding-bottom: .35rem; }
.locked-leaf-cell .filter-label { margin: 0; }
.locked-leaf-cell strong { font-weight: 600; }
.order-classification { align-self: end; margin-top: 14px; }
.order-classification > .check { display: inline-flex; align-items: center; gap: .45rem; margin: 0; font-weight: 500; }
.order-classification-kind { display: none; margin-top: .55rem; }
.order-classification:has(input[type="checkbox"]:checked) .order-classification-kind { display: block; }
.etrn-order-option { margin-bottom: 14px; }

.save-bar {
  position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border: 1px solid #2b3150; border-radius: var(--radius-md);
  background: rgb(18 23 38 / 94%); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: #fff; box-shadow: var(--shadow-lg);
}
.save-bar p { margin: 0 auto 0 0; max-width: 620px; color: #d5d9ee; font-size: .875rem; }
.save-bar .muted { color: #d5d9ee; }
.save-bar button:not(.primary) { border-color: rgb(255 255 255 / 45%); background: transparent; color: #fff; }
.save-bar button:not(.primary):hover { border-color: #fff; background: rgb(255 255 255 / 14%); color: #fff; }
.save-bar .primary { border-color: var(--action-bg); background: var(--action-bg); color: var(--action-text); box-shadow: none; }
.save-bar .primary:hover { border-color: var(--action-hover); background: var(--action-hover); color: var(--action-text); }
.save-bar :focus-visible { outline-color: #fff; }

.selected-group { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--muted); font-size: .8125rem; }
.selected-group strong { padding: 2px 8px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-ink); font-weight: 700; }
.inline-catalog-link { display: inline-block; min-height: 0; margin-top: 8px; padding: 2px 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: var(--brand); cursor: pointer; font-size: .8125rem; font-weight: 600; }
.inline-catalog-link:hover { border: 0; background: transparent; color: var(--brand-hover); text-decoration: underline; text-underline-offset: 3px; }
.inline-catalog-link:active { transform: none; }

.catalog-technical-code { margin-top: 20px; color: var(--muted); font-size: .875rem; }
.catalog-technical-code summary { width: fit-content; cursor: pointer; }
.catalog-technical-code > div { max-width: 440px; margin-top: 10px; }
.catalog-technical-code input { font-size: .875rem; }
.catalog-code-cell { display: inline-block; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.catalog-view-toggle { margin: 0 0 12px; font-size: .875rem; }
.catalog-remove-link { margin: 16px 0 0; font-size: .875rem; }
.catalog-confirm-card { max-width: 750px; }
.catalog-confirm-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.catalog-points-card { margin-top: 20px; }
.catalog-points-list { max-height: 360px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.catalog-points-list li { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.catalog-points-list li a { color: var(--brand); }

dialog { color: var(--ink); }
dialog::backdrop { background: rgb(18 23 38 / 55%); }
.quick-catalog-dialog { width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.quick-catalog-dialog h2 { margin: 0 0 8px; }
.quick-catalog-dialog label { display: block; margin: 14px 0; font-size: .875rem; }
.quick-catalog-dialog label input { margin-top: 6px; }
.quick-catalog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.quick-catalog-error { color: var(--danger); font-size: .875rem; }

/* -------------------------------------------------------------------------
   Календарь (выбор даты / периода)
   ---------------------------------------------------------------------- */
.date-filter { position: relative; display: grid; flex: 1 1 230px; min-width: 220px; gap: 5px; }
.filter-label { color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.date-picker-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 9px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink); font-weight: 600; text-align: left; box-shadow: var(--shadow-xs); }
.date-picker-trigger:hover { border-color: #a3a9c4; background: #fff; color: var(--ink); }
.date-picker-trigger:focus-visible { border-color: var(--focus); box-shadow: var(--ring); }
.date-picker-trigger > span:last-child, .date-picker-trigger .date-chevron { width: 8px; height: 8px; flex: 0 0 8px; margin: -4px 4px 0 12px; border-right: 2px solid #3b3f8f; border-bottom: 2px solid #3b3f8f; color: transparent; font-size: 0; transform: rotate(45deg); }
.date-picker-popover { position: absolute; z-index: 30; top: calc(100% + 8px); left: 0; width: min(336px, calc(100vw - 32px)); padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-lg); }
.date-picker-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 12px; border-radius: var(--radius-sm); background: var(--surface-tint); }
.date-picker-modes button { min-height: 34px; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: .8125rem; font-weight: 700; }
.date-picker-modes button:hover { background: rgb(255 255 255 / 60%); }
.date-picker-modes button.is-active { background: #fff; color: var(--brand-ink); box-shadow: var(--shadow-xs); }
.date-picker-header { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; margin-bottom: 8px; }
.date-picker-header strong { color: var(--ink); font-size: .875rem; text-align: center; text-transform: capitalize; }
.date-picker-header button { width: 34px; min-height: 34px; height: 34px; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--brand-ink); font-size: 1.4rem; line-height: 1; }
.date-picker-header button:hover { background: var(--brand-tint); }
.date-picker-weekdays, .date-picker-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.date-picker-weekdays { margin-bottom: 2px; color: var(--muted); font-size: .625rem; font-weight: 700; text-align: center; text-transform: uppercase; }
.date-picker-grid { gap: 2px; }
.date-picker-day { position: relative; min-width: 0; min-height: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: .8125rem; font-weight: 600; }
.date-picker-day:hover { background: var(--brand-tint); color: var(--brand-ink); }
.date-picker-day.is-outside { color: #9aa1bd; font-weight: 500; }
.date-picker-day.is-today::after { position: absolute; right: 6px; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent-dark); content: ""; }
.date-picker-day.is-preview, .date-picker-day.is-in-range { border-radius: 0; background: #e3e6ff; color: var(--brand-ink); }
.date-picker-day.is-start, .date-picker-day.is-end, .date-picker-day.is-selected { border-radius: 8px; background: var(--action-bg); color: var(--action-text); box-shadow: none; }
.date-picker-day.is-start.is-in-range, .date-picker-day.is-start.is-preview { border-radius: 8px 0 0 8px; }
.date-picker-day.is-end.is-in-range { border-radius: 0 8px 8px 0; }
.date-picker-day.is-start.is-end { border-radius: 8px; }
.date-picker-day.is-preview:last-child { border-radius: 0 8px 8px 0; }
.date-picker-day:active { transform: none; }
.date-picker-today { width: 100%; min-height: 34px; margin-top: 10px; padding: 4px 8px; border-color: var(--line); background: var(--surface-subtle); color: var(--brand-ink); font-size: .75rem; font-weight: 700; }

/* -------------------------------------------------------------------------
   Аналитика
   ---------------------------------------------------------------------- */
.analytics-hero-management { margin-bottom: 18px; }
.analytics-workspace { position: relative; z-index: 2; padding: 24px; }
.analytics-heading { align-items: flex-start; }
.analytics-heading .muted { margin: 4px 0 0; font-size: .8125rem; }
.analytics-filters { align-items: flex-end; }
.analytics-filters > label { flex-basis: 152px; min-width: 152px; }
.analytics-filters .analytics-checkbox { flex: 0 0 auto; }
.analytics-checkbox { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 0; white-space: nowrap; }
.analytics-checkbox span { margin: 0 !important; font-size: .75rem !important; text-transform: none !important; letter-spacing: 0 !important; }
.analytics-checkbox input { flex: 0 0 auto; }
.analytics-advanced { align-self: flex-end; min-width: 128px; padding: 10px 0; color: var(--ink-soft); font-size: .8125rem; }
.analytics-advanced summary { cursor: pointer; font-weight: 600; }
.analytics-advanced[open] { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.analytics-advanced .analytics-checkbox { margin: 10px 0 0; }
.analytics-results { position: relative; z-index: 1; margin-top: 20px; }
.analytics-results.is-updating { cursor: progress; pointer-events: none; }
.analytics-context { margin: 0 0 12px; color: var(--ink-soft); font-size: .8125rem; font-weight: 600; }
.analytics-layout { display: grid; grid-template-columns: minmax(0, 1fr) 248px; gap: 20px; }
.analytics-side { height: max-content; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-subtle); }
.analytics-side h2 { margin-bottom: 14px; font-size: 1rem; }

.analytics-metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.analytics-metrics .metric { min-width: 0; min-height: 112px; padding: 18px; border-radius: var(--radius-md); }
.analytics-metrics .metric::before { display: none; }
.analytics-metrics .metric span { min-height: 32px; line-height: 1.25; letter-spacing: .07em; }
.analytics-metrics .metric strong { display: block; color: var(--ink); font-size: clamp(1.5rem, 2.4vw, 2.1rem); line-height: 1.1; }
.analytics-metrics .metric small { display: block; margin-top: 8px; color: var(--muted); font-size: .75rem; }
.analytics-metrics .metric.delta strong { color: #b4283a; }
.analytics-metrics .metric.delta.negative strong { color: #b4283a; }
.analytics-insights { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .85fr); gap: 18px; margin-bottom: 18px; }
.analytics-panel { padding: 22px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.analytics-insights .analytics-panel { margin-bottom: 0; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; font-size: 1.125rem; }
.panel-heading .eyebrow { margin-bottom: 4px; }
.panel-heading .muted { max-width: 620px; margin: 6px 0 0; font-size: .8125rem; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; color: var(--muted); font-size: .75rem; font-weight: 600; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend-plan, .bar-plan { background: #818cf8; }
.legend-approved, .bar-approved { background: var(--success); }
.delivery-chart { height: 225px; padding: 8px 0 0; border-bottom: 1px solid var(--line); }
.delivery-chart-bars { display: flex; align-items: stretch; height: 100%; gap: 5px; overflow: hidden; }
.delivery-chart-item { display: grid; flex: 1 1 0; min-width: 24px; grid-template-rows: 1fr auto; gap: 7px; color: var(--muted); font-size: .625rem; text-align: center; }
.delivery-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; min-height: 0; }
.delivery-bars i { display: block; width: min(13px, 38%); min-height: 2px; border-radius: 4px 4px 1px 1px; transition: filter 160ms var(--ease); }
.delivery-chart-item:hover .delivery-bars i { filter: brightness(.88); }
.delivery-chart-item span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.customer-bars { display: grid; gap: 15px; padding: 4px 0 0; margin: 0; list-style: none; }
.customer-bars li > div { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; color: var(--ink-soft); font-size: .8125rem; }
.customer-bars li > div span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-bars strong { flex: none; color: var(--ink); font-size: .75rem; }
.customer-bars i { display: block; height: 8px; overflow: hidden; border-radius: 999px; background: #eceef6; }
.customer-bars b { display: block; height: 100%; min-width: 4px; border-radius: inherit; background: var(--brand-light); }
.empty-panel { margin: 12px 0 0; color: var(--muted); font-size: .875rem; }
.attention-panel { border-color: #dfe3f7; background: var(--surface); }
.attention-list { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; }
.attention-list a { display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(130px, .8fr) minmax(120px, .65fr) auto; align-items: center; gap: 16px; padding: 13px 15px; border-top: 1px solid #eef0f6; color: var(--ink-soft); font-size: .8125rem; }
.attention-list a:first-child { border-top: 0; }
.attention-list a:hover { background: var(--surface-tint); color: var(--brand-ink); }
.attention-list a > span:first-child { display: grid; gap: 2px; }
.attention-list small { color: var(--muted); font-size: .72rem; }
.attention-volume { color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.analytics-detail { margin-bottom: 0; }
.analytics-table { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); }
.analytics-table table { min-width: 0; table-layout: fixed; }
.analytics-table th:nth-child(1) { width: 16%; }
.analytics-table th:nth-child(2) { width: 27%; }
.analytics-table th:nth-child(3) { width: 20%; }
.analytics-table th:nth-child(4) { width: 23%; }
.analytics-table th:nth-child(5) { width: 14%; }
.analytics-table th, .analytics-table td { padding: 13px 14px; overflow-wrap: anywhere; }
.row-address { display: -webkit-box; max-width: 100%; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.analytics-table td .volume-flow { display: grid; gap: 3px; color: var(--muted); font-size: .75rem; }
.volume-flow strong { color: var(--ink); }
.group-list { padding: 0; margin: 0; list-style: none; }
.group-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: .8125rem; }
.group-list li:first-child { border-top: 0; }
.group-list strong { color: var(--ink); white-space: nowrap; }

/* -------------------------------------------------------------------------
   AI-агент
   ---------------------------------------------------------------------- */
.agent-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.agent-chat, .agent-safety { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.agent-safety { background: var(--surface-subtle); }
.agent-safety ol { display: grid; gap: 14px; padding-left: 20px; margin: 16px 0; color: var(--ink-soft); font-size: .875rem; line-height: 1.45; }
.agent-safety p { margin-bottom: 0; font-size: .8125rem; line-height: 1.5; }
.agent-message-system { padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-tint); }
.agent-message-system strong { color: var(--ink); font-size: 1rem; }
.agent-message-system p { max-width: 690px; margin: 8px 0 0; color: var(--ink-soft); line-height: 1.55; }
.agent-message { margin-top: 16px; padding: 16px 18px; border-radius: var(--radius-md); }
.agent-message-user { margin-left: 12%; border: 1px solid var(--line); background: var(--surface-subtle); }
.agent-message-answer { margin-right: 4%; border: 1px solid #cfd4f5; background: #f0f2ff; }
.agent-message p { margin: 6px 0 0; color: var(--ink-soft); line-height: 1.55; }
.agent-error { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--danger-line); border-radius: var(--radius-sm); color: #9a2133; background: var(--danger-bg); }
.agent-result { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; }
.agent-result h2 { margin: 4px 0; font-size: 1rem; }
.agent-result .muted { margin: 0; font-size: .8125rem; }
.agent-result-scroll { margin-top: 14px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.agent-result table { width: 100%; min-width: 560px; font-size: .8125rem; }
.agent-result th, .agent-result td { padding: 9px 10px; border-bottom: 1px solid #eceef5; text-align: left; vertical-align: top; }
.agent-result th { color: var(--muted); background: var(--surface-subtle); white-space: nowrap; }
.agent-admin { display: grid; gap: 16px; margin-top: 20px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-subtle); }
.agent-admin h2 { margin: 4px 0 8px; font-size: 1.125rem; }
.agent-admin p { max-width: 850px; margin: 0; }
.agent-admin-form { display: grid; gap: 12px; }
.agent-admin-form textarea { min-height: 210px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8125rem; line-height: 1.45; }
.agent-admin-form .primary { justify-self: start; }
.agent-examples { display: grid; gap: 16px; padding: 20px 0; }
.agent-example-group { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.agent-example-group-fast { border-color: var(--warning-line); background: #fffaea; }
.agent-example-group-ai { background: var(--surface-tint); }
.agent-example-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.agent-example-heading .eyebrow { margin-bottom: 3px; }
.agent-example-heading h2 { margin: 0; font-size: 1rem; }
.agent-example-group > p { margin: 8px 0 14px; color: var(--ink-soft); font-size: .8125rem; line-height: 1.5; }
.agent-example-buttons { display: grid; gap: 8px; }
.agent-example-buttons form { margin: 0; }
.agent-example-buttons button { justify-content: flex-start; padding: 11px 14px; border-color: var(--line); background: rgb(255 255 255 / 80%); color: var(--ink-soft); font-size: .875rem; font-weight: 500; text-align: left; }
.agent-example-buttons form button { width: 100%; }
.agent-example-buttons button:hover { border-color: var(--brand-light); background: #fff; color: var(--brand-ink); }
.quick-report-form { display: grid; gap: 14px; }
.quick-report-controls { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.quick-period-tabs { display: inline-flex; overflow: hidden; height: 42px; border: 1px solid var(--warning-line); border-radius: var(--radius-sm); background: #fff6df; }
.quick-period-tabs button { min-width: 76px; min-height: 0; padding: 8px 12px; border: 0; border-right: 1px solid var(--warning-line); border-radius: 0; background: transparent; color: #6b5316; font-size: .8125rem; }
.quick-period-tabs button:last-child { border-right: 0; }
.quick-period-tabs button:hover { background: #fff; }
.quick-period-tabs button.is-active { color: #4d3a05; background: #fff; box-shadow: inset 0 -2px 0 var(--accent-dark); font-weight: 700; }
.quick-period-field { display: grid; gap: 5px; min-width: 178px; margin: 0; color: #6b5316; font-size: .6875rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.quick-period-field input { height: 42px; min-height: 42px; padding: 8px 10px; border-color: var(--warning-line); background: #fffefa; font-size: .875rem; font-weight: 600; letter-spacing: normal; text-transform: none; }
.quick-period-range { display: flex; align-items: flex-end; gap: 9px; }
.quick-range-dash { padding-bottom: 11px; color: #a07d1a; }
.quick-report-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.quick-report-buttons button { display: grid; justify-content: stretch; gap: 3px; min-height: 66px; padding: 12px 14px; border-color: var(--warning-line); background: rgb(255 255 255 / 80%); color: #4d3a05; text-align: left; }
.quick-report-buttons button span { font-size: .875rem; font-weight: 700; }
.quick-report-buttons button small { color: #76651f; font-size: .75rem; font-weight: 400; line-height: 1.35; }
.quick-report-buttons button:hover { border-color: var(--accent-dark); background: #fff; }
.agent-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 9px; border-radius: 999px; font-size: .6875rem; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.agent-badge-fast { color: #6b5316; border: 1px solid #e3cf86; background: #fff3b8; }
.agent-badge-ai { color: #312e81; border: 1px solid #b9c0f0; background: #e6e9ff; }
.agent-compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; padding-top: 18px; border-top: 1px solid var(--line); }
.agent-compose textarea { min-height: 76px; resize: vertical; }

/* -------------------------------------------------------------------------
   Склад
   ---------------------------------------------------------------------- */
.warehouse-hero { align-items: flex-end; margin: 0 0 20px; }
main > .warehouse-hero { position: relative; z-index: 5; }
.warehouse-date { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 9px; padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface); }
.warehouse-date label, .warehouse-calendar .filter-label { display: block; width: 100%; color: var(--ink-soft); font-size: .75rem; }
.warehouse-date input { min-height: 42px; padding: 8px; border-radius: var(--radius-sm); }
.warehouse-calendar { min-width: 240px; }
.warehouse-calendar .date-picker-popover { left: auto; right: 0; }
.warehouse-date .date-picker-header button { padding: 0; min-height: 32px; }
.warehouse-date .date-picker-day { padding: 0; min-height: 36px; }
.warehouse-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.warehouse-summary > div { display: grid; align-content: start; gap: 6px; min-height: 100px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-xs); }
.warehouse-summary > div > small:first-child { color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.warehouse-summary small { color: var(--muted); font-size: .75rem; line-height: 1.4; }
.warehouse-summary strong { color: var(--ink); font-size: 1.5rem; line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.warehouse-attention { padding: 20px 24px; }
.warehouse-attention h2 { margin: 4px 0 6px; font-size: 1.0625rem; }
.warehouse-attention p { margin: 0 0 12px; color: var(--muted); font-size: .8125rem; }
.warehouse-shortage-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.warehouse-shortage-list a { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(190px, 2fr) auto; align-items: center; gap: 16px; padding: 11px 14px; border: 1px solid var(--danger-line); border-left-width: 4px; border-radius: var(--radius-sm); background: #fffafb; color: var(--ink); }
.warehouse-shortage-list a:hover { border-color: #e29aa6; background: var(--danger-bg); color: var(--ink); }
.warehouse-shortage-list span { color: var(--muted); font-size: .8rem; }
.warehouse-shortage-list b { color: var(--danger); white-space: nowrap; }
.warehouse-content { padding: 24px; }
.warehouse-intro { display: flex; justify-content: space-between; gap: 16px; }
.warehouse-intro h2 { margin: 0 0 6px; }
.warehouse-intro p { margin: 0 0 12px; color: var(--muted); font-size: .8125rem; }
.warehouse-readonly { align-self: flex-start; padding: 5px 12px; border-radius: 999px; background: var(--surface-tint); color: var(--muted); font-size: .8125rem; font-weight: 600; }
.warehouse-group { margin: 0; color: var(--brand-ink); font-size: 1rem; }
.warehouse-group-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.warehouse-group-totals { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .8rem; }
.warehouse-items { display: grid; gap: 10px; }
.warehouse-item { display: grid; grid-template-columns: minmax(150px, 1.15fr) minmax(170px, 1fr) minmax(260px, 1.7fr) minmax(170px, 1fr); align-items: center; gap: 18px; padding: 16px; scroll-margin-top: 88px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-subtle); }
.warehouse-item:target { border-color: var(--brand-light); box-shadow: var(--ring); }
.warehouse-product, .warehouse-plan, .warehouse-result { display: grid; gap: 5px; }
.warehouse-product small, .warehouse-plan small, .warehouse-result small { color: var(--muted); font-size: .75rem; }
.warehouse-plan span, .warehouse-result span { display: flex; justify-content: space-between; gap: 10px; font-size: .8125rem; }
.warehouse-plan b, .warehouse-result b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.warehouse-entry { display: grid; grid-template-columns: 1fr 1fr; align-items: end; gap: 8px; }
.warehouse-entry label { display: grid; gap: 5px; margin: 0; color: var(--muted); font-size: .75rem; }
.warehouse-entry input { min-width: 0; min-height: 40px; padding: 7px 10px; background: #fffdf6; color: var(--ink); }
.warehouse-entry button { min-height: 40px; padding: 7px 12px; }
.warehouse-entry button:disabled { opacity: .65; cursor: wait; }
.warehouse-entry .warehouse-clear { background: transparent; color: var(--muted); box-shadow: none; }
.warehouse-entry .warehouse-clear:hover { border-color: #a3a9c4; background: var(--surface-tint); color: var(--brand-ink); }
.warehouse-feedback { grid-column: 1 / -1; min-height: 1.2em; color: var(--success); font-size: .75rem; }
.warehouse-feedback.warehouse-error { color: var(--danger); }
.warehouse-static { display: flex; gap: 16px; font-size: .8125rem; }
.warehouse-negative, .warehouse-alert { color: var(--danger); }
.warehouse-alert { font-weight: 700; }

.dispatch-workspace { position: relative; z-index: 6; margin-bottom: 20px; }
.dispatch-filters .date-filter { max-width: 340px; }
.dispatch-filters > label { flex: 0 1 260px; }
.dispatch-orders { position: relative; z-index: 1; }
.dispatch-order .section-heading { align-items: flex-start; margin-bottom: 12px; }
.dispatch-order h2 { margin: 4px 0 0; font-size: 1.0625rem; line-height: 1.4; }
.dispatch-order-state { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.dispatch-pending { font-size: .8125rem; }
.dispatch-lines summary { cursor: pointer; color: var(--ink-soft); font-size: .875rem; font-weight: 600; }
.dispatch-lines .table-wrap { margin-top: 14px; }

.versions-card { margin-bottom: 0; }

/* Исправления сохранённого этапа — в заголовке состава заявки */
.stage-amendments { margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.stage-amendments > summary { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; list-style: none; color: var(--ink-soft); }
.stage-amendments > summary::-webkit-details-marker { display: none; }
.stage-amendments > summary > span:first-child { color: var(--brand); font-size: 1.25rem; }
.stage-amendments > summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 1.25rem; }
.stage-amendments[open] > summary::after { content: "−"; }
.stage-amendments > summary:hover { background: var(--surface-subtle); border-radius: var(--radius-md); }
.stage-amendments strong, .stage-amendments small { display: block; }
.stage-amendments strong { font-weight: 700; }
.stage-amendments small { margin-top: 3px; color: var(--muted); font-size: .75rem; line-height: 1.35; }
.stage-amendment-options { display: grid; gap: 8px; padding: 0 16px 16px; }
.stage-amendment-options p { margin: 0 0 4px; font-size: .75rem; }
.order-card .stage-amendments { position: relative; margin: 0; flex-shrink: 0; }
.order-card .stage-amendments > summary { padding: 9px 14px; }
.order-card .stage-amendments > summary small, .order-card .stage-amendments > summary::after { display: none; }
.order-card .stage-amendment-options { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: 300px; max-width: calc(100vw - 64px); padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-lg); }

/* -------------------------------------------------------------------------
   Адаптив
   ---------------------------------------------------------------------- */
@media (max-width: 1120px) {
  .analytics-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .analytics-insights, .analytics-layout, .agent-workspace { grid-template-columns: 1fr; }
  .analytics-side { display: none; }
  .warehouse-item { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid > div:last-child { grid-column: 1 / -1; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .analytics-filters > label, .analytics-advanced { width: 100%; }
  .analytics-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-metrics .metric:last-child { grid-column: 1 / -1; }
  .attention-list a { grid-template-columns: 1fr auto; gap: 8px 12px; }
  .attention-list a > span:nth-child(2), .attention-list a > span:nth-child(3) { grid-column: 1 / -1; }
  .analytics-table, .analytics-table table, .analytics-table tbody, .analytics-table tr, .analytics-table td { display: block; width: 100%; }
  .analytics-table thead { display: none; }
  .analytics-table tr { padding: 12px 14px; border-top: 1px solid var(--line); }
  .analytics-table tr:first-child { border-top: 0; }
  .analytics-table td { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; padding: 7px 0; border: 0; }
  .analytics-table td::before { content: attr(data-label); color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
  .analytics-table td .volume-flow { grid-template-columns: 1fr; }

  /* Список заявок: карточки вместо горизонтального скролла */
  .order-table { overflow: visible; border: 0; background: transparent; }
  .order-table table, .order-table tbody, .order-table tr, .order-table td { display: block; width: 100%; min-width: 0; }
  .order-table thead { display: none; }
  .order-table tr { padding: 14px 16px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-xs); }
  .order-table td { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; padding: 6px 0; border: 0; }
  .order-table .order-cell-value { min-width: 0; overflow-wrap: anywhere; }
  .order-table .order-cell-value .badge { max-width: 100%; white-space: normal; }
  .order-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; align-self: center; }
  .order-table td:not([data-label]) { display: block; }
  .order-table .row-actions { justify-content: space-between; padding-top: 6px; border-top: 1px solid var(--line); }
  .table-wrap:has(.empty) tr { padding: 0; border: 0; box-shadow: none; }
}
@media (max-width: 680px) {
  .warehouse-hero { display: block; padding: 20px; }
  .warehouse-date { margin-top: 16px; }
  .warehouse-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .warehouse-item { grid-template-columns: 1fr; }
  .warehouse-shortage-list a { grid-template-columns: 1fr auto; }
  .warehouse-shortage-list span { grid-column: 1 / -1; grid-row: 2; }
  .warehouse-calendar .date-picker-popover { left: 50%; right: auto; transform: translate(-50%, -50%); }
}
@media (max-width: 640px) {
  main { padding: 20px 16px 40px; }
  footer { padding: 16px; }
  .dashboard-hero, .analytics-hero, .agent-hero { align-items: stretch; flex-direction: column; padding: 22px; }
  .dashboard-hero h1 { font-size: 1.875rem; }
  .hero-actions { width: 100%; }
  .hero-action, .hero-actions .button { flex: 1 1 100%; width: 100%; }
  .analytics-hero-note, .agent-status { min-width: 0; }
  .metrics { gap: 10px; }
  .metric { min-height: 88px; padding: 14px 14px 14px 18px; }
  .metric strong { font-size: 1.5rem; }
  .workspace, .card, .analytics-workspace { padding: 16px; }
  .filters { padding: 12px; }
  .filters label, .filters .date-filter { flex-basis: 100%; max-width: none; min-width: 0; width: 100%; }
  .filters button, .filters .reset { width: 100%; }
  .order-top, .page-heading, .section-heading, .action-footer { align-items: stretch; flex-direction: column; }
  .order-top > .badge, .page-heading > .badge { align-self: flex-start; }
  .facts, .form-grid { grid-template-columns: 1fr; }
  .flow-card { padding: 14px; }
  .flow-step { min-width: 160px; }
  .line-row { grid-template-columns: 1fr; gap: 12px; }
  .remove { padding-bottom: 0; }
  .save-bar { position: static; padding: 14px; }
  .save-bar p, .save-bar button { width: 100%; }
  .action-footer .button, .action-footer button { width: 100%; }
  .order-card > .section-heading { align-items: flex-start; flex-wrap: wrap; flex-direction: row; }
  .order-card .stage-amendment-options { right: auto; left: 0; }
  .agent-chat, .agent-safety { padding: 18px; }
  .agent-compose { grid-template-columns: 1fr; }
  .agent-message-user { margin-left: 0; }
  .quick-report-buttons { grid-template-columns: 1fr; }
  .quick-report-controls { align-items: stretch; flex-direction: column; }
  .quick-period-tabs { align-self: flex-start; }
  .quick-period-range { align-items: stretch; flex-direction: column; }
  .quick-range-dash { display: none; }
  .date-filter, .filters .date-filter { flex-basis: 100%; max-width: none; }
  .date-picker-popover { position: fixed; top: 50%; left: 50%; width: min(336px, calc(100vw - 32px)); transform: translate(-50%, -50%); }
  .date-picker-popover::before { position: fixed; z-index: -1; inset: -200vmax; background: rgb(18 23 38 / 35%); content: ""; }
  .dispatch-filters .date-filter { min-width: 0; max-width: none; width: 100%; }
  .dispatch-filters > label { flex-basis: 100%; }
  .dispatch-order .dispatch-label { align-self: flex-start; }
  .catalog-confirm-actions, .quick-catalog-actions { flex-direction: column-reverse; }
}
@media (max-width: 500px) {
  .analytics-panel { padding: 18px; }
  .analytics-metrics .metric { padding: 14px; }
  .analytics-metrics .metric span { min-height: 42px; }
  .panel-heading { flex-direction: column; }
  .chart-legend { justify-content: flex-start; }
  .delivery-chart { height: 190px; }
  .delivery-chart-item:nth-child(n+15) { display: none; }
}

/* Планшет и телефон: боковая панель превращается в верхнюю полосу */
@media (max-width: 900px) {
  body { padding-left: 0; }
  .top { position: sticky; inset: auto; top: 0; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; font-size: 1.0625rem; }
  .mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-sub { display: none; }
  .top nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .top nav > a, .admin-nav summary { white-space: nowrap; padding: 9px 12px; }
  .admin-nav { position: relative; align-self: center; }
  .admin-nav-links { position: fixed; z-index: 45; top: auto; left: 16px; right: 16px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-lg); }
  .account { margin: 0 0 0 auto; padding: 4px 4px 4px 12px; background: transparent; }
}
@media (max-width: 640px) { .account-name { display: none; } }

@media (forced-colors: active) {
  .badge { border: 1px solid CanvasText; }
  .primary, .hero-action { border: 1px solid ButtonText; }
}
@media print {
  .top, footer, .save-bar, .skip-link, .back { display: none !important; }
  body { padding-left: 0; background: #fff; }
  .card, .workspace, .metric { box-shadow: none; }
}

/* Native checkbox controls: the form owns state and saving. */
.switch-field, .order-classification > .switch-field { align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.switch-control { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 46px; }
.switch-control input[type="checkbox"] { position: absolute; inset: -9px 0; z-index: 1; width: 46px; height: 44px; margin: 0; opacity: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; border: 1px solid #8790a7; border-radius: 999px; background: #8790a7; pointer-events: none; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); }
.switch-control input:checked + .switch-track { border-color: var(--action-bg); background: var(--action-bg); }
.switch-control input:checked + .switch-track::after { transform: translateX(20px); }
.switch-control input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 3px; }
.switch-control input:disabled { cursor: not-allowed; }
.switch-control:has(input:disabled) { opacity: .55; }
.switch-field:has(input:disabled) { cursor: not-allowed; }
#order-form .line-row, #recurring-form .line-row { gap: 14px; padding: 16px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-subtle); }
#order-form #lines > .line-row:first-child, #recurring-form #lines > .line-row:first-child { padding-top: 16px; border-top: 1px solid var(--line); }
#order-form .line-row > div, #recurring-form .line-row > div { min-width: 0; }
#order-form .line-row .remove, #recurring-form .line-row .remove { min-height: 44px; padding: 9px 0; color: var(--ink-soft); cursor: pointer; }
@media (forced-colors: active) {
  .switch-track { border: 1px solid ButtonText; background: Canvas; }
  .switch-track::after { background: ButtonText; }
  .switch-control input:checked + .switch-track { background: Highlight; border-color: Highlight; }
  .switch-control input:checked + .switch-track::after { background: HighlightText; }
}
