:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --ink: #1b2436;
  --ink-2: #4a5468;
  --muted: #7b8497;
  --line: #e2e5ec;
  --line-2: #eef0f4;
  --accent: #3552c9;
  --accent-ink: #ffffff;
  --accent-soft: #eaeefc;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c53030;
  --crit-bg: #fde2e2; --crit: #b42318;
  --high-bg: #feead7; --high: #b54708;
  --med-bg:  #fdf3c7; --med:  #8a6100;
  --low-bg:  #dff3e4; --low:  #2b6a3f;
  --shadow: 0 1px 2px rgba(20, 28, 45, .05), 0 4px 16px rgba(20, 28, 45, .05);
  --radius: 12px;
  color-scheme: light;
}
/* Тема: по умолчанию системная. Выбор пользователя ставит data-theme на <html>
   (см. переключатель в шапке) и перекрывает системную настройку. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151d; --panel: #181e29; --ink: #e8ebf2; --ink-2: #b8bfcd; --muted: #8790a2;
    --line: #2a3242; --line-2: #222937; --accent: #7b93f0; --accent-ink: #0d1220; --accent-soft: #232c47;
    --crit-bg: #4a1d1d; --crit: #ffb4ab; --high-bg: #4a2d14; --high: #ffc58a;
    --med-bg: #43391a; --med: #f3d77c; --low-bg: #1c3a27; --low: #9ddcb0;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #11151d; --panel: #181e29; --ink: #e8ebf2; --ink-2: #b8bfcd; --muted: #8790a2;
    --line: #2a3242; --line-2: #222937; --accent: #7b93f0; --accent-ink: #0d1220; --accent-soft: #232c47;
    --crit-bg: #4a1d1d; --crit: #ffb4ab; --high-bg: #4a2d14; --high: #ffc58a;
    --med-bg: #43391a; --med: #f3d77c; --low-bg: #1c3a27; --low: #9ddcb0;
    --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
}
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 10px 4px; }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* ── верх ── */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok i { background: var(--ok); }
.conn.bad i { background: var(--bad); }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 9px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: border-color .15s, background .15s, box-shadow .15s;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { box-shadow: 0 2px 10px rgba(53, 82, 201, .3); }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.big { padding: 12px 22px; font-size: 15px; }
.btn.wide { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ── раскладка ── */
.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - 62px); }
.side { border-right: 1px solid var(--line); padding: 18px 14px; background: var(--panel); }
.side-title { margin: 20px 4px 8px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.history { display: flex; flex-direction: column; gap: 4px; max-height: calc(100vh - 170px); overflow: auto; }
.h-item {
  text-align: left; border: 1px solid transparent; background: transparent; border-radius: 9px;
  padding: 9px 10px; cursor: pointer; display: grid; gap: 3px;
}
.h-item:hover { background: var(--line-2); }
.h-item.active { background: var(--accent-soft); border-color: var(--accent); }
.h-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.main { padding: 26px 32px 60px; max-width: 1280px; width: 100%; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .history { max-height: 220px; }
  .main { padding: 18px 16px 48px; }
  .top { padding: 10px 16px; }
  .brand-sub { display: none; }
}

/* ── карточки/форма ── */
h1 { font-size: 23px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 10px; }
.lead { color: var(--ink-2); margin: 0 0 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2 { display: flex; align-items: center; gap: 10px; }
.step { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 800; display: inline-grid; place-items: center; flex: none; }
.card-note { color: var(--muted); font-size: 12.5px; margin: -4px 0 14px; }

label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
label .req { color: var(--bad); }
input[type=text], input[type=url], input[type=password], input:not([type]), textarea, select {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--panel);
  font-weight: 400; font-size: 14px; color: var(--ink); width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid2, .grid3, .row2 { grid-template-columns: 1fr; } }
.full { grid-column: 1 / -1; }

.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s; background: var(--line-2);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop b { display: block; font-size: 15px; margin-bottom: 4px; }
.files { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.files li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.files .ext { font-size: 10.5px; font-weight: 800; padding: 3px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; }
.files .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.x:hover { color: var(--bad); background: var(--line-2); }

.seg { display: grid; gap: 8px; }
.seg-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 700px) { .seg-opts { grid-template-columns: 1fr; } }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; }
.opt span {
  display: block; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer;
  font-weight: 400; color: var(--ink-2); height: 100%;
}
.opt span b { display: block; color: var(--ink); font-size: 13.5px; margin-bottom: 2px; }
.opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; }
.chip { position: relative; }
.chip span { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.submit-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 6px; }

