:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #667085; --line: #e3e6ec;
  --accent: #2f6fed; --accent-text: #fff; --hover: #f0f3fa;
  --ok: #1a7f4b; --ok-bg: #e3f4ea; --warn: #9a6700; --warn-bg: #fff4d6;
  --bad: #b42318; --bad-bg: #fde7e5; --info: #175cd3; --info-bg: #e3edff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --panel: #1b2029; --text: #e6e9f0; --muted: #98a2b3; --line: #2b3240;
    --accent: #5b8def; --accent-text: #0b1020; --hover: #232a36;
    --ok: #6ee7a8; --ok-bg: #123524; --warn: #f5c451; --warn-bg: #3a2f10;
    --bad: #ff8a80; --bad-bg: #3d1a17; --info: #8ab4ff; --info-bg: #172a4d;
    color-scheme: dark; /* встроенные элементы (выбор даты, списки) тоже тёмные */
  }
}
* { box-sizing: border-box; }
/* display: grid/flex у компонентов не должен перебивать атрибут hidden */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.spacer { flex: 1; }
main { padding: 20px; }
h1 { font-size: 20px; margin: 0 0 4px; word-break: break-all; }
h2 { font-size: 15px; margin: 0 0 10px; }
.mt { margin-top: 10px; }
.flush { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.row-flex { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

button, select, input[type=text], input[type=number], input[type=search], input[type=password], input[type=datetime-local], input[type=date], textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 10px; }
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
input[type=search] { min-width: 220px; }
.toolbar input[type=search] { width: 240px; max-width: 100%; }

.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted);
  margin-bottom: 10px; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--info-bg); }
