/* Base: the contour style (DESIGN.md), shared with the Users admin. */
: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; }
main { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 48px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.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; }
.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 { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.icon-btn:hover:not(:disabled) { background: #f1f5f9; color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.link { padding: 0; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; }
.link:hover { color: var(--accent-hover); }
.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, .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
input:not([type=checkbox], [type=radio]), select, textarea { width: 100%; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; font-weight: 400; }
input:not([type=checkbox], [type=radio], [type=file]), select { height: 38px; }
input[type=file] { padding: 7px 12px; }
textarea { min-height: 76px; padding: 9px 12px; resize: vertical; }
::placeholder { color: var(--faint); }
input[readonly], textarea[readonly] { background: #f8fafc; color: var(--muted); }
input:disabled, select:disabled { background: #f8fafc; color: var(--faint); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.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; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 24px; }
:is(button, input, select, textarea, a):focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.with-action { display: flex; gap: 8px; }
.with-action :is(input, select) { flex: 1; min-width: 0; }

/* Contour bar (DESIGN.md Л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; text-decoration: none; }
.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; }
.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 { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel { display: grid; gap: 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .search { width: min(320px, 100%); }
.toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar-group select { width: auto; }
.filter-picker { width: 240px; }
.ms-empty { padding: 8px 10px; }
.toolbar > .toolbar-group:first-child { flex: 1 1 auto; }
.section-head { display: grid; gap: 4px; }
.section-head h2, .form h2, .proxies > h2 { font-size: 16px; }
.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; }
.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); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .wide { grid-column: 1 / -1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.message { padding: 9px 12px; border-radius: 8px; color: var(--ok); background: var(--ok-soft); font-size: 13px; white-space: pre-line; }
.message:empty { display: none; }
.message.error { color: var(--danger); background: var(--danger-soft); }

/* Login (the users service signs in; this card only waits or explains) */
.login { width: min(400px, calc(100vw - 32px)); margin: 12vh auto; padding: 28px; display: grid; gap: 14px; }
.login h1 { font-size: 22px; }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.data-table { min-width: 720px; }
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; }
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; }
td.menu-cell { width: 1%; text-align: right; padding-right: 10px; }
.person { font-weight: 600; overflow-wrap: anywhere; }
.person + .muted, .person + .sub { font-size: 13px; margin-top: 2px; }
.sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); }
tr.inactive :is(.person, .sub, .chip) { opacity: .55; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.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); }
.note { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.error-text { color: var(--danger); }
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* Chips, multiselect and row menu: popovers render in the top layer, so the table's scroll box never clips them */
.chip { padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.off { background: var(--danger-soft); color: var(--danger); }
.ms-trigger { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; min-width: 220px; min-height: 38px; 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; }
.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-placeholder { padding: 0 4px; color: var(--faint); }
[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; }
.ms-panel { width: max-content; min-width: 280px; max-width: min(420px, calc(100vw - 16px)); }
.ms-search { margin-bottom: 6px; }
.ms-quick { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 4px 10px 8px; }
.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; }
.ms-option .badge { margin-left: auto; }
.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; }
.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:not(:disabled) { background: #f1f5f9; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover:not(:disabled) { background: var(--danger-soft); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--line); }

/* Dialogs and toast */
dialog { width: min(460px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 24px; border: 1px solid var(--line);
  border-radius: 14px; color: var(--text); box-shadow: 0 24px 70px #0f172240; }
dialog.wide { width: min(620px, 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; }
.secret-value { min-height: 96px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
#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; white-space: pre-line; box-shadow: 0 10px 30px #0f172240; z-index: 10; }
#toast.error { background: var(--danger); }
#toast:empty { display: none; }

@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; }
  .toolbar-group :is(input, select, .filter-picker) { flex: 1 1 100%; width: 100%; }
}
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
}

/* Universal: metrics and compact history. */
.sources-table { min-width: 960px; }
.sources-table td:first-child { width: 28%; min-width: 220px; }
.source-url { display: inline-block; margin-top: 2px; color: var(--muted); font-size: 13px; text-decoration: none; }
.source-url:hover { color: var(--accent); text-decoration: underline; }
.sources-table td { vertical-align: top; }
.sources-table .values { min-width: 240px; }
.history-table { min-width: 960px; }
.history-table td { vertical-align: top; }
.history-table .values { min-width: 260px; }
.values { font-size: 13px; color: var(--text-2); }
/* Name | value rows share one column grid, so values line up across a cell. */
.metric-list { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 4px 16px; align-items: center; }
.metric { display: contents; }
.metric-name { color: var(--muted); }
.metric-value { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
/* Hint marks and the floating hint box (admin.js: hintMark, showTip). */
.tip { position: fixed; z-index: 20; max-width: min(320px, calc(100vw - 16px)); padding: 8px 10px; border-radius: 8px;
  background: var(--text); color: #fff; font-size: 12px; font-weight: 400; line-height: 1.45; white-space: pre-line; pointer-events: none; box-shadow: var(--shadow); }
.tip-icon { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px; padding: 0;
  border: 1px solid var(--line-strong); border-radius: 50%; background: none; color: var(--muted); font-family: inherit; font-size: 11px; font-weight: 600; line-height: 1;
  text-transform: none; letter-spacing: 0; vertical-align: middle; cursor: help; flex-shrink: 0; }
.tip-icon:hover, .tip-icon[aria-describedby] { color: var(--accent); border-color: var(--accent); }
.tip-icon.delta { border-color: transparent; font-size: 13px; }
.tip-icon.warn { color: var(--danger); border-color: currentColor; }
@media (pointer: coarse) { .tip-icon { width: 24px; height: 24px; } }
.status-line { display: flex; align-items: center; gap: 2px; }
.source-name { padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.source-name:hover { color: var(--accent); text-decoration: underline; }
.values.stale .metric-list { opacity: .6; }
.metric-reject { width: 22px; height: 22px; font-size: 14px; flex-shrink: 0; opacity: 0; }
.metric-value:hover .metric-reject, .metric-reject:focus-visible { opacity: 1; }
@media (pointer: coarse) { .metric-reject { opacity: 1; } }
.summary-line { margin: -4px 0 0; }
.summary-line.has-errors { color: var(--danger); font-weight: 600; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 20px; }
.field-head > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-head .icon-btn { width: 28px; height: 28px; margin: -6px -6px -6px 0; }
.field-head .icon-btn:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.tags-table { min-width: 0; }
.tags-table td:nth-child(2) { width: 30%; }
.run-details { min-width: 160px; max-width: 300px; overflow-wrap: anywhere; color: var(--danger); font-size: 13px; white-space: pre-line; }
.run-time { margin-top: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
tr.inactive > td { opacity: .55; }
.load-more { display: flex; justify-content: center; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.hint.error { color: var(--danger); }
#source-form { gap: 16px; }
#source-form .form-section { border-top: 1px solid var(--line); padding-top: 16px; }
#source-filter { max-width: 100%; }
.fields-editor { display: grid; gap: 16px; min-width: 0; }
.field-row { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.field-row > .btn { justify-self: start; }
textarea { width: 100%; min-height: 80px; resize: vertical; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
select { height: 38px; max-width: 100%; }
:is(select, textarea):focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.panel, .table-wrap, .form { min-width: 0; }
#check-save { justify-self: start; }
#check-results table { min-width: 640px; }
#check-status { overflow-wrap: anywhere; }
@media (max-width: 720px) {
  .field-row { padding: 12px; }
  .toolbar > select { width: 100%; }
  .form { padding: 16px; }
}

/* Codex sign-in */
.codex-login { display: grid; gap: 8px; padding: 12px 16px; border-radius: 8px; background: var(--accent-soft); color: var(--text-2); }
.codex-login a { overflow-wrap: anywhere; }
.codex-limits { display: grid; gap: 8px; }
.limit-line { display: grid; grid-template-columns: minmax(150px, max-content) minmax(80px, 200px) auto; align-items: center; gap: 12px; }
.limit-line meter { width: 100%; }
@media (max-width: 600px) { .limit-line { grid-template-columns: 1fr; gap: 4px; } }
#codex-code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 18px; letter-spacing: .05em; color: var(--text); }

/* Phones: each source becomes a card, so values are visible without scrolling the table sideways. */
@media (max-width: 720px) {
  .sources-table { min-width: 0; }
  .sources-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .sources-table tr { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .sources-table tbody tr:last-child { border-bottom: 0; }
  .sources-table td { display: block; padding: 0; border: 0; width: auto !important; min-width: 0 !important; }
  .sources-table td:first-child { grid-column: 1; }
  .sources-table td.menu-cell { grid-column: 2; grid-row: 1; }
  .sources-table td:not(:first-child, .menu-cell) { grid-column: 1 / -1; }
  .sources-table td.empty { grid-column: 1 / -1; padding: 16px 0; }
}
.field-row textarea { min-height: 56px; }
#accounts-table { min-width: 640px; }
#proxies-table { min-width: 560px; }