/* ── статусы ── */
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill.run { background: var(--accent-soft); color: var(--accent); }
.pill.done { background: var(--low-bg); color: var(--low); }
.pill.err { background: var(--crit-bg); color: var(--crit); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.critical { background: #e5484d; } .dot.high { background: #f76b15; } .dot.medium { background: #f5c518; } .dot.low { background: #30a46c; }
.cnt { display: inline-flex; align-items: center; gap: 3px; }
.spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ── просмотр проверки ── */
.rv-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.rv-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rv-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 6px; }
.progress div { border-top: 3px solid var(--line); padding-top: 8px; font-size: 12.5px; color: var(--muted); }
.progress div.on { border-color: var(--accent); color: var(--ink); font-weight: 600; }
.progress div.cur { border-color: var(--accent); color: var(--accent); font-weight: 700; }
@media (max-width: 700px) { .progress { grid-template-columns: 1fr 1fr; } }
.errbox { border: 1px solid var(--crit); background: var(--crit-bg); color: var(--crit); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; word-break: break-word; }

.verdict { border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; display: grid; gap: 6px; border: 1px solid; }
.verdict b { font-size: 16px; }
.verdict.sign { background: var(--low-bg); color: var(--low); border-color: currentColor; }
.verdict.sign_with_protocol { background: var(--high-bg); color: var(--high); border-color: currentColor; }
.verdict.do_not_sign { background: var(--crit-bg); color: var(--crit); border-color: currentColor; }
.verdict p { margin: 0; color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat .n { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; }
.t th { text-align: left; background: var(--line-2); padding: 9px 10px; font-size: 12px; color: var(--ink-2); position: sticky; top: 0; }
.t td { border-top: 1px solid var(--line); padding: 9px 10px; vertical-align: top; }
.t td.num { color: var(--muted); font-variant-numeric: tabular-nums; width: 36px; }
.t td.cl { white-space: nowrap; color: var(--ink-2); }
.t tr.risk { cursor: pointer; }
.t tr.risk:hover td { background: var(--line-2); }
.t tr.more td { background: var(--line-2); padding: 12px 16px; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.more-grid h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.more-grid p { margin: 0; white-space: pre-wrap; }
@media (max-width: 900px) { .more-grid { grid-template-columns: 1fr; } }
.lvl { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 12px; padding: 3px 9px; border-radius: 6px; white-space: nowrap; }
.lvl.critical { background: var(--crit-bg); color: var(--crit); }
.lvl.high { background: var(--high-bg); color: var(--high); }
.lvl.medium { background: var(--med-bg); color: var(--med); }
.lvl.low { background: var(--low-bg); color: var(--low); }
.t td.pre { white-space: pre-wrap; min-width: 220px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; }
.kv > div { padding: 8px 12px; border-top: 1px solid var(--line); }
.kv > div:nth-child(odd) { font-weight: 600; color: var(--ink-2); background: var(--line-2); }
.notes { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.internal { font-size: 12px; font-weight: 700; color: var(--crit); margin-bottom: 8px; }

/* ── диалог и тост ── */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; max-width: 620px; width: calc(100% - 32px); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(15, 20, 30, .45); }
.dlg form { display: grid; gap: 12px; }
.dlg p { margin: -4px 0 4px; font-size: 13px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.hint { font-weight: 500; font-size: 11.5px; }
.hint.set { color: var(--ok); }
.hint.unset { color: var(--warn); }
.ping-out { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; background: var(--line-2); white-space: pre-line; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 20; max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); color: #fff; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ── вход и сотрудники ── */
.me { font-size: 12.5px; color: var(--ink-2); text-align: right; line-height: 1.25; }
.me b { display: block; color: var(--ink); font-size: 13px; }
.auth { min-height: calc(100vh - 62px); display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center; }
.auth-card img { margin: 0 auto; }
.auth-card h1 { margin: 0; }
.auth-card p { margin: 0; }
.auth-card label { text-align: left; }
.auth-err { color: var(--crit); background: var(--crit-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.small { font-size: 12px; }
.wide-dlg { max-width: 860px; }
.dlg-body { display: grid; gap: 12px; }
.dlg h3 { margin: 6px 0 10px; font-size: 14px; }
select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--panel); color: var(--ink); width: 100%; }
.user-form { border-top: 1px solid var(--line); padding-top: 12px; }
.pass-row { display: flex; gap: 10px; align-items: flex-end; margin-top: 12px; flex-wrap: wrap; }
.created { border: 1px solid var(--ok); background: var(--low-bg); color: var(--ink); border-radius: 10px; padding: 12px 14px; white-space: pre-line; }
.created code { font-size: 14px; font-weight: 700; user-select: all; }
.role-admin { color: var(--accent); font-weight: 700; }
.owner { color: var(--ink-2); }
.t .acts { white-space: nowrap; text-align: right; }
.t .acts .btn { padding: 5px 9px; font-size: 12px; }

/* Переключатель темы */
.theme-btn { padding: 7px 10px; font-size: 15px; line-height: 1; }
.top-right { display: flex; align-items: center; gap: 12px; }
