:root {
  --bg: #f6f5f1; --surface: #ffffff; --text: #1c1b22; --muted: #5d5b69; --line: #e2dfd5;
  --accent: #4b3fd6; --accent-ink: #ffffff; --ok: #1f7a4d; --warn: #9a6200; --err: #b42318; --info: #2557b8;
  --ok-bg: #e4f5ec; --warn-bg: #fdf0d5; --err-bg: #fde7e4; --info-bg: #e6eefc; --idle-bg: #ecebe6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131a; --surface: #1d1c26; --text: #f1eff7; --muted: #aaa6bb; --line: #2d2b3a;
    --accent: #9a8fff; --accent-ink: #14131a; --ok: #5fd39b; --warn: #f0b94d; --err: #ff8a80; --info: #8fb4ff;
    --ok-bg: #173225; --warn-bg: #3a2c10; --err-bg: #3d1c19; --info-bg: #172542; --idle-bg: #2a2935;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); }
.boot { padding: 24px; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* оболочка */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 6px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; min-height: 40px; }
.brand img { width: 24px; height: 24px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.who span { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; white-space: nowrap; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; width: 100%; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { flex: none; padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; white-space: nowrap; }
nav.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 14px max(12px, env(safe-area-inset-right)) 40px max(12px, env(safe-area-inset-left)); }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 12px; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--err); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 8px; min-height: 36px; }
label.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.form { display: grid; gap: 10px; max-width: 560px; }
.form.wide { max-width: 760px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.filters input, .filters select { width: auto; min-width: 140px; flex: 1 1 140px; max-width: 320px; }

/* карточки, значки */
.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card .big { font-size: 26px; font-weight: 700; line-height: 1.1; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--idle-bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }
.banner { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); }
.kv { display: grid; grid-template-columns: minmax(110px, 170px) 1fr; gap: 4px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
pre.err { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--err-bg); color: var(--err); font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; }

/* таблицы; на телефоне строки превращаются в карточки */
table.t { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.t th, table.t td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
table.t th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--bg); }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.link { cursor: pointer; }
table.t tbody tr.link:hover { background: var(--bg); }
td .title { font-weight: 600; overflow-wrap: anywhere; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.empty { padding: 20px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
@media (max-width: 720px) {
  table.t, table.t tbody, table.t tr, table.t td { display: block; width: 100%; }
  table.t thead { display: none; }
  table.t { border: 0; background: transparent; }
  table.t tr { margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 0; }
  table.t td { display: grid; grid-template-columns: 96px 1fr; gap: 8px; border: 0; padding: 3px 12px; }
  table.t td::before { content: attr(data-l); color: var(--muted); font-size: 12px; padding-top: 2px; }
  table.t td[data-l=""]::before { content: none; }
  table.t td[data-l=""] { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 8px; font-size: 12px; }
}

/* вход */
.login { max-width: 360px; margin: 10vh auto 0; padding: 0 16px; }
.login .card { padding: 18px; }
.login h1 { text-align: center; }

/* уведомления */
#toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10; display: grid; gap: 6px; width: min(92vw, 420px); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.err { background: var(--err); color: #fff; }

/* то, что раньше было style="…": CSP запрещает инлайн-стили */
.errtext { color: var(--err); }
.formmsg { min-height: 1.3em; margin: 0; }
.linkcard { text-decoration: none; color: inherit; display: block; }
.linkcard:hover { border-color: var(--muted); }
.mb { margin-bottom: 12px; }
.statussel { min-width: 130px; }
@media (max-width: 520px) {
  .who span { display: none; } /* на телефоне почту не показываем: шапка остаётся в одну строку */
  .bar { padding-bottom: 0; }
}

/* ёмкость */
.cap-chart { width: 100%; height: auto; max-width: 760px; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.cap-chart .cap-grid { stroke: var(--line); stroke-width: 1; }
.cap-chart .cap-limit { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.cap-chart .cap-axis { fill: var(--muted); font-size: 10px; }
.cap-chart .cap-bar { fill: var(--ok); }
.cap-chart .cap-bar.warn { fill: var(--warn); }
.cap-chart .cap-bar.err { fill: var(--err); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* партнёры: ключ и секрет показываются один раз */
.secrets { display: grid; gap: 10px; }
.secrets .banner { margin-bottom: 0; }
.secrets .row { flex-wrap: nowrap; }
.secrets .row input.mono { flex: 1 1 auto; min-width: 0; width: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
