/* ==========================================================================
   PriceSync — интерфейс
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-hover: #f3f4f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;

  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(67, 56, 202, 0.22);

  --pending: #d97706;
  --pending-text: #92400e;
  --pending-bg: #fff7e6;
  --pending-bg-strong: #fde7b0;
  --pending-border: #f5c26b;

  --ok: #067647;
  --ok-bg: #ecfdf3;
  --danger: #d92d20;
  --danger-bg: #fef3f2;
  --danger-hover: #b42318;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 20px 32px -8px rgba(16, 24, 40, 0.18), 0 6px 12px -4px rgba(16, 24, 40, 0.06);

  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --pulse-period: 2.4s;
  --topbar-h: 60px;
  color-scheme: light;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

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

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

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 550; font-size: 13.5px; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
  user-select: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-block { width: 100%; height: 42px; font-size: 14.5px; }
.btn-toggle[aria-pressed="true"] { background: var(--pending-bg); border-color: var(--pending-border); color: var(--pending-text); }

.btn-group { display: inline-flex; }
.btn-group .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  transition: background-color .15s, color .15s;
  flex: none;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.sm svg { width: 15px; height: 15px; }

.btn-ok {
  height: 32px; min-width: 56px; padding: 0 14px;
  border: 1px solid var(--pending); border-radius: 999px;
  background: var(--pending); color: #fff;
  font-weight: 650; letter-spacing: .02em;
  box-shadow: 0 1px 2px rgba(146, 64, 14, .25);
  transition: transform .1s, background-color .15s;
}
.btn-ok:hover { background: #b45309; }
.btn-ok:active { transform: scale(.96); }
.btn-ok:disabled { opacity: .6; }

/* ---------- Поля ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.input {
  width: 100%; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; line-height: 1.4; }
select.input { padding-right: 30px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input.is-invalid { border-color: var(--danger); }
.input-price { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 110px; gap: 12px; }

.form-error {
  margin: 0 0 14px; padding: 10px 12px;
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid #fecdca; border-radius: var(--radius-sm);
  font-size: 13px;
}

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

.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px 28px 28px; box-shadow: var(--shadow-md);
}
.login-title { margin: 22px 0 4px; font-size: 20px; font-weight: 650; letter-spacing: -.01em; text-align: center; }
.login-sub { margin: 0 0 24px; color: var(--muted); text-align: center; }
.password-wrap { position: relative; display: block; }
.password-wrap .input { padding-right: 44px; }
.password-toggle { position: absolute; right: 4px; top: 4px; }

/* ---------- Бренд ---------- */

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; }
.brand--center { justify-content: center; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  border-radius: 8px; background: var(--accent); color: #fff;
}
.brand-name { font-size: 16px; }

/* ---------- Верхняя панель ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.6) blur(10px);
  -webkit-backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
.topbar-spacer { flex: 1; }

.conn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 26px; padding: 0 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; font-weight: 550;
}
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.conn[data-state="online"] .conn-dot { background: #12b76a; box-shadow: 0 0 0 3px rgba(18, 183, 106, .18); }
.conn[data-state="connecting"] .conn-dot { background: var(--pending); animation: conn-blink 1s ease-in-out infinite; }
.conn[data-state="offline"] { color: var(--danger); background: var(--danger-bg); border-color: #fecdca; }
.conn[data-state="offline"] .conn-dot { background: var(--danger); }
@keyframes conn-blink { 50% { opacity: .3; } }

.pending-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--pending-border); background: var(--pending-bg); color: var(--pending-text);
  font-weight: 600; font-size: 13px;
}
.pending-pill:hover { background: var(--pending-bg-strong); }
.pending-pill[aria-pressed="true"] { box-shadow: 0 0 0 3px rgba(217, 119, 6, .2); }
.pending-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pending); animation: conn-blink 1.6s ease-in-out infinite; }
.pending-count { font-variant-numeric: tabular-nums; }

.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px;
  border: 0; border-radius: 999px; background: none; text-align: left;
  transition: background-color .15s;
}
.user-chip:hover { background: var(--surface-hover); }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11.5px; color: var(--muted); }

.tabs {
  max-width: 1120px; margin: 0 auto; padding: 0 20px;
  display: flex; gap: 4px;
}
.tab {
  position: relative; height: 40px; padding: 0 12px;
  border: 0; background: none; color: var(--muted); font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); }
.tab.is-active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px;
}

/* ---------- Основная область ---------- */

