/* Base: copied from DESIGN.md, section 16 (the contour style shared by every service). */
: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; }
#who { 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, .proxies > 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; display: grid; gap: 14px; }
.login h1 { font-size: 22px; }

/* 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; }
.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: the «⋯» menu renders in the top layer, so a table's scroll box never clips it */
[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); }

/* 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::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: min(560px, calc(100% - 32px)); overflow-wrap: anywhere; 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; }
}

/* This service only */
.nowrap { white-space: nowrap; }
input:disabled, select:disabled { background: #f8fafc; color: var(--faint); }
textarea[readonly] { background: #f8fafc; color: var(--muted); }
.cols > .wide { grid-column: 1 / -1; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.message, #toast { white-space: pre-line; }  /* check results come in several lines */
.connections { display: grid; gap: 32px; }
#accounts-table { min-width: 760px; }
#api-keys-table, #jobs-table { min-width: 640px; }
#journal-table { min-width: 860px; }
.journal td:not(.details) { white-space: nowrap; }
.journal td { vertical-align: top; }
.period { display: inline-flex; align-items: center; gap: 6px; }
.toolbar .filters input[type=date] { width: auto; }
.sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; color: var(--muted); font-size: 13px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.off { background: var(--danger-soft); color: var(--danger); }
.note { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.error-text { color: var(--danger); }
.guide { padding: 12px; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; color: var(--text-2); background: var(--accent-soft); font-size: 13px; line-height: 1.45; }
.guide:empty { display: none; }
.guide a { color: var(--accent); }
.guide .btn { margin-top: 8px; display: flex; width: fit-content; }
.form-fields { display: grid; gap: 14px; }
.form-fields .tabs { margin-bottom: 0; }
.secret-value { min-height: 96px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
pre.result { max-width: 760px; max-height: 460px; margin: 0; overflow: auto; padding: 16px 24px; border: 1px solid var(--line); border-radius: 14px;
  color: var(--text-2); background: var(--card); box-shadow: var(--shadow);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.progress { width: 160px; height: 6px; margin-top: 6px; overflow: hidden; border-radius: 999px; background: var(--line); }
.progress span { display: block; height: 100%; background: var(--accent); }
.refresh-status { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 12px 16px; border-radius: 8px; color: var(--text-2); background: #f8fafc; }
.refresh-status > .btn { margin-left: auto; }
.refresh-status .hint { flex-basis: 100%; order: 1; font-size: 12px; color: var(--muted); }
.refresh-status .hint.error { color: var(--danger); }
.refresh-status .hint > .btn { margin: 0 8px 0 0; }
.session-check { width: auto; margin: 8px 0; }
.session-check :is(th, td) { padding: 4px 16px 4px 0; border: 0; text-transform: none; letter-spacing: 0; }
.session-check tbody tr:hover { background: none; }
.session-check td.bad { color: var(--danger); }
.preview { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.preview table { font-size: 12px; }
.preview :is(th, td) { max-width: 220px; padding: 6px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: none; letter-spacing: 0; }
.preview .header-row td { background: var(--accent-soft); font-weight: 600; }
.qr { width: min(280px, 100%); border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 720px) {
  .toolbar .filters :is(input, select) { flex: 1 1 100%; width: 100%; }
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.none { background: #f1f5f9; color: var(--muted); }
.tab-count { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; text-align: center; }
.health { display: grid; gap: 10px; margin-bottom: 12px; padding: 12px 16px; border-radius: 8px; background: #f8fafc; }
.health.bad { background: var(--danger-soft); }
.health-headline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; font-size: 14px; }
.health-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.health-pill { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ok); font-size: 13px; text-align: left; cursor: pointer; }
.health-pill:hover { border-color: currentColor; }
.health-pill.warn { color: var(--warn); }
.health-pill.off { color: var(--danger); }
.health-name { color: var(--text); font-weight: 600; }
.health-issues { font-size: 12px; }
