:root {
  --bg: #f3f0e9;
  --surface: #ffffff;
  --surface-2: #f7f5f0;
  --text: #1f2328;
  --muted: #5f6368;
  --line: #e2ded5;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #2f7a23;
  --ok-soft: #e6f3e2;
  --warn: #b26a00;
  --warn-soft: #fff1dc;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #202328;
    --surface-2: #262a30;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #353a41;
    --accent: #60a5fa;
    --accent-ink: #0b1220;
    --accent-soft: #1d2a40;
    --ok: #7bd389;
    --ok-soft: #1c3322;
    --warn: #f0b45a;
    --warn-soft: #3a2c14;
    --bad: #ff8a80;
    --bad-soft: #3d1f1f;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }

/* Шапка и навигация */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1440px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { flex: none; white-space: nowrap; font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-icon { width: 28px; height: 28px; flex: none; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { font-weight: 500; color: var(--muted); font-size: 11.5px; letter-spacing: .01em; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; order: 3; width: 100%; padding-bottom: 2px; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  white-space: nowrap; padding: 7px 10px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 14px;
}
.nav a:hover { background: var(--surface); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--line); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
/* Пункты меню всегда по центру: во второй строке — авто-отступами (прокрутка не ломается),
   в одну строку (класс one-row ставит скрипт в base.html, если меню помещается) — сеткой 1fr|auto|1fr */
.nav > a:first-child { margin-left: auto; }
.nav > a:last-child { margin-right: auto; }
.top.one-row .top-inner { display: grid; grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr); }
.top.one-row .brand { justify-self: start; }
.top.one-row .nav { order: 0; width: auto; padding-bottom: 0; }
.top.one-row .top-right { justify-self: end; margin-left: 0; }

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 24px; margin: 4px 0 4px; letter-spacing: -.01em; }
.lead { color: var(--muted); margin: 0 0 20px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* Карточки */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; min-width: 0;
}
.grid .card { margin-bottom: 0; }
.stat-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 18px; font-weight: 650; margin: 4px 0 2px; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
table.components form.rename { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
table.components form.rename input { flex: 1 1 160px; max-width: 240px; padding: 6px 10px; font-size: 13px; }
.src-list { list-style: none; margin: 8px 0 6px; padding: 0; display: grid; gap: 5px; }
.src-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.src-list .src-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-list .badge { padding: 1px 9px; font-size: 12px; flex: none; }

/* Значки */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.sky { background: rgba(3, 155, 229, .15); color: #039be5; }   /* предбронь ведомственная */
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; vertical-align: middle; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Сообщения */
.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.err { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alerts { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.alerts h2 { color: var(--warn); }
.alerts ul { margin: 0; padding-left: 18px; }
.alerts li { margin: 4px 0; }

/* Формы */
form { margin: 0; }
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=email], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; outline: none;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; margin: 10px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.row { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 14px; }
.row label { margin-top: 0; }
.row > div > label { margin-top: 0; }
@media (max-width: 440px) { .row > div + div > label { margin-top: 14px; } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--line); }
.seg small { display: block; font-weight: 400; font-size: 12px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--bad); }
button.small { padding: 6px 12px; font-size: 13px; }
button.link { border: none; background: none; padding: 6px 8px; color: var(--muted); font-weight: 500; }
.inline { display: inline; }

/* Списки и таблицы */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: none; padding-top: 0; }
.ev-title { font-weight: 600; }
.ev-meta { color: var(--muted); font-size: 13px; }
table.log { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.log td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.log td.t { white-space: nowrap; color: var(--muted); width: 1%; }
table.log td.m { white-space: pre-wrap; overflow-wrap: anywhere; }
table.components td.c { color: var(--text); }
table.components td.c .muted { font-size: 13px; }
.lvl-error { color: var(--bad); font-weight: 600; }
.lvl-warn { color: var(--warn); font-weight: 600; }
pre.box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow: auto; max-height: 260px; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; }
.copy { display: flex; gap: 8px; align-items: stretch; }
.copy input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 4px 0; }
.muted { color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.filters a { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; }
.filters a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Вход */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .logo { text-align: center; }
.login .logo img { display: inline-block; vertical-align: top; }
.login h1 { text-align: center; margin-bottom: 2px; }
.login .lead { text-align: center; }
.login button { width: 100%; margin-top: 18px; padding: 11px; }
footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 0 16px 28px; }

.user-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-main { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; color: var(--text); }
.user-main:hover { text-decoration: none; }
.user-main:hover .ev-title { color: var(--accent); }
.user-tags { display: flex; gap: 6px; flex-wrap: wrap; }
/* Отделы на странице «Пользователи» */
.users-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.users-bar .btn { white-space: nowrap; }
details.dept { padding: 0; overflow: hidden; }
.dept-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 18px 20px; cursor: pointer; list-style: none; user-select: none; }
.dept-head * { cursor: pointer; }
.dept-head::-webkit-details-marker { display: none; }
.dept-head:hover .dept-title { color: var(--accent); }
.dept-chev { font-size: 26px; line-height: 1; color: var(--muted); transition: transform .15s; width: 14px; text-align: center; }
details.dept[open] .dept-chev { transform: rotate(90deg); }
.dept-title { font-size: 24px; font-weight: 700; line-height: 1.2; min-width: 0; overflow-wrap: anywhere; }
.dept-count { display: inline-block; min-width: 26px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; text-align: center; }
.dept-body { padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.dept-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
/* Окна */
dialog.modal { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 24px));
               max-height: calc(100vh - 40px); background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog.modal::backdrop { background: rgba(0,0,0,.45); }
