/* Base: copied verbatim from the contour DESIGN.md, section 16. Keep in sync with it, not edited locally. */
:root {
  --bg: #f5f7fb; --card: #fff; --line: #e2e8f0; --line-strong: #cbd5e1;
  --text: #0f172a; --text-2: #334155; --muted: #64748b; --faint: #94a3b8;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-soft: #eff4ff; --accent-text: #1e40af;
  --ok: #15803d; --ok-soft: #ecfdf3; --danger: #b42318; --danger-soft: #fef2f2;
  --warn: #b45309; --warn-soft: #fffbeb;
  --shadow: 0 1px 2px #0f17220a, 0 4px 16px #0f17220d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
/* Room for the scrollbar on every page, so a short page and a long one line up to the pixel */
html { scrollbar-gutter: stable; }
body { margin: 0; min-width: 320px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
main { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* Controls */
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 8px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.secondary { background: var(--card); color: var(--text-2); border-color: var(--line-strong); }
.btn.secondary:hover:not(:disabled) { background: #f8fafc; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #912018; }
.icon-btn { width: 32px; height: 32px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.icon-btn:hover { background: #f1f5f9; color: var(--text); }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field > .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
input:not([type=checkbox], [type=radio]) { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; }
input::placeholder { color: var(--faint); }
input[readonly] { background: #f8fafc; color: var(--muted); }
input:is([type=checkbox], [type=radio]) { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
input[type=file] { padding: 6px 12px; height: auto; }
textarea { width: 100%; min-height: 96px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; resize: vertical; }
select { height: 38px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; min-width: 0; }
td select, [popover] select { height: 32px; }
.check { display: inline-flex; gap: 10px; align-items: flex-start; color: var(--text-2); cursor: pointer; }
.check input { margin-top: 2px; flex-shrink: 0; }
.check small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
:is(button, input, select, textarea, a):focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.with-action { display: flex; gap: 8px; }
.with-action > :first-child { flex: 1; min-width: 0; }

/* Contour bar (Л2) */
.contour { background: var(--card); border-bottom: 1px solid var(--line); }
.contour-inner { width: min(1160px, calc(100% - 32px)); margin: 0 auto; height: 52px; display: flex; align-items: center; gap: 24px; }
.contour-brand { font-weight: 700; color: var(--text); text-decoration: none; }
.contour-links { display: flex; gap: 20px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.contour-links a { color: var(--muted); font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; padding: 16px 0 14px; border-bottom: 2px solid transparent; }
.contour-links a:hover { color: var(--text); }
.contour-links a[aria-current=page] { color: var(--accent); border-bottom-color: var(--accent); }
.contour-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.contour-user .btn { height: 32px; padding: 0 12px; }
.contour-user span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.contour-user span a { color: inherit; text-decoration: none; }  /* email → profile in Users, set by contour.js */
.contour-user span a:hover { color: var(--text); text-decoration: underline; }
.contour-more { height: 32px; padding: 0 12px; flex-shrink: 0; }  /* «Ещё ▾» / «Сервисы ▾»: contour.js adds and shows it */
.contour-menu a { text-decoration: none; }
.contour-menu a[aria-current=page] { color: var(--accent); font-weight: 600; }

/* Layout */
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 28px 0 20px; }
.top h1 { font-size: 22px; }
.lead { color: var(--muted); font-size: 13px; margin-top: 4px; }
#account-email { overflow-wrap: anywhere; font-size: 13px; }
.tabs { display: flex; flex-wrap: wrap; gap: 0 24px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 0 12px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel { display: grid; gap: 16px; }
.panel h2 { font-size: 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; }
.toolbar .search { width: min(260px, 100%); }
.form { display: grid; gap: 18px; padding: 24px; max-width: 760px; }
.form-section { display: grid; gap: 16px; }
.form-section + .form-section { padding-top: 22px; border-top: 1px solid var(--line); }
.form-section h2 { font-size: 16px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.message { padding: 9px 12px; border-radius: 8px; color: var(--ok); background: var(--ok-soft); font-size: 13px; }
.message:empty { display: none; }
.message.error { color: var(--danger); background: var(--danger-soft); }

/* Login */
#login { width: min(400px, calc(100vw - 32px)); margin: 12vh auto; padding: 28px; }
#login h1 { font-size: 22px; margin-bottom: 20px; }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
th.num, td.num { text-align: right; white-space: nowrap; }
th.narrow, td.narrow { width: 1%; white-space: nowrap; }
td.when { color: var(--muted); font-size: 13px; white-space: nowrap; }
td.menu-cell { width: 1%; text-align: right; padding-right: 10px; }
.details { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.action-danger { color: var(--danger); font-weight: 600; }
.person { font-weight: 600; overflow-wrap: anywhere; }
.person + .muted { font-size: 13px; margin-top: 2px; }
tr.inactive td, tr.reverted td { opacity: .55; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.load-more { justify-self: center; }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.list-foot > span { color: var(--muted); font-size: 13px; }
.journal td:not(.details) { white-space: nowrap; }
.journal td { vertical-align: top; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ok); background: var(--ok-soft); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.off { color: var(--danger); background: var(--danger-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.none { color: var(--muted); background: #f1f5f9; }
.badge.busy { color: var(--accent-text); background: var(--accent-soft); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600; }

/* Popovers: menu «⋯» and multiselect render in the top layer, so a table's scroll box never clips them */
[popover] { position: fixed; inset: auto; margin: 0; padding: 6px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); box-shadow: 0 10px 30px #0f172226; }
.menu-panel { min-width: 200px; }
.menu-item { display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: 6px; background: none; color: var(--text); text-align: left; }
.menu-item:hover { background: #f1f5f9; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--line); }
/* Multiselect (.ms-*) and per-item select (.role-option): copy every .ms-* and .role-option rule from
   00.users/app/static/index.html, but NOT its global `select { height: 32px }` — it would undo the 38px above */

/* Dialogs and toast */
dialog { width: min(460px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; padding: 24px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); box-shadow: 0 24px 70px #0f172240; }
dialog.wide { width: min(720px, calc(100% - 32px)); }
dialog.wider { width: min(820px, calc(100% - 32px)); }
dialog::backdrop { background: #0f172259; }
dialog form, .dialog-body { display: grid; gap: 14px; }
dialog h2 { font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px;
  border-radius: 10px; background: #0f172a; color: #fff; font-size: 13px; box-shadow: 0 10px 30px #0f172240; z-index: 10; }
#toast.error { background: var(--danger); }
#toast:empty { display: none; }

@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
}
@media (max-width: 720px) {
  main, .contour-inner { width: calc(100% - 24px); }
  .contour-links, .contour-user span { display: none; }  /* links move into the «Сервисы ▾» popover */
  .top { padding-top: 18px; }
  .cols { grid-template-columns: 1fr; }
  .form { padding: 18px; }
  .tabs { gap: 0 18px; }
  /* First-run setup card (section 10): cells stack */
  #setup td { display: block; border-bottom: 0; padding-bottom: 0; }
  #setup td:last-child { width: auto; text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  #setup tr:last-child td:last-child { border-bottom: 0; }
}

/* Multiselect (.ms-*), copied from the Users admin without its global select height */
.ms-trigger { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; min-width: 220px; min-height: 36px; padding: 4px 32px 4px 8px;
  position: relative; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); text-align: left; }
td .ms-trigger { max-width: 420px; }
.ms-trigger:hover:not(:disabled) { border-color: var(--faint); }
.ms-trigger::after { content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; margin-top: -6px;
  border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.ms-trigger:disabled { opacity: 1; cursor: default; background: #f8fafc; }
.ms-trigger:disabled::after { display: none; }
.ms-placeholder { padding: 0 4px; color: var(--faint); }
.ms-panel { width: max-content; max-width: min(320px, calc(100vw - 16px)); }
.ms-search { margin-bottom: 6px; }
.ms-list { display: grid; max-height: 260px; overflow-y: auto; }
.ms-option { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.ms-option:hover { background: #f1f5f9; }
/* Single choice (platform filter): the option is a button, the count sits on the right. */
.ms-option.pick { justify-content: space-between; width: 100%; border: 0; background: none; color: inherit; font: inherit; text-align: left; }
.ms-option.pick:hover { background: #f1f5f9; }
.field > .ms-trigger, .filters > .ms-trigger { min-width: 0; min-height: 38px; }
.ms-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 4px 2px; margin-top: 6px; border-top: 1px solid var(--line); }
.ms-foot .btn { height: 32px; padding: 0 12px; }

/* Admin-only controls; the API enforces the same rule, this only stops offering actions that would fail. */
body:not([data-role="admin"]) [data-admin] { display: none !important; }

/* Parse: only what the base lacks — page sections, detail pages, JSON blocks, the dashboard */
a { color: var(--accent-text); }
a.person { color: var(--text); text-decoration: none; }
a.btn { text-decoration: none; }
#message-effective-metrics { display: grid; gap: 12px; }
a.person:hover { color: var(--accent); text-decoration: underline; }
.field select, .filters select { width: 100%; }
/* The collector configuration is JSON. */
#collector-form textarea { font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; }
select[multiple] { height: auto; }
summary:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.toolbar h2, .section h2, .proxies > h2 { font-size: 16px; }
.toolbar .actions { flex-wrap: wrap; }
.view, .section { display: grid; gap: 12px; min-width: 0; }
/* DESIGN.md: 32px between page sections (panel gap 16 + 16). */
.view > .section + *, .view > * + .section, .panel > .section + .section { margin-top: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters > :not(.btn) { flex: 1 1 160px; min-width: 0; }
td.when { white-space: nowrap; }
details > summary { color: var(--text-2); font-weight: 600; cursor: pointer; }
.state:empty { display: none; }
.state.error { color: var(--danger); }
.clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--text-2); font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }
button.chip { border: 0; margin: 0 4px 4px 0; }
button.chip:hover { color: var(--accent); }
.metrics { display: flex; flex-wrap: wrap; gap: 4px 12px; max-width: 240px; font-size: 13px; color: var(--text-2); }
.metrics > span { white-space: nowrap; }
#messages-table a.person { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mono { overflow-wrap: anywhere; }
pre { max-height: 420px; margin: 0; overflow: auto; padding: 12px 16px; border-radius: 8px; background: #0f172a; color: #dbeafe;
  font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
#messages-table, #runs-table { min-width: 900px; }
#providers-table, #topics-table, #collectors-table, #keys-table, #services-table, #rejections-table, #stats-metrics-table, #dashboard-runs-table { min-width: 720px; }
#journal-table { min-width: 900px; }
/* Journal filters keep DESIGN.md widths: search up to 260px, the rest by content. */
#journal-filter-form .filters > * { flex: 0 1 200px; }
#journal-filter-form .filters > .search { flex-basis: 260px; }
#journal-filter-form .filters > input[type=date] { flex-basis: 160px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { display: grid; gap: 4px; padding: 16px 24px; }
.stat strong { font-size: 22px; }
.detail { display: grid; gap: 24px; padding: 24px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-head h2 { font-size: 18px; overflow-wrap: anywhere; }
.detail-head .actions { flex-wrap: wrap; }
/* Grid items default to min-width: auto, so a wide table would stretch the card past the phone width. */
.detail > *, .detail-section > * { min-width: 0; }
.detail-section { display: grid; gap: 12px; padding-top: 22px; border-top: 1px solid var(--line); }
.detail-section > h3 { font-size: 16px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
.detail-item { display: grid; gap: 4px; min-width: 0; margin: 0; }
.detail-item > span, .detail-item dt { font-size: 12px; font-weight: 600; color: var(--muted); }
.detail-item strong, .detail-item dd { margin: 0; font-weight: 400; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail-item-full { grid-column: 1 / -1; }
.detail .card { box-shadow: none; }
.credential-group { display: grid; gap: 12px; }
.credential-group + .credential-group { padding-top: 16px; border-top: 1px solid var(--line); }
.access { width: min(400px, calc(100vw - 32px)); margin: 12vh auto; padding: 28px; display: grid; gap: 16px; }
.access h1 { font-size: 22px; }

@media (max-width: 720px) {
  .stats, .detail-grid { grid-template-columns: 1fr; }
  .detail { padding: 18px; }
}
/* Credential files (service account keys): the picker button matches .btn.secondary. */
input[type=file] { height: auto; padding: 6px; color: var(--muted); }
input[type=file]::file-selector-button { height: 30px; margin-right: 10px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: 6px; background: var(--card); color: var(--text-2); font: inherit; font-weight: 600; cursor: pointer; }
input[type=file]::file-selector-button:hover { background: #f8fafc; }
/* Topic rows open the topic page; the name turns into a link on hover so the row reads as clickable. */
tr[data-href] { cursor: pointer; }
tr[data-href]:hover a.person { color: var(--accent); text-decoration: underline; }
.field-action { display: flex; gap: 8px; }
.field-action > input { flex: 1; min-width: 0; }
/* Optional collector fields: «×» sits on the label line, so the input keeps the full width. */
/* Collector form: every group is a DESIGN.md form section; optional ones fold. */
#collector-plugin-fields { display: grid; gap: 18px; }
#collector-form .form-section { padding-top: 22px; border-top: 1px solid var(--line); }
details.form-section:not([open]) { gap: 0; }
#collector-form details > summary { display: flex; align-items: baseline; gap: 12px; list-style: none; min-width: 0; }
#collector-form details > summary::-webkit-details-marker { display: none; }
#collector-form details > summary::before { content: "▸"; color: var(--muted); width: 12px; flex: none; }
#collector-form details[open] > summary::before { content: "▾"; }
details.form-section > summary h2 { color: var(--text); }
.section-note { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
details.form-section[open] > summary .section-note { display: none; }
/* A deliberate state worth noticing (paused topic), not an error. */
.message.note { color: var(--text-2); background: #f1f5f9; }
#topic-warning { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
#topic-warning[hidden] { display: none; }
/* Dashboard: stat cards open their screen. */
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--line-strong); }
#system-details { display: grid; gap: 12px; }
/* The grid gap stops at the details content slot, so cards inside it need their own spacing. */
#system-details > .card + .card { margin-top: 12px; }
/* Daily bar chart in the overview statistics: bar heights are set from data, everything else is static. */
.chart { display: grid; gap: 8px; padding: 16px 24px; }
.chart .bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; border-bottom: 1px solid var(--line); }
.chart .bar { flex: 1; min-width: 2px; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { display: flex; justify-content: space-between; gap: 8px; }
/* Publications: the visibility column appears only when hidden ones are listed; the card leads with the text. */
#messages-table:not(.show-visibility) th:nth-child(5), #messages-table:not(.show-visibility) td:nth-child(5) { display: none; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.message-text:empty { display: none; }

/* Name edited in place (topic title, topic row): field + Сохранить + Отмена in one line, error under it. */
.title-line { display: flex; align-items: center; gap: 8px; flex: 1 1 320px; min-width: 0; }
.title-line .inline-edit { flex: 1; min-width: 0; }
.inline-edit input[aria-invalid="true"] { border-color: var(--danger); }
.inline-edit { display: grid; gap: 4px; min-width: min(420px, 100%); }
.inline-edit-row { display: flex; gap: 8px; align-items: center; }
.inline-edit-row input:not([type=checkbox], [type=radio]) { flex: 1; min-width: 0; height: 32px; }
.inline-edit-row .btn { height: 32px; padding: 0 12px; }
.inline-edit .hint { font-size: 12px; }
.inline-edit .hint:empty { display: none; }
/* A phone keeps the name field full width; the buttons move to the next line. */
@media (max-width: 720px) {
  .title-line { flex-wrap: wrap; }
  .inline-edit-row { flex-wrap: wrap; }
  .inline-edit-row input:not([type=checkbox], [type=radio]) { flex-basis: 100%; }
  .inline-edit + #topic-subtitle { margin-top: 8px; }
}

/* Status of a list read from the provider under a collector field: loading, error with «Обновить», count with «Обновить». */
.options-status.action-danger { color: var(--danger); }
.cols > .field-wide { grid-column: 1 / -1; }
p.options-status { margin: 0; font-size: 12px; color: var(--muted); }
.options-status:empty { display: none; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
