/* === Design Tokens === */
:root {
  --color-bg: #edf1f7;
  --color-surface: #ffffff;
  --color-surface-alt: #fafbfc;
  --color-text: #1a1a1a;
  --color-text-muted: #64748b;
  --color-text-soft: #475569;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-soft: rgba(37,99,235,.12);
  --color-success: #16a34a;
  --color-success-soft: #dcfce7;
  --color-danger: #dc2626;
  --color-danger-soft: #fef2f2;
  --color-warning: #d97706;
  --color-navbar-bg: #0f172a;
  --color-navbar-fg: #94a3b8;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.4);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-7: 32px;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: var(--font-sans); font-size: 14px; color: var(--color-text); background: var(--color-bg); }

/* === Navbar === */
.navbar { background: var(--color-navbar-bg); color: #fff; padding: 0 var(--space-7); display: flex; align-items: center; gap: var(--space-2); height: 56px; box-shadow: 0 2px 8px rgba(0,0,0,.15); position: sticky; top: 0; z-index: 100; }
.navbar .brand { font-weight: 700; font-size: 17px; color: #fff; text-decoration: none; margin-right: var(--space-6); letter-spacing: -.02em; }
.navbar-links { display: contents; }
.navbar-toggle { display: none; }
.navbar-mobile-footer { display: none; }
.navbar a { color: var(--color-navbar-fg); text-decoration: none; font-size: 14px; padding: var(--space-2) 14px; border-radius: var(--radius-sm); transition: all .15s; font-weight: 500; }
.navbar a:hover { color: #fff; background: rgba(255,255,255,.08); }
.navbar a.active { color: #fff; background: rgba(255,255,255,.12); }
.navbar a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.navbar-spacer { flex: 1; }
.navbar-user { color: #cbd5e1; font-size: 13px; }
.navbar form { display: inline; }
.navbar .btn-sm { color: #cbd5e1; border-color: #475569; background: transparent; }
.navbar .btn-sm:hover { color: #fff; border-color: #94a3b8; }

/* === Container === */
.container { max-width: 1200px; margin: 0 auto; padding: 28px var(--space-6); }

/* === Page header === */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.page-header h1 { font-size: 24px; font-weight: 700; color: var(--color-navbar-bg); letter-spacing: -.02em; }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--color-border-strong); background: var(--color-surface); color: #374151; cursor: pointer; font-size: 13px; font-weight: 500; text-decoration: none; transition: all .15s; }
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); box-shadow: 0 1px 3px rgba(37,99,235,.3); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); box-shadow: 0 2px 6px rgba(37,99,235,.35); }
.btn-primary:active { background: #1e40af; border-color: #1e40af; }
.btn-danger { background: var(--color-surface); color: var(--color-danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--color-danger-soft); border-color: #f87171; }
.btn-sm { padding: 5px var(--space-3); font-size: 12px; border-radius: var(--radius-sm); }

/* Inline Lucide-style icons */
.icon { width: 1em; height: 1em; flex-shrink: 0; display: inline-block; vertical-align: -2px; }
.btn .icon, .btn-sm .icon { width: 14px; height: 14px; }
.btn-primary .icon { width: 16px; height: 16px; }
.password-toggle .icon { width: 18px; height: 18px; }

/* === Table === */
.table { width: 100%; background: var(--color-surface); border-radius: var(--radius-lg); border-collapse: collapse; box-shadow: var(--shadow-sm); overflow: hidden; }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid #f1f5f9; }
.table th { font-weight: 600; color: var(--color-text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; background: var(--color-surface-alt); }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:not(.category-header-row):hover td { background: #f8fafc; }
.actions { text-align: right; vertical-align: middle; white-space: nowrap; }
.actions form { display: inline-block; }
.actions > * + *, .actions form + form, .actions form + .btn, .actions .btn + form { margin-left: 6px; }
.table input[type='text'], .table input[type='url'], .table input[type='email'], .table input[type='number'], .table input[type='search'] { border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); padding: 7px 10px; font-size: 13px; font-family: inherit; background: var(--color-surface); color: var(--color-text); transition: all .15s; width: 100%; max-width: 280px; }
.table input[type='text']:focus, .table input[type='url']:focus, .table input[type='email']:focus, .table input[type='number']:focus, .table input[type='search']:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }

/* === Form === */
.form { background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-7); box-shadow: var(--shadow-sm); max-width: 720px; }
.form--panel { max-width: 1100px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.form-group label { font-weight: 500; font-size: 13px; color: #374151; }
.form-group input, .form-group select, .form-group textarea { border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); padding: 9px var(--space-3); font-size: 14px; width: 100%; transition: all .15s; background: var(--color-surface); color: var(--color-text); font-family: inherit; }
.form-group select { appearance: none; -webkit-appearance: none; -moz-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }
.form-group select::-ms-expand { display: none; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.form-group.checkbox { flex-direction: row; align-items: center; gap: var(--space-2); }
.form-group.checkbox input { width: auto; }
.form-group input[type='checkbox'], .form-group input[type='radio'] { width: auto; padding: 0; border: 0; background: none; box-shadow: none; cursor: pointer; accent-color: var(--color-primary); }
.form-group > label:has(> input[type='checkbox']), .form-group > label:has(> input[type='radio']) { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-weight: 500; }
.hint { font-weight: 400; color: var(--color-text-muted); font-size: 11px; display: block; }

.form-group.has-error input, .form-group.has-error select, .form-group.has-error textarea { border-color: var(--color-danger); box-shadow: 0 0 0 3px rgba(220,38,38,.1); }
.form-group.has-error label { color: var(--color-danger); }
.field-error { color: var(--color-danger); font-size: 12px; margin-top: var(--space-1); display: block; }
.form-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-5); }

/* Input with toggle button (e.g. show/hide password) */
.input-with-toggle { position: relative; display: block; }
.input-with-toggle > input { padding-right: 42px; }
.input-with-toggle > .password-toggle { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer; color: var(--color-text-muted); padding: 0; transition: color .15s, background .15s; }
.password-toggle:hover { color: var(--color-text); background: var(--color-surface-alt); }
.password-toggle:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle.is-showing { color: var(--color-primary); }
.password-toggle.is-showing .icon-eye { display: none; }
.password-toggle.is-showing .icon-eye-off { display: inline; }

/* === JSON editor === */
.json-editor { font-family: var(--font-mono); font-size: 13px; }
.error-msg { color: #ef4444; font-size: 12px; margin-top: var(--space-1); min-height: 16px; }

/* === Filters === */
.filters { display: flex; gap: var(--space-3); margin-bottom: var(--space-5); }
.filters select, .toolbar select { border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); padding: 9px 14px; font-size: 14px; background: var(--color-surface); color: var(--color-text); transition: all .15s; cursor: pointer; min-width: 170px; appearance: none; -webkit-appearance: none; -moz-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; line-height: 1.4; }
.filters select:hover, .toolbar select:hover { border-color: var(--color-border-strong); background-color: var(--color-surface-alt); }
.filters select:focus, .toolbar select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.filters select::-ms-expand, .toolbar select::-ms-expand { display: none; }

/* === Toolbar === */
.toolbar { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); align-items: center; flex-wrap: wrap; }
.search-input { position: relative; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); padding: 9px var(--space-3) 9px 36px; font-size: 14px; background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'/%3E%3C/svg%3E") no-repeat 12px center; transition: all .15s; min-width: 220px; }
.search-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }

/* === Images === */
.shop-logo { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; margin-right: 6px; }
.product-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: var(--radius-sm); vertical-align: middle; margin-right: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* === Category tree === */
.table tr.category-root td { font-weight: 600; }

/* === Table scroll wrapper (desktop) — sticky thead, internal scroll === */
@media (min-width: 901px) {
  .table-scroll {
    max-height: calc(100vh - 200px);
    overflow: auto;
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    overscroll-behavior: contain;
  }
  /* Reset the table's own clipping/collapse so sticky <th> can work reliably */
  .table-scroll > .table {
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    border-collapse: separate;
    border-spacing: 0;
  }
  .table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    /* sticky cells need their own bg — thead is otherwise transparent */
    background: var(--color-surface-alt);
    /* border-collapse: separate loses td border-bottom merging — restore via inset shadow */
    box-shadow: inset 0 -1px 0 var(--color-border);
  }
  /* Category group headers inside tbody — pin below thead while scrolling */
  .table-scroll tr.category-header-root td,
  .table-scroll tr.category-header-child td {
    position: sticky;
    z-index: 1;
  }
  .table-scroll tr.category-header-root td { top: 33px; }
  .table-scroll tr.category-header-child td { top: 62px; }
}

.table tr.category-header-row td { padding: 0; border-bottom: none; }
.table tr.category-header-row:hover td { background: transparent; }

.category-label { display: inline-block; font-weight: 600; }

.table tr.category-header-root td {
  padding: 14px var(--space-4) 10px;
  background: #e8edf6;
  border-bottom: 2px solid #dae0ed;
}
.table tr.category-header-root:not(:first-child) td { padding-top: 28px; }
.table tr.category-header-root .category-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-navbar-bg);
  text-transform: uppercase;
  letter-spacing: .06em;
  position: relative;
  padding-left: 14px;
}
.table tr.category-header-root .category-label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 1px;
  bottom: 1px;
  width: 4px;
  border-radius: 2px;
  background: var(--color-primary);
}

