:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #1b2430;
  --muted: #5d6978;
  --line: #dfe4ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --ok: #17733f;
  --ok-soft: #e4f5ea;
  --warn: #8f5200;
  --warn-soft: #fff3df;
  --err: #b3261e;
  --err-soft: #fdeceb;
  --chip: #eef1f5;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #20272f;
    --ink: #e7ebf0;
    --muted: #9aa6b4;
    --line: #2e3742;
    --accent: #5b9dff;
    --accent-ink: #0d1117;
    --accent-soft: #1d2d45;
    --ok: #6bd39a;
    --ok-soft: #17301f;
    --warn: #eab568;
    --warn-soft: #33270f;
    --err: #ff8f87;
    --err-soft: #3a1b19;
    --chip: #262e38;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2 { line-height: 1.25; }
.container { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 16px; padding-bottom: 96px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap-any { overflow-wrap: anywhere; }
.pre { white-space: pre-line; }
.code { font-variant-numeric: tabular-nums; }
.page-title { font-size: 22px; margin: 4px 0 16px; }

/* Шапка */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 52px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: inherit; text-decoration: none; }
.mainnav { display: flex; gap: 14px; }
.mainnav a { color: var(--muted); text-decoration: none; padding: 4px 0; }
.mainnav a[aria-current="page"] { color: var(--ink); box-shadow: 0 2px 0 var(--accent); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.userbox form { margin: 0; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Формы */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 400;
}
textarea { resize: vertical; line-height: 1.45; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form-inline label { min-width: 200px; }

.auth-card {
  max-width: 420px; margin: 40px auto; padding: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 14px; font-size: 21px; }

.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; overflow-wrap: anywhere; }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.secret { display: inline-block; margin-left: 6px; padding: 2px 8px; font-size: 15px; background: var(--surface); color: var(--ink); border-radius: 6px; user-select: all; }

/* Вкладки и фильтры */
.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 10px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count { display: inline-block; min-width: 22px; padding: 0 6px; text-align: center; font-size: 12px; line-height: 18px; background: var(--chip); border-radius: 9px; font-weight: 500; color: var(--muted); }
.tabs-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; padding-bottom: 6px; flex-wrap: wrap; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters select { width: auto; max-width: 100%; }
.filter-search { flex: 1 1 180px; }

.bulkbar {
  position: sticky; top: var(--topbar-h, 53px); z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.bulkbar.has-selection { background: var(--accent-soft); border-color: var(--accent); }
.check-inline { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.bulk-count { color: var(--muted); }
.bulkbar.has-selection .bulk-count { color: var(--ink); font-weight: 600; }
.bulk-actions { margin-left: auto; display: flex; gap: 8px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

/* Карточки */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card.is-selected { border-color: var(--accent); }
.card-done { opacity: .82; }
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.check { padding-top: 3px; cursor: pointer; }
.card-title { flex: 1; min-width: 0; }
.card-title h2 { font-size: 15.5px; font-weight: 600; margin: 0 0 2px; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin: 0; font-size: 13px; color: var(--muted); }
.card-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--chip); color: var(--muted); }
.conf-high { background: var(--ok-soft); color: var(--ok); }
.conf-medium { background: var(--accent-soft); color: var(--accent); }
.conf-low { background: var(--warn-soft); color: var(--warn); }
.status-published { background: var(--ok-soft); color: var(--ok); }
.status-failed { background: var(--err-soft); color: var(--err); }
.status-conflict { background: var(--warn-soft); color: var(--warn); }
.status-approved, .status-publishing { background: var(--accent-soft); color: var(--accent); }

.proposal { margin-top: 10px; }
.field { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 2px 10px; padding: 5px 0; }
.field-label { color: var(--muted); font-size: 13px; padding-top: 1px; }
.field-value p { margin: 2px 0 0; }
.prop-link { overflow-wrap: anywhere; }
.desc { white-space: pre-line; overflow-wrap: anywhere; }
.desc.is-clamped { max-height: 6.6em; overflow: hidden; position: relative; }
.desc.is-clamped::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.2em;
  background: linear-gradient(to bottom, transparent, var(--surface));
}
.reason { margin: 6px 0 0; color: var(--muted); }
.empty-note { margin: 8px 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; color: var(--muted); }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 5px; padding: 0; margin: 8px 0 0; }
.chip { padding: 2px 9px; border-radius: 8px; font-size: 12.5px; background: var(--chip); color: var(--muted); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }

details > summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.current, .alts { margin-top: 8px; }
.current dl { margin: 6px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.current dt { color: var(--muted); font-size: 12.5px; }
.current dd { margin: 0 0 6px; font-size: 14px; }

.alt-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.alt { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.alt-main { flex: 1 1 320px; min-width: 0; }
.alt-main a { overflow-wrap: anywhere; }
.alt-main p { margin: 3px 0 0; }
.alt-text { color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.alt-actions { display: flex; flex-direction: column; gap: 4px; }
.tag { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 12px; background: var(--chip); color: var(--muted); }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }

.edit-form { margin-top: 10px; }
.edit-tools { margin: -6px 0 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.history { margin-left: auto; }

.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

/* Диалог и уведомление */
.dialog { max-width: 520px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 20px; }
.dialog::backdrop { background: rgba(15, 20, 28, .45); }
.dialog h2 { margin: 0 0 10px; font-size: 18px; }
.dialog ul { padding-left: 18px; margin: 8px 0; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.is-error { background: var(--err); color: #fff; }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.table-actions form { margin: 0; }
.details pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; max-width: 460px; margin: 6px 0 0; }
.panel { margin-top: 18px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel h2 { margin: 0 0 10px; font-size: 16px; }
.plain { margin: 0; padding-left: 18px; }

/* Продаваемые товары */
.sales-line { margin: 8px 0 0; color: var(--ink); overflow-wrap: anywhere; }
.value-a { background: var(--ok-soft); color: var(--ok); }
.value-b { background: var(--accent-soft); color: var(--accent); }
.value-c { background: var(--chip); color: var(--muted); }
.value-d { background: var(--chip); color: var(--muted); font-weight: 500; }
.sales-status-approved { background: var(--ok-soft); color: var(--ok); }
.sales-status-conflict { background: var(--warn-soft); color: var(--warn); }
.sales-status-rejected { background: var(--chip); color: var(--muted); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.alt-suggested { outline: 2px solid var(--ok); }
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.param-grid label { font-weight: 500; }
.panel .form { margin-top: 8px; }
.form label.check-inline { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

@media (max-width: 640px) {
  .mainnav { flex-wrap: wrap; row-gap: 4px; }
  .userbox { margin-left: 0; width: 100%; justify-content: space-between; }
  .bulkbar { position: static; }
  .bulk-actions { margin-left: 0; width: 100%; }
  .bulk-actions .btn { flex: 1; }
  .field { grid-template-columns: minmax(0, 1fr); }
  .card-head { flex-wrap: wrap; }
  .card-title { flex-basis: calc(100% - 44px); }
  .card-badges { width: 100%; justify-content: flex-start; }
  .tabs-tools { margin-left: 0; width: 100%; }
  .filters select, .filters .btn { flex: 1 1 45%; }
  .actions .btn { flex: 1 1 auto; }
  .history { margin-left: 0; }
}
