:root {
  --navy: #103a5c;
  --navy-2: #1f4e78;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #dfe4ea;
  --text: #1c2430;
  --muted: #6a7585;
  --accent: #1f6feb;
  --ok-bg: #e3f4e8; --ok: #1e6b3a;
  --warn-bg: #fff4d6; --warn: #8a5a00;
  --info-bg: #e8f0fe; --info: #2457a6;
  --gray-bg: #eceef2; --gray: #4a5363;
  --purple-bg: #f2eaf5; --purple: #6b3a8a;
  --bad-bg: #fdeded; --bad: #b42318;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #103a5c 0%, #1f4e78 100%); }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card p { margin: -6px 0 4px; }
label { display: grid; gap: 5px; font-weight: 500; font-size: 13px; }
label.inline, label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,111,235,.25); border-color: var(--accent); }
input[type=checkbox] { padding: 0; }
.form-error { color: var(--bad); min-height: 1em; font-size: 13px; }

.brand { font-weight: 800; letter-spacing: .5px; color: #fff; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .75; }
.brand.big { color: var(--navy); font-size: 22px; }

/* кнопки */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b9c2cd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #185bc4; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.wide { width: 100%; padding: 10px; }
.btn.danger { color: var(--bad); }
.btn.on-dark { color: #fff; border-color: rgba(255,255,255,.35); }
.btn:disabled { opacity: .5; cursor: default; }

/* шапка */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 0 16px; height: 52px; background: var(--navy); color: #fff; }
#nav { display: flex; gap: 2px; overflow-x: auto; }
#nav button { background: none; border: 0; color: rgba(255,255,255,.75); padding: 16px 12px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
#nav button:hover { color: #fff; }
#nav button.active { color: #fff; border-bottom-color: #6cb2ff; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.whoami { opacity: .8; }
.live { display: inline-flex; align-items: center; gap: 6px; opacity: .9; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #f0b429; }
.live.on i { background: #3ddc84; box-shadow: 0 0 0 3px rgba(61,220,132,.25); }
.live.off i { background: #ff6b6b; }

main { padding: 12px 16px 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.toolbar input[type=search] { width: 260px; }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 7px 11px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--navy); color: #fff; }
.stats { display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 2px 8px; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); }
.bulkbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 8px; background: #fff8e1; border: 1px solid #f3d98b; border-radius: var(--radius); }

/* таблица */
.grid { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tabulator { font-size: 13px; border: 0; background: #fff; }
.tabulator .tabulator-header { background: #f0f3f7; border-bottom: 1px solid var(--line); }
.tabulator .tabulator-header .tabulator-col { background: #f0f3f7; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 7px 8px; }
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input,
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter select { padding: 3px 5px; font-size: 12px; border-radius: 4px; }
.tabulator-row .tabulator-cell { padding: 6px 8px; border-right: 1px solid #eef1f4; }
.tabulator-row.tabulator-row-even { background: #fafbfc; }
.tabulator-row.has-issue { box-shadow: inset 3px 0 0 var(--bad); }
.tabulator-row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff1a8; } to { background: inherit; } }
.tabulator-row.deleted { opacity: .4; text-decoration: line-through; }
.tabulator .tabulator-footer { background: #f7f9fb; border-top: 1px solid var(--line); }
.tabulator-cell.tabulator-editable:hover { background: #f1f6ff; cursor: text; }
.tabulator-row.selected { background: #eaf2ff !important; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.gray { background: var(--gray-bg); color: var(--gray); }
.pill.purple { background: var(--purple-bg); color: var(--purple); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.issue { color: var(--bad); font-size: 12px; }
.ico { border: 0; background: none; cursor: pointer; padding: 2px 5px; border-radius: 4px; color: var(--muted); font-size: 14px; }
.ico:hover { background: var(--gray-bg); color: var(--text); }
.ico.danger:hover { background: var(--bad-bg); color: var(--bad); }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* панели */
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; align-items: start; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel h3 { margin: 0 0 6px; font-size: 15px; }
.panel p { margin: 0 0 10px; font-size: 13px; }
.table-wrap { overflow-x: auto; max-height: 70vh; overflow-y: auto; }
table.simple { border-collapse: collapse; width: 100%; font-size: 13px; }
table.simple th, table.simple td { padding: 6px 8px; border-bottom: 1px solid #eef1f4; text-align: left; white-space: nowrap; }
table.simple th { position: sticky; top: 0; background: #f0f3f7; font-weight: 600; z-index: 1; }
table.simple td.num, table.simple th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.simple tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfc; position: sticky; bottom: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1 1 140px; }

/* документация */
.doc { max-width: 940px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; line-height: 1.55; }
.doc h2 { margin: 0 0 8px; }
.doc h3 { margin: 22px 0 6px; }
.doc code { background: #f1f3f6; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.doc pre { background: #0f1b2a; color: #dbe7f5; padding: 12px 14px; border-radius: 6px; overflow-x: auto; font-size: 12.5px; line-height: 1.45; }
.doc pre code { background: none; padding: 0; color: inherit; }
.doc table.simple td { white-space: normal; }
.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow code { flex: 1; overflow-x: auto; padding: 8px; }

/* модальное окно */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 12px; width: 100%; max-width: 680px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
#modal-body { padding: 16px 18px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid textarea { min-height: 70px; resize: vertical; }
.field-error { color: var(--bad); font-size: 12px; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 8px 0; border-bottom: 1px solid #eef1f4; font-size: 13px; }
.history .meta { color: var(--muted); font-size: 12px; }
.history del { color: var(--bad); }
.history ins { color: var(--ok); text-decoration: none; }
.rules li { margin-bottom: 6px; }

/* уведомления */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: #1c2430; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toastin .2s ease-out; }
.toast.error { background: var(--bad); }
.toast.ok { background: #1e6b3a; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 4px 12px; }
  #nav { order: 3; width: 100%; }
  #nav button { padding: 10px 10px; }
  .whoami { display: none; }
  main { padding: 10px 10px 12px; }
  .toolbar input[type=search] { width: 100%; }
  .seg { overflow-x: auto; max-width: 100%; }
  .panels { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; height: 100%; border-radius: 0; }
}

/* закреплённые столбцы не должны просвечивать при горизонтальной прокрутке */
.tabulator-row .tabulator-cell.tabulator-frozen { background: inherit; }
.tabulator .tabulator-header .tabulator-col.tabulator-frozen { background: #f0f3f7; }
.tabulator-row { background: #fff; }

/* действующие фильтры над таблицей продаж */
.stats .filters { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text); }
.chip { background: #fff4d6; color: #8a5a00; border: 1px solid #f3d98b; border-radius: 10px; padding: 1px 8px; font-size: 12px; }

/* фильтр периода в столбце «Дата» */
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter select.date-filter { width: 100%; padding: 3px 4px; font-size: 12px; border-radius: 4px; }
.month-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 760px) { .month-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* правки редакторов, которые администратор ещё не просмотрел */
.badge-review { display: inline-block; font-weight: 700; font-size: 11px; letter-spacing: .3px; padding: 2px 7px; border-radius: 4px; cursor: pointer; }
.badge-review.editor { background: var(--bad); color: #fff; }
.badge-review.editor:hover { background: #8f1c13; }
.badge-review.admin { background: #f5c400; color: #3d2f00; }
.badge-review.admin:hover { background: #dcae00; }
.review-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tabulator-row .tabulator-cell.cell-changed-editor { background: #fdeded; box-shadow: inset 0 0 0 2px #f1a39c; }
.tabulator-row .tabulator-cell.cell-changed-admin { background: #fff6cc; box-shadow: inset 0 0 0 2px #f0d264; }
.nav-count, .review-btn .count { background: var(--bad); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 5px; }
.review-btn.active { border-color: var(--bad); color: var(--bad); font-weight: 600; }

/* подсказка о синхронизации листов группы */
.sync-hint { flex-basis: 100%; color: #1f4e78; background: #eef4fb; border: 1px solid #d3e3f5; border-radius: 6px; padding: 4px 10px; }