.table tr.category-header-child td {
  padding: var(--space-2) var(--space-4) 6px;
  background: #f2f5fb;
  border-bottom: 1px solid #e4e9f2;
}
.table tr.category-header-child .category-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-soft);
  background: #dce4f5;
  padding: 3px var(--space-3);
  border-radius: var(--radius-sm);
  letter-spacing: .01em;
}

/* === Status badge === */
.status-badge { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; }
.status-active { background: var(--color-success-soft); color: var(--color-success); }
.status-inactive { background: #f1f5f9; color: #94a3b8; }

/* === Status pill === */
.status-pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; border: 1px solid transparent; background: transparent; font-family: inherit; }
.status-pill.is-active { background: var(--color-success-soft); color: var(--color-success); border-color: rgba(22,163,74,.2); }
.status-pill.is-inactive { background: #f1f5f9; color: var(--color-text-muted); border-color: var(--color-border); }
.variant-count-badge { display: inline-block; padding: 2px 8px; background: #f1f5f9; border-radius: 12px; font-size: 12px; color: #475569; }
.muted { color: #94a3b8; }
/* When rendered as interactive element (button/link), restore feedback */
button.status-pill, a.status-pill { cursor: pointer; transition: opacity .15s; }
button.status-pill:hover, a.status-pill:hover { opacity: .8; }
button.status-pill:focus-visible, a.status-pill:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* === Image gallery (Antd/shadcn picture-card style) === */
.image-gallery { display: flex; flex-wrap: wrap; gap: var(--space-3); min-height: 104px; align-items: flex-start; }

.gallery-item {
  position: relative;
  width: 104px; height: 104px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.gallery-item:hover { border-color: var(--color-border-strong); }
/* First item = main — primary outline */
.gallery-item.is-main,
.gallery-item:first-child {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.gallery-item a { display: block; width: 100%; height: 100%; cursor: zoom-in; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* "Главное" — tiny corner indicator (star ribbon top-left), no text overlap */
.gallery-main-badge {
  position: absolute; top: 0; left: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--color-primary); color: #fff;
  border-radius: 0 0 var(--radius-md) 0;
  pointer-events: none;
  z-index: 3;
}
.gallery-main-badge svg { width: 11px; height: 11px; }
.gallery-main-badge .badge-text { display: none; }

/* Hover overlay with action buttons (centered, like Antd picture-card) */
.gallery-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 6px;
  background: rgba(15, 23, 42, .55);
  opacity: 0;
  transition: opacity .15s;
  z-index: 2;
  pointer-events: none;
}
.gallery-item:hover .gallery-overlay,
.gallery-item:focus-within .gallery-overlay { opacity: 1; pointer-events: auto; }

.gallery-action-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.92);
  color: #1f2937;
  border: 0; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .15s;
}
.gallery-action-btn:hover { background: #fff; transform: scale(1.08); }
.gallery-action-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.gallery-action-btn .icon { width: 14px; height: 14px; }
.gallery-action-btn.is-danger:hover { background: var(--color-danger); color: #fff; }
.gallery-action-btn.is-primary:hover { background: var(--color-primary); color: #fff; }
.gallery-item:first-child .gallery-action-btn.action-set-main { display: none; }

/* Drag handle — small grip badge top-right, visible on hover */
.drag-handle {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(15,23,42,.6); color: #fff;
  border-radius: var(--radius-sm);
  cursor: grab; user-select: none;
  padding: 0;
  opacity: 0;
  transition: opacity .15s;
  z-index: 3;
  backdrop-filter: blur(4px);
}
.gallery-item:hover .drag-handle { opacity: 1; }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 12px; height: 12px; }

.gallery-item.sortable-ghost { opacity: .35; }
.gallery-item.sortable-drag { box-shadow: var(--shadow-md); transform: scale(1.04); border-color: var(--color-primary); }

/* Upload tile — dashed placeholder at end of gallery */
.upload-tile {
  width: 104px; height: 104px; flex-shrink: 0;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px;
  font-size: 12px; font-weight: 500;
  cursor: pointer; padding: 0;
  font-family: inherit;
  transition: border-color .15s, color .15s, background .15s;
}
.upload-tile:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-soft);
}
.upload-tile:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.upload-tile .icon { width: 22px; height: 22px; }

.gallery-actions { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
#image-upload-status { font-size: 12px; color: var(--color-text-muted); }

/* === Image lightbox === */
.lightbox-overlay { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.75); align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.lightbox-overlay.active { display: flex; }
.lightbox-overlay img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }
.lightbox-close { position: absolute; top: var(--space-4); right: var(--space-6); background: none; border: none; color: #fff; font-size: 36px; cursor: pointer; line-height: 1; }

/* === Dashboard === */
.admin-dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-5); margin-top: var(--space-6); }
.dashboard-card { display: block; padding: var(--space-7) var(--space-6); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); text-decoration: none; color: inherit; cursor: pointer; transition: all .2s; }
.dashboard-card:hover { border-color: var(--color-primary); box-shadow: 0 4px 16px rgba(37,99,235,.12); transform: translateY(-2px); }
.dashboard-card h2 { margin: 0 0 var(--space-2); font-size: 18px; color: var(--color-text); }
.dashboard-card p { margin: 0; font-size: 14px; color: var(--color-text-muted); }
.dashboard-card .stat-value { font-size: 28px; font-weight: 700; color: var(--color-text); display: block; line-height: 1.2; }
.dashboard-card .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted); font-weight: 600; display: block; margin-bottom: var(--space-2); }
.dashboard-card .stat-delta { font-size: 12px; color: var(--color-text-muted); display: block; margin-top: var(--space-1); }