.container { max-width: 1120px; margin: 0 auto; padding: 20px 20px 80px; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.search {
  position: relative; flex: 1 1 320px; display: flex; align-items: center;
  height: 40px; padding: 0 12px; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--faint); transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); color: var(--accent); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: none; background: none; color: var(--text); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-kbd {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface-2);
}
.search:focus-within .search-kbd { display: none; }

/* ---------- Категории ---------- */

.catalog { display: flex; flex-direction: column; gap: 10px; }

.cat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cat.has-pending { border-color: var(--pending-border); }

.cat-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 4px; min-height: 52px; }
.cat-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px; border: 0; background: none; text-align: left; border-radius: var(--radius-sm);
}
.cat-toggle:hover .cat-name { color: var(--accent); }
.chev { flex: none; color: var(--faint); transition: transform .22s ease; }
.cat.is-open > .cat-head .chev { transform: rotate(90deg); color: var(--text-2); }
.cat-name { font-weight: 650; font-size: 15px; letter-spacing: -.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color .15s; }
.count-badge {
  flex: none; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; line-height: 20px;
  font-variant-numeric: tabular-nums;
}
.pending-badge {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 650; color: var(--pending-text);
  background: var(--pending-bg); border: 1px solid var(--pending-border); border-radius: 999px; padding: 0 8px; line-height: 20px;
}
.pending-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--pending); }

.cat-actions { display: flex; gap: 2px; opacity: .85; }
.cat-head:hover .cat-actions { opacity: 1; }

.cat-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .25s ease; }
.cat.is-open > .cat-body { grid-template-rows: 1fr; }
.cat-inner { overflow: hidden; min-height: 0; }
.cat:not(.is-open) > .cat-body .cat-inner { visibility: hidden; transition: visibility 0s .25s; }
.cat.is-open > .cat-body .cat-inner { visibility: visible; }
.cat-content { border-top: 1px solid var(--border); }

.sub { border-top: 1px solid var(--border); }
.sub-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 8px 20px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.sub-name { flex: 1; min-width: 0; font-weight: 600; font-size: 13px; color: var(--text-2); text-transform: none; }
.sub-name::before { content: "↳ "; color: var(--faint); }
.sub .row { padding-left: 32px; }