dialog.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 42px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 4px 18px 16px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.check.pick { padding: 8px 0; margin: 0; border-bottom: 1px solid var(--line); }
.check.pick:last-of-type { border-bottom: none; }
.gacc { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; background: var(--surface-2); }
.gacc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gacc .check { margin: 8px 0 0; }
details > summary { list-style-position: outside; }
.btn.small { padding: 5px 12px; font-size: 13px; }
table.versions td { vertical-align: middle; white-space: nowrap; }
details > summary.btn { list-style: none; cursor: pointer; }
details > summary.btn::-webkit-details-marker { display: none; }
@media (max-width: 560px) {
  table.versions td:nth-child(2), table.versions td:nth-child(4) { display: none; }
  table.versions td { white-space: normal; padding: 7px 4px; }
  table.versions .btn.small { padding: 5px 9px; white-space: nowrap; }
}
.colors { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input { max-width: 150px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.color-row select { max-width: 200px; }
.swatch { display: inline-block; width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); flex: none; }

@media (min-width: 1180px) { .nav a { padding: 7px 8px; font-size: 13.5px; } }
@media (min-width: 1440px) { .nav { gap: 1px; } .nav a { padding: 6px 6px; font-size: 13px; } .brand small { font-size: 10.5px; } }

/* Публичные страницы: о приложении, политика */
.pub-hero { display: flex; gap: 16px; align-items: center; margin: 4px 0 8px; }
.pub-hero img { border-radius: 16px; flex: none; }
.pub-list { padding-left: 20px; margin: 6px 0 12px; }
.pub-list li { margin: 6px 0; }
.pub-sep { border: none; border-top: 1px solid var(--line); margin: 28px 0 8px; }

/* «Ближайшие мероприятия»: подтверждённые разворачиваются */
details.ev-card > summary { list-style: none; cursor: pointer; }
details.ev-card > summary::-webkit-details-marker { display: none; }
details.ev-card .ev-more { display: inline-block; margin-top: 4px; color: var(--accent); font-size: 13px; }
details.ev-card[open] .ev-more { font-size: 0; }
details.ev-card[open] .ev-more::after { content: "▾ Свернуть"; font-size: 13px; }
details.ev-card .ev-desc {
  white-space: pre-line; overflow-wrap: anywhere; font-size: 14px; margin-top: 8px; padding: 10px 12px;
  border-radius: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
}

.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; vertical-align: -2px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Active Directory: выбор групп и подразделений */
.scope-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; margin-top: 8px; }
.scope-list label.check { margin: 6px 0; }
.ad-block-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.ad-block-head h2 { margin: 0; }
.ad-pw-all { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 14px; }
.ad-pw-all label.check { margin: 0; }

/* Вкладки страницы настроек (например, «Битрикс24») */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.tabs a { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 14px; }
.tabs a:hover { text-decoration: none; border-color: var(--accent); }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.actions .spacer { flex: 1; }
.stage-row { margin-top: 10px; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); }
.stage-row .stage-name { font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 440px) { .stage-row .stage-name { margin-bottom: 6px; } }
.uc-src { padding: 12px 0; border-top: 1px solid var(--line); }
.uc-src:first-of-type { border-top: 0; padding-top: 4px; }
.uc-src-head { display: flex; gap: 10px; align-items: center; }
.uc-src-head .dot { width: 12px; height: 12px; flex: none; }
.uc-src-head input { font-weight: 600; }
.uc-src-meta { font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }
.uc-src .actions { margin-top: 8px; flex-wrap: wrap; }
input.uc-color { width: 64px; height: 38px; padding: 2px; cursor: pointer; }

/* ---------- админка лицензирования ---------- */
main.adm { max-width: 1200px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.page-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
a.btn.primary:hover { text-decoration: none; }
.stat-value.big { font-size: 28px; }
.stat-value small { font-size: 16px; font-weight: 500; color: var(--muted); }
.pills { display: flex; gap: 6px; margin-top: 4px; }
.meter { height: 5px; border-radius: 3px; background: var(--line); margin-top: 10px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
@media (max-width: 760px) { .grid.two { grid-template-columns: minmax(0, 1fr); } }
.card h2 small { font-weight: 500; font-size: 13px; }
dl.kv button.link { color: var(--accent); padding: 0; font-weight: 500; }
.li-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.li-row > .muted { grid-column: 1 / -1; font-size: 13px; }
.li-row .badge { justify-self: end; }
dl.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 12px; margin: 8px 0 16px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.card.wide { overflow-x: auto; }
table.clients { width: 100%; border-collapse: collapse; font-size: 14px; }
table.clients th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.clients td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.clients tr:last-child td { border-bottom: 0; }
table.clients tr.off td { opacity: .6; }
table.clients .mono { font-size: 13px; }
form.search { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.search input { flex: 1 1 260px; width: auto; }
form.search select { flex: 0 0 auto; width: auto; }
.danger-zone { border-color: color-mix(in srgb, var(--bad, #d33) 45%, var(--line)); }
.danger-zone h2 { color: var(--bad, #c62828); }
pre.qr { line-height: 1; font-size: 8px; }
.seg.two { grid-template-columns: repeat(2, 1fr); max-width: 520px; margin-bottom: 4px; }
[hidden] { display: none !important; }
table.upd td { vertical-align: top; }
td.nowrap { white-space: nowrap; }
table.upd pre.box { white-space: pre-wrap; max-height: 320px; overflow: auto; font-size: 12px; }
button[disabled] { opacity: .5; cursor: default; }