/* === Tabs === */
.tabs { display: flex; border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-5); }
.tab { display: inline-block; padding: 10px var(--space-4); border: none; background: transparent; border-bottom: 2px solid transparent; color: var(--color-text-soft); font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; transition: all .15s; font-family: inherit; }
.tab:hover { background: var(--color-surface-alt); }
.tab.active { border-bottom-color: var(--color-primary); color: var(--color-primary); }
.tab:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === Sticky save bar === */
.sticky-save-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-6);
  box-shadow: 0 -2px 8px rgba(0,0,0,.04);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  z-index: 50;
  margin-top: var(--space-6);
  margin-left: calc(-1 * var(--space-7));
  margin-right: calc(-1 * var(--space-7));
  margin-bottom: calc(-1 * var(--space-7));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.sticky-save-bar .save-status { margin-right: auto; font-size: 13px; color: var(--color-text-muted); align-self: center; }

/* === Form as panel (desktop): internal scroll, pinned tabs + save bar === */
@media (min-width: 901px) {
  .form--panel {
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Viewport minus: navbar (56) + container padding-top (28) + page-header (~52) + container padding-bottom (28) + safety (4) */
    max-height: calc(100vh - 168px);
    /* Reserve a workable height so short tabs (e.g. Варианты) don't collapse
       the body and clip the absolutely-positioned axis suggestions dropdown */
    min-height: min(560px, calc(100vh - 168px));
    overflow: hidden;
  }
  .form--panel > .tabs {
    margin: 0;
    padding: var(--space-5) var(--space-7) 0;
    flex-shrink: 0;
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .form--panel > .form-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-6) var(--space-7);
    min-height: 0;
  }
  .form--panel > .sticky-save-bar {
    position: static;
    margin: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-shrink: 0;
  }
}