.empty-cat { padding: 16px 20px; color: var(--muted); font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Строка товара ---------- */

.row {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px;
  padding: 10px 12px 10px 20px; min-height: 56px;
  border-bottom: 1px solid var(--border);
  background-color: var(--surface);
  transition: background-color .3s;
}
.row:last-child { border-bottom: 0; }
.row:hover { background-color: var(--surface-2); }

.row-main { min-width: 0; }
.row-title { display: flex; align-items: center; gap: 4px; min-width: 0; }
.item-name { font-weight: 550; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-comment { color: var(--muted); font-size: 12.5px; margin-top: 1px; white-space: pre-line; overflow-wrap: anywhere; }
.row-meta { color: var(--faint); font-size: 12px; margin-top: 2px; }

.row-price { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.price {
  font-variant-numeric: tabular-nums; font-weight: 650; font-size: 16px; letter-spacing: -.01em; white-space: nowrap;
}
.currency { color: var(--muted); font-weight: 550; font-size: 12.5px; margin-left: 4px; }
.row-actions { display: flex; align-items: center; gap: 2px; min-width: 32px; justify-content: flex-end; }

.copy-btn { opacity: 0; }
.row:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
@media (hover: none) { .copy-btn { opacity: .6; } }

mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }

/* Изменённая позиция: плавное чередование фона (только у неподтвердившего пользователя) */
@keyframes pending-pulse {
  0%, 100% { background-color: var(--pending-bg); }
  50%      { background-color: var(--pending-bg-strong); }
}
.row.is-pending {
  animation: pending-pulse var(--pulse-period) ease-in-out infinite;
  box-shadow: inset 3px 0 0 var(--pending);
}
.row.is-pending:hover { animation-play-state: paused; background-color: var(--pending-bg-strong); }

/* У администратора — спокойная подсветка без мигания, пока не все подтвердили */
.row.is-open-admin { background-color: #fffcf5; box-shadow: inset 3px 0 0 var(--pending-border); }

.change-line {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px;
  margin-top: 4px; font-size: 12.5px; color: var(--pending-text);
}
.change-line .old { text-decoration: line-through; color: #b54708; opacity: .75; font-variant-numeric: tabular-nums; }
.change-line .new { font-weight: 700; font-variant-numeric: tabular-nums; }
.change-line .arrow { color: var(--pending); }
.change-line .when { color: var(--muted); }
.change-badge {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--pending);
  border-radius: 999px; padding: 0 7px; line-height: 18px;
}

.change-details { margin-top: 4px; font-size: 12px; }
.change-details summary {
  cursor: pointer; color: var(--pending-text); font-weight: 600; list-style: none; display: inline-flex; align-items: center; gap: 4px;
}
.change-details summary::-webkit-details-marker { display: none; }
.change-details summary::before { content: "▸"; transition: transform .15s; display: inline-block; }
.change-details[open] summary::before { transform: rotate(90deg); }
.change-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; }
.change-list li { display: flex; gap: 8px; flex-wrap: wrap; color: var(--text-2); font-variant-numeric: tabular-nums; }
.change-list .seq { font-family: var(--mono); color: var(--muted); font-size: 11.5px; }

.ack-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  border-radius: 999px; padding: 0 8px; line-height: 20px; border: 1px solid;
}
.chip-ok { color: var(--ok); background: var(--ok-bg); border-color: #abefc6; }
.chip-wait { color: var(--pending-text); background: var(--pending-bg); border-color: var(--pending-border); }
.chip-muted { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

/* ---------- Предупреждения ---------- */

#banners:empty { display: none; }
#banners { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid; font-size: 13.5px; line-height: 1.45;
}
.banner svg { flex: none; margin-top: 1px; }
.banner-warn { background: var(--accent-soft); border-color: #c7d2fe; color: #312e81; }
.banner-danger { background: var(--danger-bg); border-color: #fecdca; color: #912018; }

.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-title { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
a.btn { text-decoration: none; }

/* ---------- Пустые состояния ---------- */

.empty-state {
  text-align: center; padding: 56px 20px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0 0 16px; }
.empty-state p:last-child { margin-bottom: 0; }

/* ---------- История ---------- */

.history-filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px;
  align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 14px 0; margin-bottom: 12px;
}
.field--compact { margin-bottom: 14px; }
.field--compact .input { height: 36px; font-size: 13px; }
.history-filter-actions { margin-bottom: 14px; display: flex; }
.history-summary { color: var(--muted); font-size: 13px; margin: 4px 2px 10px; }

.history-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; white-space: nowrap;
  background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.history-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.history-table tr:last-child td { border-bottom: 0; }
.history-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-table .nowrap { white-space: nowrap; }
.history-table .seq { font-family: var(--mono); color: var(--faint); font-size: 11.5px; }
.h-item { font-weight: 600; }
.h-cat { color: var(--muted); font-size: 12px; }
.h-type { display: inline-block; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; margin-top: 2px; }
.h-new { font-weight: 700; }
.h-up { color: var(--danger); }
.h-down { color: var(--ok); }
.ack-cell { white-space: nowrap; }
.ack-time { display: block; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.history-more-wrap { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- Модальное окно ---------- */

.modal {
  border: 0; padding: 0; background: transparent; max-width: calc(100vw - 24px); width: 460px;
  color: var(--text);
}
.modal::backdrop { background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
.modal[open] { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px 20px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.modal-body { padding: 12px 20px 2px; }
.modal-body p { margin: 0 0 14px; color: var(--text-2); }
.modal-card > .form-error { margin: 0 20px 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.price-was { font-size: 12.5px; color: var(--muted); margin: -6px 0 14px; }

/* ---------- Уведомления ---------- */

.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 240px; max-width: 380px; padding: 12px 14px;
  background: #101828; color: #fff; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; line-height: 1.4;
  animation: toast-in .2s ease-out;
}
.toast.is-leaving { animation: toast-out .2s ease-in forwards; }
.toast-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.toast-success .toast-icon { color: #47cd89; }
.toast-error { background: #7a271a; }
.toast-error .toast-icon { color: #fda29b; }
.toast-warn .toast-icon { color: #fdb022; }
.toast-info .toast-icon { color: #a4bcfd; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Роли ---------- */

body:not([data-role="admin"]) .admin-only { display: none !important; }

/* ---------- Адаптивность ---------- */

@media (max-width: 860px) {
  .user-meta { display: none; }
}

@media (max-width: 640px) {
  :root { --topbar-h: 54px; }
  body { font-size: 14px; }
  .topbar-inner { padding: 0 12px; gap: 8px; }
  .brand-name { display: none; }
  .conn { padding: 0 8px; }
  .conn-label { display: none; }
  .conn[data-state="offline"] .conn-label { display: inline; }
  .pending-label { display: none; }
  .tabs { padding: 0 8px; }
  .container { padding: 12px 10px 90px; }

  .toolbar { gap: 8px; }
  .search { flex-basis: 100%; }
  .search-kbd { display: none; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { height: 34px; padding: 0 10px; font-size: 13px; }
  #add-category { margin-left: auto; }

  .cat-head { padding: 4px 4px 4px 0; min-height: 48px; }
  .cat-name { font-size: 14.5px; }
  .cat-actions .icon-btn { width: 30px; height: 30px; }

  /* Компактная строка: название сверху, цена и действия справа */
  .row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main price" "main actions"; gap: 2px 10px; padding: 9px 8px 9px 14px; }
  .row-main { grid-area: main; }
  .row-price { grid-area: price; }
  .row-actions { grid-area: actions; }
  .sub .row { padding-left: 22px; }
  .sub-head { padding-left: 14px; }
  .item-name { white-space: normal; }
  .row-meta { font-size: 11.5px; }
  .price { font-size: 15.5px; }
  .copy-btn { display: none; }
  .btn-ok { height: 30px; }

  .history-filters { grid-template-columns: 1fr 1fr; padding: 12px 12px 0; }
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td { display: block; width: 100%; }
  .history-table tr { padding: 10px 12px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  .history-table td { padding: 0; border: 0; }
  .history-table td.c-item { grid-column: 1 / -1; }
  .history-table td.num { text-align: left; }
  .history-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 600; }

  .toasts { left: 10px; right: 10px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }

  .modal { width: 100%; max-width: 100vw; margin: auto 0 0; }
  .modal-card { border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

/* ---------- Уменьшенная анимация ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
  .row.is-pending {
    animation: none !important;
    background-color: var(--pending-bg-strong);
    box-shadow: inset 4px 0 0 var(--pending);
  }
  .pending-dot, .conn[data-state="connecting"] .conn-dot { animation: none !important; }
}

@media print {
  .topbar, .toolbar, .row-actions, .cat-actions, .toasts { display: none !important; }
  .cat-body { grid-template-rows: 1fr !important; }
  .cat-inner { visibility: visible !important; }
  .row.is-pending { animation: none; }
}

/* ---------- Перетаскивание категорий (администратор) ---------- */

#catalog { position: relative; }
body[data-role="admin"] .cat-head { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.drag-grip {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 18px; margin: 0 -6px 0 4px; color: var(--faint); opacity: .55; cursor: grab;
  transition: opacity .15s, color .15s;
}
.cat-head:hover .drag-grip { opacity: 1; color: var(--muted); }
.cat.is-dragging {
  position: relative; z-index: 15;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-lg);
  transition: box-shadow .15s, border-color .15s;
}
body.is-reordering, body.is-reordering * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }
body.is-reordering .cat:not(.is-dragging) { opacity: .92; }
@media (hover: none) { .drag-grip { opacity: .8; } }

/* ---------- Перетаскивание подкатегорий ---------- */

.cat-content { position: relative; }
body[data-role="admin"] .sub-head { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sub-head .drag-grip { margin: 0 -2px 0 -10px; }
.sub-head:hover .drag-grip { opacity: 1; color: var(--muted); }
.sub.is-dragging {
  position: relative; z-index: 5;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-lg);
  border-radius: var(--radius-sm);
}
.sub.is-dragging .sub-head { background: var(--accent-soft); }
.drag-box > .sub:not(.is-dragging) { opacity: .92; }

/* ---------- Перетаскивание товаров ---------- */

.sub { position: relative; }
body[data-role="admin"] .row.is-draggable { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: grab; }
.row-grip {
  position: absolute; left: 1px; top: 50%; transform: translateY(-50%);
  width: 18px; margin: 0; opacity: 0;
}
.row:hover .row-grip { opacity: 1; color: var(--muted); }
.sub .row-grip { left: 9px; }
.row.is-dragging {
  z-index: 5;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-lg);
  border-radius: var(--radius-sm);
  animation: none;
}
.drag-box > .row:not(.is-dragging) { opacity: .92; }
@media (hover: none) { .row-grip { opacity: .55; } }
@media (max-width: 640px) { .row-grip { left: -2px; } .sub .row-grip { left: 4px; } }

/* ==========================================================================
   Ночная тема
   ========================================================================== */

.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle:hover { color: var(--accent); }

/* Плавная смена темы только в момент переключения */
html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: background-color .3s ease, border-color .3s ease, color .3s ease !important;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1c2029;
  --surface-hover: #242a36;
  --border: #2a303c;
  --border-strong: #3b4252;
  --text: #e7e9ef;
  --text-2: #c4c9d4;
  --muted: #8d95a7;
  --faint: #636b7d;

  --accent: #8b93ff;
  --accent-hover: #a5abff;
  --accent-soft: #23264a;
  --accent-ring: rgba(139, 147, 255, .3);

  --pending: #f59e0b;
  --pending-text: #fbbf24;
  --pending-bg: #2a2111;
  --pending-bg-strong: #4d3710;
  --pending-border: #7c5a17;

  --ok: #4ade80;
  --ok-bg: #11291b;
  --danger: #f87171;
  --danger-bg: #2d1618;
  --danger-hover: #ef4444;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, .45);
  --shadow-lg: 0 20px 36px -8px rgba(0, 0, 0, .6), 0 6px 12px -4px rgba(0, 0, 0, .4);
}

html[data-theme="dark"] body { background: var(--bg); }
html[data-theme="dark"] .topbar { background: rgba(23, 26, 33, .9); }

/* Кнопки с белым текстом — чуть темнее акцент для контраста */
html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .brand-mark { background: #6366f1; }
html[data-theme="dark"] .btn-primary:hover:not(:disabled) { background: #4f46e5; }
html[data-theme="dark"] .btn-danger { background: #dc2626; color: #fff; }
html[data-theme="dark"] .btn-danger:hover:not(:disabled) { background: #b91c1c; }
html[data-theme="dark"] .btn-ok { background: #d97706; border-color: #d97706; }
html[data-theme="dark"] .btn-ok:hover { background: #b45309; }
html[data-theme="dark"] .change-badge { background: #b45309; }

html[data-theme="dark"] .input { background: var(--surface-2); }
html[data-theme="dark"] .search { background: var(--surface); }
html[data-theme="dark"] select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238d95a7' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

html[data-theme="dark"] .form-error,
html[data-theme="dark"] .conn[data-state="offline"] { border-color: #5c2427; }
html[data-theme="dark"] .chip-ok { border-color: #1f5133; }
html[data-theme="dark"] .banner-warn { border-color: #3a3f78; color: #c7cbff; }
html[data-theme="dark"] .banner-danger { border-color: #5c2427; color: #fca5a5; }

html[data-theme="dark"] mark { background: #5b4a12; color: #fff3c4; }
html[data-theme="dark"] .row.is-open-admin { background-color: #1f1b12; }
html[data-theme="dark"] .change-line .old { color: #d6a35a; }
html[data-theme="dark"] .h-up { color: #f87171; }
html[data-theme="dark"] .h-down { color: #4ade80; }

html[data-theme="dark"] .toast { background: #262b36; border: 1px solid #343b4a; }
html[data-theme="dark"] .toast-error { background: #4a1d1f; border-color: #6b2a2d; }
html[data-theme="dark"] .modal::backdrop { background: rgba(0, 0, 0, .6); }
html[data-theme="dark"] .modal-card { border: 1px solid var(--border); }
html[data-theme="dark"] .login-card { box-shadow: var(--shadow-lg); }

html[data-theme="dark"] .row.is-dragging,
html[data-theme="dark"] .sub.is-dragging { background: var(--surface-2); }

/* ---------- Состояние товара: New / Б/У ---------- */

.cond-badge {
  flex: none; display: inline-flex; align-items: center;
  height: 19px; padding: 0 7px; margin-right: 4px; border-radius: 6px;
  font-size: 10.5px; font-weight: 750; letter-spacing: .04em; line-height: 1;
  border: 1px solid;
}
.cond-new { color: #067647; background: #ecfdf3; border-color: #abefc6; }
.cond-used { color: #93370d; background: #fff6ed; border-color: #f9dbaf; }
html[data-theme="dark"] .cond-new { color: #4ade80; background: #11291b; border-color: #1f5133; }
html[data-theme="dark"] .cond-used { color: #fdba74; background: #2b1d10; border-color: #6b4317; }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.segment { position: relative; cursor: pointer; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: flex; align-items: center; justify-content: center; height: 32px; border-radius: 6px;
  font-weight: 600; font-size: 13px; color: var(--muted); transition: background-color .15s, color .15s, box-shadow .15s;
}
.segment:hover span { color: var(--text); }
.segment input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.segment input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segment-new input:checked + span { background: #ecfdf3; color: #067647; box-shadow: inset 0 0 0 1px #abefc6; }
.segment-used input:checked + span { background: #fff6ed; color: #93370d; box-shadow: inset 0 0 0 1px #f9dbaf; }
html[data-theme="dark"] .segment-new input:checked + span { background: #11291b; color: #4ade80; box-shadow: inset 0 0 0 1px #1f5133; }
html[data-theme="dark"] .segment-used input:checked + span { background: #2b1d10; color: #fdba74; box-shadow: inset 0 0 0 1px #6b4317; }

/* ---------- Оповещения в Telegram ---------- */

.tg-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.tg-card, .tg-help {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.tg-badge {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.tg-badge.is-on { color: var(--ok); background: var(--ok-bg); border-color: #abefc6; }
.tg-badge.is-off { color: var(--pending-text); background: var(--pending-bg); border-color: var(--pending-border); }
html[data-theme="dark"] .tg-badge.is-on { border-color: #1f5133; }
.mono { font-family: var(--mono); font-size: 13px; }

.switch-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; cursor: pointer; font-weight: 600; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative; flex: none; width: 40px; height: 22px; border-radius: 999px;
  background: var(--border-strong); transition: background-color .2s;
}
.switch::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch-row input:checked + .switch { background: var(--ok); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.check-row { display: flex; align-items: center; gap: 9px; padding: 4px 0; cursor: pointer; color: var(--text-2); }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.tg-chats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 30px; align-items: center; }
.tg-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px;
  background: var(--accent-soft); color: var(--text); border-radius: 999px; font-size: 13px; font-weight: 550;
}
.tg-chip code { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.tg-chip-x {
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  font-size: 16px; line-height: 1;
}
.tg-chip-x:hover { background: var(--surface-hover); color: var(--danger); }
.tg-empty { color: var(--muted); font-size: 13px; }
.tg-chat-add { display: flex; gap: 8px; flex-wrap: wrap; }
.tg-chat-add .input { flex: 1 1 200px; height: 36px; }
.tg-found { margin-top: 10px; display: grid; gap: 6px; }
.tg-found-title { margin: 0; font-size: 13px; color: var(--muted); }
.tg-found-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; text-align: left;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.tg-found-item:hover { border-color: var(--accent); }
.tg-found-item span { grid-column: 1; font-size: 12px; color: var(--muted); }
.tg-found-item em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; font-weight: 600; color: var(--accent); font-size: 13px; }

.tg-last { font-size: 12.5px; color: var(--muted); margin: 0 0 14px; }
.tg-last:empty { display: none; }
.tg-last-error { color: var(--danger); }
.tg-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tg-disconnect { margin-left: auto; color: var(--danger); }

.tg-help h3 { margin: 0 0 10px; font-size: 15px; }
.tg-help ol { margin: 0 0 16px; padding-left: 20px; color: var(--text-2); line-height: 1.55; }
.tg-help li { margin-bottom: 8px; }
.tg-help code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.tg-sample-title { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.tg-sample {
  font-size: 13px; line-height: 1.45; padding: 10px 12px; border-radius: 12px 12px 12px 4px;
  background: #effdde; color: #1b1b1b; border: 1px solid #d9eec3; max-width: 340px;
}
html[data-theme="dark"] .tg-sample { background: #2b5278; color: #f1f5f9; border-color: #2b5278; }

@media (max-width: 860px) { .tg-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .tg-card, .tg-help { padding: 16px; }
  .tg-disconnect { margin-left: 0; }
  .tabs { overflow-x: auto; }
}

/* ---------- Запрос подтверждения цены ---------- */

.modal-extra { margin-right: auto; color: var(--pending-text); border-color: var(--pending-border); background: var(--pending-bg); }
.modal-extra:hover:not(:disabled) { background: var(--pending-bg-strong); border-color: var(--pending); }
.modal-extra svg { width: 15px; height: 15px; }
.confirm-ask { font-weight: 600; }
@media (max-width: 640px) {
  .modal-foot { flex-wrap: wrap; }
  .modal-extra { width: 100%; margin-right: 0; order: 3; }
}

/* ---------- Перенос товаров между категорией и подкатегориями ---------- */

.drag-root .row:not(.is-dragging) { opacity: .92; }
.sub.drop-target > .sub-head { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.sub:has(> .row) > .empty-cat { display: none; }