.drop .picked { color: var(--text); font-weight: 600; word-break: break-all; }
progress { width: 100%; height: 10px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--hover); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.fname { word-break: break-all; font-weight: 500; }
/* Длинный текст в ячейках не переносится и не раздувает таблицу: обрезается многоточием, полный текст виден при наведении (см. app.js). */
td:not(.num):not(.actions):not(.check-cell):not(.progress-cell) { max-width: 28em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td:not(.num):not(.actions):not(.check-cell):not(.progress-cell) > div { overflow: hidden; text-overflow: ellipsis; }
td code.finding-value { display: inline-block; max-width: 100%; vertical-align: bottom; overflow: hidden; text-overflow: ellipsis; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.queued, .badge.processing { background: var(--info-bg); color: var(--info); }
.badge.processing::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.badge.done, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.partial, .badge.locked { background: var(--warn-bg); color: var(--warn); }
.badge.failed, .badge.corrupt { background: var(--bad-bg); color: var(--bad); }
.badge.cancelled, .badge.fmt { background: var(--hover); color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 14px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0; }
.meta dt { color: var(--muted); } .meta dd { margin: 0; word-break: break-all; }
pre.notice { white-space: pre-wrap; word-break: break-word; background: var(--warn-bg); color: var(--warn);
  border-radius: 8px; padding: 10px 12px; margin: 10px 0; font: inherit; }
pre.notice.bad { background: var(--bad-bg); color: var(--bad); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar .spacer { flex: 1; }
ul.tree, ul.children { list-style: none; margin: 0; padding: 0; }
ul.children { margin-left: 18px; border-left: 1px solid var(--line); padding-left: 6px; }
.node > .row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 6px; min-height: 28px; }
.node > .row:hover { background: var(--hover); }
.tog { width: 22px; height: 22px; padding: 0; border: none; background: none; color: var(--muted); line-height: 1; }
.tog:disabled { visibility: hidden; }
.icon { width: 20px; text-align: center; }
.name { word-break: break-all; }
.node.archive > .row .name, .node.dir > .row .name { font-weight: 600; cursor: pointer; }
.row .meta-r { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; white-space: nowrap; }
.hint { color: var(--muted); padding: 4px 8px; font-size: 14px; }
.sha { cursor: pointer; }
.sha:hover { color: var(--text); }
.results .path { word-break: break-all; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: 420px; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0,0,0,.2); word-break: break-word; }
.toast.error { border-color: var(--bad); color: var(--bad); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog input[type=password], dialog input[type=text] { width: 100%; margin: 8px 0; }
input[type=radio] { margin: 0 6px 0 0; vertical-align: middle; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
button.link { border: none; background: none; padding: 0 2px; color: var(--accent); font-size: 14px; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
.field { display: block; margin: 12px 0; border: none; padding: 0; }
.field select { width: 100%; margin-top: 4px; }
fieldset.field legend { padding: 0; margin-bottom: 4px; color: var(--muted); }
fieldset.field label { display: block; margin: 3px 0; }
ul.notes { margin: 6px 0; padding-left: 18px; font-size: 14px; }
ul.notes li { margin: 3px 0; word-break: break-word; }
.hint.err { color: var(--bad); }
#archiveDialog { width: min(520px, 94vw); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { padding: 5px 10px; border-radius: 7px; color: var(--muted); font-weight: 500; }
nav a:hover { background: var(--hover); text-decoration: none; color: var(--text); }
nav a[aria-current=page] { background: var(--info-bg); color: var(--info); }

.tag { --tag-hue: 210; display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 13px;
  font-weight: 600; border: 1px solid transparent; white-space: nowrap; line-height: 1.5;
  background: hsl(var(--tag-hue) 70% 92%); color: hsl(var(--tag-hue) 60% 28%); }
@media (prefers-color-scheme: dark) { .tag { background: hsl(var(--tag-hue) 40% 22%); color: hsl(var(--tag-hue) 80% 80%); } }
button.tag { cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
button.tag:hover:not(:disabled) { filter: brightness(.96); background: hsl(var(--tag-hue) 70% 88%); }
.tag b { font-weight: 700; opacity: .7; }
.tag.active { border-color: hsl(var(--tag-hue) 60% 40%); box-shadow: 0 0 0 2px hsl(var(--tag-hue) 60% 60% / .35); }
.tag.muted-tag { background: var(--hover); color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row .tags { margin-left: 6px; gap: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
label.f { display: block; font-size: 14px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { display: block; width: 100%; margin-top: 3px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.field-error { color: var(--bad); font-size: 14px; margin-top: 3px; min-height: 0; }
input.invalid, textarea.invalid, select.invalid { border-color: var(--bad); }
.hintbox { background: var(--hover); border-radius: 8px; padding: 8px 12px; font-size: 14px; color: var(--muted); margin: 6px 0; }
.hintbox code { color: var(--text); }
dialog.wide { width: min(760px, 96vw); max-height: 94vh; overflow: auto; }
.checklist { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
.checklist label { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; }
.checklist label:hover { background: var(--hover); }
.checklist .grow { flex: 1; min-width: 0; word-break: break-word; }
.badge.off { background: var(--hover); color: var(--muted); }
.badge.kind { background: var(--info-bg); color: var(--info); }
table.compact td, table.compact th { padding: 6px 8px; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; }
td .sub { color: var(--muted); font-size: 13px; word-break: break-all; }
.empty-state { text-align: center; color: var(--muted); padding: 24px 12px; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  nav { order: 3; width: 100%; }
}
button.danger-solid { background: var(--bad); color: #fff; border-color: var(--bad); font-weight: 600; }
button.danger-solid:hover:not(:disabled) { background: var(--bad); filter: brightness(1.1); }
dialog.confirm { width: min(500px, 94vw); }
.confirm-lead { margin: 0 0 8px; word-break: break-word; }
@media (max-width: 640px) {
  main { padding: 12px; }
  .hide-sm { display: none; }
  .row .meta-r { flex-wrap: wrap; }
}

/* редактор шаблона */
.sample-box { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; display: grid; gap: 8px; }
.sample-title { font-weight: 600; }
.sample-pick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.template-editor { display: grid; gap: 10px; }
.unit-result { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 6px; }
#unitCount { font-weight: 600; }
.unit-first { margin: 0; padding: 8px; background: var(--bg); border-radius: 6px; max-height: 14em; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.unit-result .ok { color: var(--ok, #067647); }
.unit-result .bad, #unitCount.bad { color: var(--bad); }

td.progress-cell { min-width: 180px; }
td .sub.err { color: var(--bad); }
progress:indeterminate { opacity: .6; }

.pager { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-top: 10px; }
.pager-pages { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pager button.page { min-width: 34px; padding: 4px 8px; }
.pager button.page.current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.pager .gap { padding: 0 4px; color: var(--muted); }


.badge.running { background: var(--info-bg); color: var(--info); }
.badge.running::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }

/* Переключатель вида на странице «URL» */
.tabs { display: inline-flex; gap: 0; }
.tabs .tab { border-radius: 0; }
.tabs .tab:first-child { border-radius: 6px 0 0 6px; }
.tabs .tab:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.tabs .tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.checklist label { display: flex; align-items: center; gap: 6px; }
.tag.more { background: var(--hover); color: var(--muted); border: 1px dashed var(--line); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.tag.more:hover:not(:disabled) { background: var(--hover); color: var(--text); filter: none; }

.finding-value { word-break: break-all; }
tr.false-positive td { opacity: .55; }
tr.false-positive .finding-value { text-decoration: line-through; }
label.inline-check { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.finding-value.secret { background: var(--hover); padding: 1px 4px; border-radius: 4px; }

/* Окно сканирования */
dialog.scan-dialog { width: min(560px, 94vw); max-height: 94vh; overflow-y: auto; }
.scan-dialog label.f { display: block; margin-top: 10px; }
.scan-dialog fieldset label { display: block; margin: 4px 0; }
.preview-line { margin: 14px 0 4px; min-height: 40px; }

/* Страница «Настройки» */
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.subtabs .tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.subtabs .tab[aria-selected="true"] .muted { color: inherit; }
.setting-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 8px 24px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting-row.dirty { background: var(--info-bg); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.setting-title { font-weight: 600; }
.setting-desc { color: var(--muted); font-size: 14px; margin-top: 4px; }
.setting-control input[type=text].wide { width: 100%; }
.setting-control input[type=number], .setting-control input[type=text] { max-width: 100%; }
.unit-input { display: inline-flex; gap: 6px; }
.unit-input input { width: 8em; }
.switch { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.save-bar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 10px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 -2px 10px rgba(0,0,0,.12); margin-top: 12px; }
@media (max-width: 800px) { .setting-row { grid-template-columns: 1fr; } }

/* фильтры списков: несколько значений галочками, интервал времени */
.multi { position: relative; display: inline-block; }
.multi > summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; background: var(--panel, transparent); white-space: nowrap; }
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after { content: ' ▾'; color: var(--muted, #888); }
.multi.active > summary { border-color: var(--accent); font-weight: 600; }
.multi-panel { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 220px; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.multi-panel .checklist { max-height: 260px; border: 0; }
.multi-foot { padding: 4px 8px 2px; }
.time-range { display: inline-flex; align-items: center; gap: 4px; }
.time-range input { width: auto; }
select.review { min-width: 9.5em; }
select.review-in_progress { border-color: #d98e04; }
select.review-done { border-color: #2e9e5b; }
.note-btn { white-space: nowrap; }
.note-line { max-width: 28em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#noteDialog { width: min(600px, 94vw); overflow-x: hidden; }
#noteDialog p { overflow-wrap: anywhere; }
dialog textarea#noteText { width: 100%; max-width: 100%; resize: vertical; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* пользователи и назначения */
.selection-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; margin: 8px 0; border: 1px solid var(--accent); border-radius: 8px; background: var(--hover); }
.selection-bar .spacer { flex: 1; }
.row-check, .head-check { width: 16px; height: 16px; cursor: pointer; }
td.check-cell, th.check-cell { width: 1.5em; padding-right: 0; }
tr.disabled-row { opacity: .6; }
#userBtn { white-space: nowrap; }
.assignee { white-space: nowrap; }
.keys-dialog { width: min(900px, 92vw); }
.keys-dialog input[readonly] { flex: 1; font-family: monospace; }

/* страница входа: пока пользователь не вошёл, видна только она */
body.locked > header, body.locked > main, body.locked > #toasts { display: none; }
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-screen[hidden] { display: none; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0 0 4px; text-align: center; }
.login-card button.primary { width: 100%; }
.curl-example { background: var(--hover); padding: 8px 10px; border-radius: 6px; overflow-x: auto; user-select: all; }

/* Подсказка при наведении: непрозрачная, поверх всего. */
#tip { position: fixed; inset: auto; margin: 0; max-width: min(520px, 92vw); padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); font-size: 13px; line-height: 1.4; box-shadow: 0 6px 20px rgba(0,0,0,.25); overflow-wrap: anywhere; white-space: pre-wrap; pointer-events: none; }

/* Строка «подсказка + кнопка ИИ» в диалогах правил. */
.ai-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.ai-row input { flex: 1; min-width: 200px; }

/* Выбор метки с фильтром по названию. */
.tag-pick { display: flex; flex-direction: column; gap: 4px; }
.tag-pick input[type=search] { min-width: 0; width: 100%; }