/* === Toasts === */
.toast-container { position: fixed; top: var(--space-4); right: var(--space-4); z-index: 2000; display: flex; flex-direction: column; gap: var(--space-2); pointer-events: none; }
.toast { background: var(--color-surface); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); box-shadow: 0 4px 12px rgba(0,0,0,.15); border-left: 4px solid var(--color-primary); min-width: 240px; font-size: 13px; pointer-events: auto; animation: slide-in .2s ease-out; }
.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.fade-out { animation: fade-out .25s ease-in forwards; }

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fade-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* === Pagination === */
.pagination { display: flex; gap: 6px; justify-content: center; margin: var(--space-6) 0; align-items: center; }
.pagination a, .pagination span { display: inline-flex; min-width: 32px; height: 32px; padding: 0 10px; align-items: center; justify-content: center; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 13px; color: var(--color-text-soft); text-decoration: none; background: var(--color-surface); }
.pagination a:hover { background: var(--color-surface-alt); border-color: var(--color-border-strong); }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination .disabled { opacity: .4; pointer-events: none; }
.pagination .info { border: none; background: none; color: var(--color-text-muted); font-size: 12px; }

/* === Skeleton === */
.skeleton { background: linear-gradient(90deg, #f1f5f9, #e2e8f0, #f1f5f9); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--space-1); }
.skeleton-text { height: 12px; width: 100%; margin: var(--space-1) 0; }
@keyframes shimmer {
  from { background-position: 0% 0; }
  to { background-position: -200% 0; }
}

/* === Login === */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: var(--space-6); }
.login-card { width: 100%; max-width: 400px; }
.login-header { text-align: center; margin-bottom: var(--space-6); }
.login-logo { width: 48px; height: 48px; margin: 0 auto var(--space-4); background: #1e293b; color: #fff; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; }
.login-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: #111827; }
.login-subtitle { font-size: 14px; color: var(--color-text-muted); }
.login-body { background: var(--color-surface); border-radius: var(--radius-md); padding: var(--space-7); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.login-body .form-group input { height: 42px; }
.login-btn { width: 100%; height: 42px; font-size: 14px; font-weight: 500; margin-top: var(--space-1); }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: var(--space-4); font-size: 13px; }
.alert-danger { background: var(--color-danger-soft); color: var(--color-danger); border: 1px solid #fecaca; }

/* === Error banner === */
.error-banner { padding: 10px 14px; border-radius: var(--radius-md); margin-bottom: var(--space-4); font-size: 13px; background: var(--color-danger-soft); color: var(--color-danger); border: 1px solid #fecaca; }

/* === Autocomplete === */
.autocomplete-list { list-style: none; margin: 0; padding: var(--space-1) 0; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); max-height: 240px; overflow-y: auto; }
.autocomplete-list li { padding: var(--space-2) var(--space-3); cursor: pointer; font-size: 13px; color: #374151; }
.autocomplete-list li:hover { background: #f1f5f9; }
.autocomplete-empty { padding: var(--space-2) var(--space-3); font-size: 12px; color: #94a3b8; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }

/* === Attribute rows === */
.attribute-row { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .5rem; position: relative; }
.attribute-row > input { flex: 1; }
.attribute-row > .attribute-suggestions { position: absolute; top: 100%; left: 0; right: 0; z-index: 10; background: white; }

/* Styled tooltip via data-tooltip attribute (lazy: only shows on hover or focus) */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}
[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--color-text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 1000;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-tooltip]:hover::before, [data-tooltip]:focus-visible::before { opacity: 1; }
/* Suppress native title on tooltip-enabled elements to avoid double tooltip */
[data-tooltip] { /* keep title attr — screen readers still read it; CSS tooltip is purely visual */ }
/* Hide CSS tooltip on touch devices (hover doesn't make sense) */
@media (hover: none) { [data-tooltip]::after, [data-tooltip]::before { display: none; } }

/* === Responsive (mobile + tablet, up to 900px) === */
@media (max-width: 900px) {
  .container { padding: var(--space-4) var(--space-3); }

  /* Navbar — burger menu opens a dropdown panel */
  .navbar { padding: 0 var(--space-3); gap: var(--space-2); height: 52px; position: sticky; top: 0; }
  .navbar .brand { margin-right: auto; font-size: 15px; flex-shrink: 0; }
  .navbar-spacer { display: none; }
  .navbar-user { display: none; }
  .navbar form.navbar-logout-desktop { display: none; }

  /* Burger button */
  .navbar-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    background: transparent; border: 1px solid rgba(255,255,255,.12);
    border-radius: var(--radius-md);
    cursor: pointer; padding: 0;
    transition: background .15s, border-color .15s;
  }
  .navbar-toggle:hover, .navbar-toggle.open { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.24); }
  .navbar-toggle-icon, .navbar-toggle-icon::before, .navbar-toggle-icon::after {
    display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px; transition: transform .2s, opacity .2s;
  }
  .navbar-toggle-icon { position: relative; }
  .navbar-toggle-icon::before { content: ''; position: absolute; top: -6px; left: 0; }
  .navbar-toggle-icon::after  { content: ''; position: absolute; top:  6px; left: 0; }
  .navbar-toggle.open .navbar-toggle-icon { background: transparent; }
  .navbar-toggle.open .navbar-toggle-icon::before { transform: translateY(6px) rotate(45deg); }
  .navbar-toggle.open .navbar-toggle-icon::after  { transform: translateY(-6px) rotate(-45deg); }

  /* Dropdown panel */
  .navbar-links {
    display: none;
    position: absolute; top: 52px; left: 0; right: 0;
    flex-direction: column;
    background: var(--color-navbar-bg);
    padding: var(--space-2);
    box-shadow: 0 8px 16px rgba(0,0,0,.25);
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 99;
  }
  .navbar-links.open { display: flex; }
  .navbar-links a {
    padding: 12px var(--space-3); font-size: 15px; border-radius: var(--radius-md);
    color: #cbd5e1;
  }
  .navbar-links a.active { background: rgba(255,255,255,.1); color: #fff; }

  /* Mobile footer inside dropdown: user + logout */
  .navbar-mobile-footer {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: var(--space-2); padding-top: var(--space-3);
    border-top: 1px solid rgba(255,255,255,.08);
    gap: var(--space-3);
  }
  .navbar-user-mobile { color: #cbd5e1; font-size: 13px; padding: 0 var(--space-3); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .navbar-mobile-footer form { flex-shrink: 0; }

  /* Page header — buttons aligned right and sized to content, not stretched */
  .page-header { flex-wrap: wrap; gap: var(--space-3); align-items: center; }
  .page-header h1 { font-size: 20px; flex: 1 1 auto; min-width: 0; }
  .page-header > .btn, .page-header > a.btn { flex: 0 0 auto; align-self: center; }

  /* Toolbar */
  .filters, .toolbar { flex-direction: column; align-items: stretch; }
  .filters select, .toolbar select, .toolbar .search-input { width: 100%; min-width: 0; }

  /* Form */
  .form { padding: var(--space-4); }
  .form-row { grid-template-columns: 1fr; }

  /* Tables — base + per-table column hiding to keep them readable.
     We hide low-information columns on small screens; the row stays compact. */
  .table { font-size: 12px; }
  .table th, .table td { padding: var(--space-2) 8px; }
  .table .actions { gap: 4px; flex-wrap: wrap; }

  /* Products list — card layout on mobile.
     Table structure (6 cols): 1=ID, 2=Название, 3=Цена, 4=Магазин, 5=Статус, 6=Actions.
     thead hidden; each row becomes a card; only key cells render. */
  #products-list { background: transparent; box-shadow: none; border-radius: 0; }
  #products-list thead { display: none; }
  #products-list tbody { display: block; }
  #products-list tbody tr.category-header-row {
    display: block; background: transparent; padding: 0;
    margin: var(--space-3) 0 var(--space-1);
    border-bottom: 0;
  }
  #products-list tbody tr.category-header-row td {
    display: block; padding: 0; border: 0; background: transparent;
  }
  #products-list tbody tr:not(.category-header-row) {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "title status"
      "price actions";
    gap: 4px var(--space-3);
    align-items: center;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    border-bottom: 0;
  }
  #products-list tbody tr:not(.category-header-row):hover td { background: transparent; }
  #products-list tbody tr:not(.category-header-row) td {
    display: block; padding: 0; border: 0; min-width: 0;
  }
  /* Hide ID (1) and Магазин (4) on mobile */
  #products-list tbody tr td:nth-child(1),
  #products-list tbody tr td:nth-child(4) { display: none; }
  /* Map remaining content cells to grid areas via nth-child */
  #products-list tbody tr td:nth-child(2) { grid-area: title; font-weight: 600; display: flex; align-items: center; gap: var(--space-2); }
  #products-list tbody tr td:nth-child(3) { grid-area: price; color: var(--color-text-muted); font-size: 13px; }
  #products-list tbody tr td:nth-child(5) { grid-area: status; justify-self: end; }
  #products-list tbody tr td:nth-child(6) { grid-area: actions; justify-self: end; }
  #products-list tbody tr td:nth-child(6).actions { gap: 4px; }
  #products-list tbody tr td:nth-child(6) .btn-sm { padding: 4px 8px; font-size: 11px; }
  #products-list .product-thumb { width: 36px; height: 36px; margin: 0; }

  /* Categories table: hide ID */
  #categories-table th:nth-child(1), #categories-table td:nth-child(1) { display: none; }

  /* Shops table: hide URL (2) — keep Название/Статус/Actions */
  #shops-list th:nth-child(2), #shops-list td:nth-child(2) { display: none; }

  /* Users table: hide Email (2) and Магазин (4) — keep Имя/Роль/Активен/Действия */
  #users-list th:nth-child(2), #users-list td:nth-child(2),
  #users-list th:nth-child(4), #users-list td:nth-child(4) { display: none; }

  /* Attributes table: hide count column (2); allow inline rename form to wrap */
  #attributes-table th:nth-child(2), #attributes-table td:nth-child(2) { display: none; }
  #attributes-table td form[action$="/rename"] { flex-wrap: wrap; }
  #attributes-table td form[action$="/rename"] input { flex: 1 1 100%; min-width: 0; }

  /* Status pill stays compact */
  .status-pill { padding: 2px 8px; font-size: 10px; }

  /* Dashboard */
  .admin-dashboard { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .dashboard-card { padding: var(--space-5) var(--space-4); }
  .dashboard-card .stat-value { font-size: 22px; }

  /* Sticky save bar — slimmer paddings to match container insets */
  .sticky-save-bar { padding: 10px var(--space-3); margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); margin-bottom: calc(-1 * var(--space-4)); flex-wrap: wrap; gap: 6px; }
  .sticky-save-bar .save-status { font-size: 11px; flex: 1 1 100%; text-align: left; margin: 0; }

  /* Tabs scroll horizontally if needed */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; }

  /* Pagination wrap nicely */
  .pagination { flex-wrap: wrap; gap: 4px; }
  .pagination .info { flex-basis: 100%; text-align: center; order: -1; margin-bottom: 6px; }

  /* Image gallery — smaller tiles on phone, always-visible overlay (no hover on touch) */
  .gallery-item, .upload-tile { width: 88px; height: 88px; }
  .gallery-overlay { opacity: 1; pointer-events: auto; background: linear-gradient(to top, rgba(15,23,42,.65) 0%, rgba(15,23,42,0) 50%); align-items: flex-end; justify-content: flex-end; padding: 6px; }
  .gallery-action-btn { width: 26px; height: 26px; }
  .drag-handle { opacity: 1; }

  /* Product attribute rows — stack name/value vertically with delete button on its own row */
  .attribute-row { flex-direction: column; align-items: stretch; gap: var(--space-2); }
  .attribute-row > input { flex: 1 1 auto; width: 100%; }
  .attribute-row > .btn { align-self: flex-end; }

  /* Form actions stack: keep primary action prominent at top */
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

/* === Reduced motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* === Drop-zone === */
.drop-zone { position: relative; border: 2px dashed transparent; border-radius: var(--radius-lg); padding: var(--space-2); margin: calc(-1 * var(--space-2)); transition: border-color .15s, background .15s; }
.drop-zone.is-dragover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.drop-zone-hint { font-size: 12px; color: var(--color-text-muted); margin-top: var(--space-2); text-align: left; pointer-events: none; }
.drop-zone.is-dragover .drop-zone-hint { color: var(--color-primary); font-weight: 500; }

/* === Stat meta line === */
.stat-meta { font-size: 12px; color: var(--color-text-muted); margin: 4px 0 0; }
.stat-meta time { color: inherit; }

/* === HTMX loading indicator === */
.htmx-request, [aria-busy='true'] { opacity: .55; pointer-events: none; transition: opacity .15s; position: relative; }
[aria-busy='true']::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--color-primary-soft), transparent); background-size: 50% 100%; animation: shimmer 1.4s infinite; pointer-events: none; z-index: 1; }
/* Known swap targets get explicit positioning to host the shimmer overlay reliably */
#products-list, #categories-table, #users-list, #shops-list, #attributes-table { position: relative; }

