/* Дизайн-система админки: soft-dark на CSS-переменных, светлая тема через [data-theme]. */

:root {
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1c212a;
  --surface-3: #222834;
  --border: #2a313d;
  --border-strong: #3a4353;
  --text: #e7ebf2;
  --text-muted: #8b95a7;
  --text-faint: #5f6a7d;
  --accent: #4c8dff;
  --accent-weak: rgba(76, 141, 255, 0.14);
  --accent-border: rgba(76, 141, 255, 0.4);
  --green: #33c37e;
  --green-weak: rgba(51, 195, 126, 0.14);
  --amber: #e3b23c;
  --amber-weak: rgba(227, 178, 60, 0.14);
  --red: #e5645f;
  --red-weak: rgba(229, 100, 95, 0.14);
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef1f6;
  --border: #e2e7ef;
  --border-strong: #d3dae6;
  --text: #1a2230;
  --text-muted: #5d687a;
  --text-faint: #95a0b2;
  --accent: #2f6fe0;
  --accent-weak: rgba(47, 111, 224, 0.1);
  --accent-border: rgba(47, 111, 224, 0.35);
  --shadow: 0 4px 20px rgba(30, 50, 90, 0.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
svg { display: block; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
}
.brand {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 13px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 500;
  transition: 0.12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.topbar .spacer { flex: 1; }
.burger { display: none; }

/* ------------------------------------------------------- контейнер и текст */

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 24px 60px; }
.wrap-narrow { max-width: 640px; margin: 0 auto; padding: 22px 24px 60px; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 13px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.crumbs a:hover { color: var(--text-muted); }
.crumbs .sep { opacity: 0.5; }
.crumbs .cur { color: var(--text-muted); }

h1 { font-size: 22px; font-weight: 700; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 26px 0 12px; }
h3 { font-size: 15px; margin: 0 0 4px; }
.sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

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

.btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 8px 15px;
  border-radius: var(--r-sm);
  font-weight: 600;
  transition: 0.12s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.secondary:hover { border-color: var(--border-strong); filter: none; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-weak); filter: none; }
.btn:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  transition: 0.12s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: var(--r-sm);
  font-weight: 500;
  transition: 0.12s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }

/* ---------------------------------------------------------------- карточки */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card.pad { padding: 20px; }
.card + .card { margin-top: 16px; }

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

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 15px 18px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable:hover { background: var(--surface-2); cursor: pointer; }
.table-wrap { overflow-x: auto; }
.store-name { font-weight: 600; color: var(--text); }
tr.clickable:hover .store-name { color: var(--accent); }
.frac { font-weight: 700; }
.frac span { color: var(--text-faint); font-weight: 500; }

/* ------------------------------------------------------- бейджи и пилюли */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.green { background: var(--green-weak); color: var(--green); }
.pill.amber { background: var(--amber-weak); color: var(--amber); }
.pill.red { background: var(--red-weak); color: var(--red); }
.pill.accent { background: var(--accent-weak); color: var(--accent); }
.pill.muted { background: var(--surface-3); color: var(--text-muted); }
.pill .d { width: 6px; height: 6px; border-radius: 50%; }
.pill.green .d { background: var(--green); }
.pill.amber .d { background: var(--amber); }
.pill.red .d { background: var(--red); }
.pill.accent .d { background: var(--accent); }
.pill.muted .d { background: var(--text-muted); }
.pill.tiny { font-size: 11px; padding: 1px 7px; }

/* --------------------------------------------------- воркспейс витрины */

.ws-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.ws-title { display: flex; align-items: center; gap: 12px; }
.ws-title h1 { font-size: 20px; }

.stat-chips { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 14px;
  min-width: 96px;
}
.chip .n { font-size: 19px; font-weight: 700; line-height: 1.1; }
.chip .l { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.chip.green .n { color: var(--green); }
.chip.amber .n { color: var(--amber); }
.chip.accent .n { color: var(--accent); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 20px 0; overflow-x: auto; }
.tabs a {
  padding: 11px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: 0.12s;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { font-size: 12px; color: var(--text-faint); margin-left: 6px; font-weight: 600; }

/* ------------------------------------------------------------- тулбар */

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; flex: 1; min-width: 220px; }
.search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px 9px 34px;
  border-radius: var(--r-sm);
  font-size: 14px;
  outline: none;
  transition: 0.12s;
}
.search input:focus { border-color: var(--accent-border); }
.search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.fchip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
  transition: 0.12s;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.fchip:hover { color: var(--text); border-color: var(--border-strong); text-decoration: none; }
.fchip.active { background: var(--accent-weak); border-color: var(--accent-border); color: var(--accent); }
.fchip .n { opacity: 0.7; font-weight: 500; }

/* ----------------------------------------------- дерево + список товаров */

.selector { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
.tree {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 8px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
.tnode {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: 0.1s;
}
.tnode:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tnode.active { background: var(--accent-weak); color: var(--accent); }
.tnode.child { padding-left: 24px; font-size: 13.5px; }
.tnode .cnt { font-size: 12px; color: var(--text-faint); }
.tnode.active .cnt { color: var(--accent); }
.tnode .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.plist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.group-h {
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 56px;
  z-index: 2;
}
.prow {
  display: grid;
  grid-template-columns: 22px 34px 1fr 100px 96px 48px;
  gap: 14px;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  transition: 0.1s;
}
.prow:last-child { border-bottom: 0; }
.prow:hover { background: var(--surface-2); }
.thumb {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: contain;
  background: var(--surface-3);
}
.pname { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pmeta { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.price { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.price span { color: var(--text-faint); font-weight: 500; font-size: 12px; }
.stock { font-size: 12px; text-align: center; }

.tg {
  width: 40px;
  height: 23px;
  border-radius: 20px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: 0.15s;
  flex-shrink: 0;
  display: block;
}
.tg::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: 0.15s;
}
.tg.on { background: var(--green-weak); border-color: var(--green); }
.tg.on::after { left: 19px; background: var(--green); }

.bulkbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--accent-weak);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
  margin-bottom: 14px;
  font-weight: 600;
  color: var(--accent);
  flex-wrap: wrap;
}
.bulkbar.hidden { display: none; }

input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ------------------------------------------------------------------ формы */

.form-sec { padding: 20px 22px; border-bottom: 1px solid var(--border); }
.form-sec:last-child { border-bottom: 0; }
.form-sec .hint { color: var(--text-muted); font-size: 12.5px; margin: 0 0 16px; }
.field { margin-bottom: 16px; max-width: 520px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.field input[type="text"],
.field input[type="password"],
.field input[type="file"],
.field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: 0.12s;
}
.field input:focus, .field select:focus { border-color: var(--accent-border); }
.field .fh { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.field .fh code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; font-size: 11.5px; }
.row2 { display: flex; gap: 14px; flex-wrap: wrap; }
.chkline { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; margin-bottom: 0; }
.bot-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.form-sec.danger { border-color: var(--red); }
.form-sec.danger h3 { color: var(--red); }

.form-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding: 14px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ------------------------------------------------- каталог: дропзона, диффа */

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: 26px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  transition: 0.12s;
  cursor: pointer;
  display: block;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent-border); color: var(--text); }
.dropzone input[type="file"] { display: none; }

.big-stats { display: flex; gap: 22px; margin-bottom: 18px; flex-wrap: wrap; }
.big-stats .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.big-stats .l { color: var(--text-muted); font-size: 12px; }
.big-stats .green { color: var(--green); }

.diff-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.diff-row:last-child { border-bottom: 0; }
.diff-n { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 52px; }

/* ------------------------------------------------------- служебные блоки */

.flash { padding: 10px 14px; border-radius: var(--r-md); margin-bottom: 16px; font-size: 14px; }
.flash-ok { background: var(--green-weak); color: var(--green); }
.flash-err { background: var(--red-weak); color: var(--red); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 14px; color: var(--text-muted); }

details summary { cursor: pointer; color: var(--text-muted); font-size: 13px; }
.htmx-request { opacity: 0.5; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

/* --------------------------------------------------------------- адаптив */

@media (max-width: 1023px) {
  .wrap { padding: 18px 16px 48px; }
  .selector { grid-template-columns: 200px 1fr; }
}

@media (max-width: 820px) {
  .selector { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 260px; }
  .grid2 { grid-template-columns: 1fr; }
  .prow { grid-template-columns: 22px 34px 1fr 48px; }
  .prow .price, .prow .stock { display: none; }
}

@media (max-width: 767px) {
  .topbar { gap: 12px; padding: 0 14px; }
  .burger { display: grid; }
  .topbar .nav {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 8px;
    gap: 2px;
  }
  .topbar .nav.open { display: flex; }
  .brand span:last-child { display: none; }
}

/* Форма смены пароля раскрывается прямо в строке таблицы. */
.inline-form { display: inline-block; vertical-align: middle; }
.inline-form > summary { list-style: none; cursor: pointer; }
.inline-form > summary::-webkit-details-marker { display: none; }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