/* === Dark mode === */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0b1220;
    --color-surface: #111827;
    --color-surface-alt: #1f2937;
    --color-text: #e5e7eb;
    --color-text-muted: #9ca3af;
    --color-text-soft: #cbd5e1;
    --color-border: #1f2937;
    --color-border-strong: #374151;
    --color-primary: #60a5fa;
    --color-primary-hover: #93c5fd;
    --color-primary-soft: rgba(96,165,250,.18);
    --color-success: #34d399;
    --color-success-soft: rgba(52,211,153,.12);
    --color-danger: #f87171;
    --color-danger-soft: rgba(248,113,113,.12);
    --color-warning: #fbbf24;
    --color-navbar-bg: #030712;
  }
  body { color-scheme: dark; }
  .table tbody tr:not(.category-header-row):hover td { background: #1a2333; }
  .table tr.category-root td, .table tr.category-header-root td { background: #1a2333; }
  .table tr.category-header-child td { background: #161f2e; }
  .autocomplete-list, .toast { background: var(--color-surface); }
  .lightbox-overlay { background: rgba(0,0,0,.85); }
  .password-toggle:hover { background: rgba(255,255,255,.05); }
  .input-with-toggle > input, .form-group input, .form-group select, .form-group textarea, .table input[type='text'], .table input[type='url'], .table input[type='email'], .table input[type='number'], .table input[type='search'] { background-color: var(--color-surface); color: var(--color-text); }
  .filters select, .toolbar select, .form-group select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23cbd5e1' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
  .search-input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'/%3E%3C/svg%3E"); }
  /* Buttons / labels use hardcoded grays in light mode — override for legibility */
  .btn { color: var(--color-text-soft); background: var(--color-surface); border-color: var(--color-border-strong); }
  .btn:hover { background: var(--color-surface-alt); border-color: #4b5563; color: var(--color-text); }
  .btn-primary, .btn-primary:hover { color: #fff; background: #2563eb; border-color: #2563eb; }
  .btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
  .form-group label { color: var(--color-text-soft); }
  .page-header h1 { color: var(--color-text); }
  .autocomplete-list li { color: var(--color-text); }
  .autocomplete-list li:hover { background: var(--color-surface-alt); }
  .navbar .btn-sm { color: #cbd5e1; }
  .stat-pill.is-inactive, .status-pill.is-inactive { background: rgba(148,163,184,.18); color: var(--color-text-muted); }
  .table tr.category-header-root .category-label::before { background: var(--color-primary); }
  .pagination a, .pagination span { background: var(--color-surface); color: var(--color-text-soft); border-color: var(--color-border-strong); }
  .pagination .current { background: var(--color-primary); color: #0b1220; border-color: var(--color-primary); }
  .variant-count-badge { background: rgba(241,245,249,.15); color: #94a3b8; }

  /* Category header rows */
  .table tr.category-header-root .category-label { color: var(--color-text); }
  .table tr.category-header-root td { border-bottom-color: var(--color-border-strong); }
  .table tr.category-header-child .category-label { background: rgba(96,165,250,.18); color: var(--color-text); }
  .table tr.category-header-child td { border-bottom-color: var(--color-border); }

  /* Status inactive variants */
  .status-inactive { background: rgba(148,163,184,.15); color: var(--color-text-muted); }

  /* Btn:hover light fallback */
  .btn:hover { background: var(--color-surface-alt); }

  /* Login logo readable */
  .login-logo { background: #1e40af; }
  .login-header h1 { color: var(--color-text); }
}

/* Merge wizard modal */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: white;
  padding: 24px;
  border-radius: 8px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
@media (prefers-color-scheme: dark) {
  .modal-content { background: #1e293b; color: #e2e8f0; }
}
.form-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* Variant axes picker */
.axes-picker { margin-top: 4px; }
.axes-search-wrap { position: relative; }
/* Axis domain blocks (per-axis value chip list) */
#axis-domains-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.axis-domain {
  background: var(--color-surface-alt, #f8fafc);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: var(--radius-md, 6px);
  padding: 10px 12px;
}
.axis-domain-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.axis-domain-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text, #1e293b);
  text-transform: lowercase;
}
.axis-domain-remove {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #94a3b8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
}
.axis-domain-remove:hover { color: var(--color-danger, #ef4444); }
.axis-domain-values {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.axis-value-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px;
  background: var(--color-primary, #2563eb);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
}
.axis-value-remove {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 16px; height: 16px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: inherit;
  padding: 0;
}
.axis-value-remove:hover { background: rgba(255,255,255,0.4); }
.axis-value-input {
  border: 1px dashed var(--color-border-strong, #cbd5e1);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  min-width: 120px;
  color: var(--color-text, inherit);
  font-family: inherit;
}
.axis-value-input:focus { outline: none; border-style: solid; border-color: var(--color-primary, #2563eb); }
/* Color swatch shown inside a value chip */
.axis-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  flex: 0 0 auto;
}
/* Color add-control: "+ цвет" button with a pick-from-DB popover */
.color-add { position: relative; display: inline-block; }
.color-popover {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  width: 248px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
}
.color-popover[hidden] { display: none; }
.color-popover-native { display: flex; align-items: center; gap: 8px; }
.color-popover .color-native {
  width: 32px; min-width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--color-border-strong, #cbd5e1);
  border-radius: 6px; background: transparent; cursor: pointer; flex: 0 0 auto;
}
.color-native::-webkit-color-swatch-wrapper { padding: 2px; }
.color-native::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-native::-moz-color-swatch { border: none; border-radius: 4px; }
.color-native-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12px; color: var(--color-text-muted, #64748b);
}
.color-search {
  width: 100%; box-sizing: border-box;
  padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 6px; font-family: inherit;
}
.color-search:focus { outline: none; border-color: var(--color-primary, #2563eb); }
.color-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.color-list-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 6px; background: transparent; border: none;
  border-radius: 6px; cursor: pointer; font-size: 13px;
  text-align: left; font-family: inherit; color: var(--color-text, #1e293b);
}
.color-list-item:hover { background: var(--color-surface-alt, #f1f5f9); }
.color-list-item.is-selected { background: var(--color-primary-soft, #dbeafe); }
.color-list-swatch {
  width: 16px; height: 16px; border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1); flex: 0 0 auto;
}
.color-list-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.color-list-empty { padding: 8px; font-size: 12px; color: var(--color-text-muted, #94a3b8); text-align: center; }
.color-popover-foot { display: flex; justify-content: flex-end; gap: 6px; }
/* Required-field marker in variant table headers */
.req-mark { color: var(--color-danger, #dc2626); font-weight: 700; }
/* Per-field validation highlight (only the empty required field, not the whole group) */
input.is-invalid, select.is-invalid {
  border-color: var(--color-danger, #dc2626) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12) !important;
}
/* Variant image strip (per-row upload) */
.variant-images-strip {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.variant-thumb {
  position: relative;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm, 4px);
  overflow: hidden;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-surface-alt);
}
.variant-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.variant-thumb-remove {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6); color: #fff;
  border: none; cursor: pointer;
  font-size: 11px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  font-family: inherit;
}
.variant-thumb-remove:hover { background: var(--color-danger, #ef4444); }
.variant-thumb-upload {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm, 4px);
  border: 1px dashed var(--color-border-strong, #cbd5e1);
  background: transparent;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted, #94a3b8);
  font-size: 20px;
  user-select: none;
}
.variant-thumb-upload:hover { border-color: var(--color-primary, #2563eb); color: var(--color-primary, #2563eb); }
.variant-thumb-upload.is-uploading { opacity: 0.5; pointer-events: none; }

/* Variants section header (inline bulk price) */
.variants-section-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 6px; flex-wrap: wrap;
}
.variants-bulk { display: flex; gap: 6px; align-items: center; }
.variants-bulk input { width: 120px; }
.axes-search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong, #cbd5e1);
  border-radius: var(--radius-md, 6px);
  font-size: 14px;
  background: var(--color-surface, transparent);
  color: var(--color-text, inherit);
  font-family: inherit;
}
.axes-search:focus {
  outline: none;
  border-color: var(--color-primary, #2563eb);
  box-shadow: 0 0 0 3px var(--color-primary-soft, rgba(37,99,235,0.15));
}
.axes-suggestions {
  display: none;
  position: fixed; /* pinned via JS so the scrolling form body can't clip it */
  max-height: 280px;
  overflow-y: auto;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border-strong, #cbd5e1);
  border-radius: var(--radius-md, 6px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 1000;
  padding: 4px 0;
}
.axes-suggestions.is-open { display: block; }
.axes-suggestion {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text, #1e293b);
  user-select: none;
}
.axes-suggestion:hover { background: var(--color-surface-alt, #f1f5f9); }
.axes-suggestions:empty::before {
  content: 'Ничего не найдено';
  display: block;
  padding: 12px;
  color: var(--color-text-muted, #94a3b8);
  font-size: 13px;
  text-align: center;
}

/* ── billing-admin дополнения ─────────────────────────── */
.ta-r { text-align: right; }
.section-title { font-size: 15px; font-weight: 600; margin: 24px 0 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.tool-row td { color: var(--muted, #6b7280); background: rgba(0,0,0,0.02); }
.tool-branch { color: var(--muted, #9ca3af); margin-right: 2px; }
.msg-details { border: 1px solid var(--border, #e5e7eb); border-radius: 8px; margin-bottom: 8px; }
.msg-details > summary { cursor: pointer; padding: 10px 14px; font-size: 14px; list-style: none; }
.msg-details > summary::-webkit-details-marker { display: none; }
.msg-details > summary::before { content: '▸'; margin-right: 8px; color: var(--muted, #9ca3af); }
.msg-details[open] > summary::before { content: '▾'; }
.msg-details > .table-scroll { padding: 0 14px 12px; }
.msg-more > summary { font-weight: 600; }
.msg-more > .msg-more-body { padding: 0 14px 6px; }
.date-input { cursor: pointer; }
.date-input::-webkit-calendar-picker-indicator { cursor: pointer; }

.alert-success { background: var(--color-success-soft); color: var(--color-success); border: 1px solid rgba(22,163,74,.25); }
.test-panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); margin-bottom: var(--space-4); box-shadow: var(--shadow-sm); }
.test-panel > h2 { font-size: 15px; font-weight: 600; margin-bottom: var(--space-2); }
.test-panel .form { padding: 0; box-shadow: none; max-width: none; background: transparent; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--space-2) var(--space-4); margin-bottom: var(--space-3); }
.kv > div { font-size: 13px; }
.kv .kv-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted); font-weight: 600; }
.kv .kv-value { font-family: var(--font-mono); font-size: 13px; word-break: break-all; }
.code-block { font-family: var(--font-mono); font-size: 12px; background: var(--color-surface-alt); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-3); overflow-x: auto; white-space: pre; margin: var(--space-2) 0; }
.blockers { margin: 0; padding-left: 18px; font-size: 13px; color: var(--color-warning); }
.blockers li { margin-bottom: 2px; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }
