:root {
  --bg: #E8ECF0;
  --surface: #FFFFFF;
  --sunken: #F2F4F7;
  --ink: #17212B;
  --muted: #5A6774;
  --line: #CFD6DD;
  --accent: #2446C7;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1E7FB;
  --ok: #1E8757;
  --ok-soft: #DAF0E4;
  --warn: #9A6210;
  --warn-soft: #F7EAD1;
  --bad: #BF3627;
  --bad-soft: #F8DDD9;
  --log-bg: #1B2430;
  --log-ink: #D5DEE8;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171E;
    --surface: #18212A;
    --sunken: #141C24;
    --ink: #E4EAF0;
    --muted: #8D9CAB;
    --line: #2A3540;
    --accent: #819AFF;
    --accent-ink: #0D1322;
    --accent-soft: #1E2849;
    --ok: #3DC48B;
    --ok-soft: #16322A;
    --warn: #E3AA45;
    --warn-soft: #382B14;
    --bad: #F2705F;
    --bad-soft: #3C1D19;
    --log-bg: #0C1117;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
code { font: 500 12.5px/1.4 var(--mono); }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- кнопки и поля */

.btn {
  font: 500 14px/1 var(--font);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input {
  font: 400 15px/1.3 var(--font);
  color: var(--ink);
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--bad); font-size: 14px; min-height: 1.5em; margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- бренд */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  display: inline-grid; place-items: center;
}
.brand-mark::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-ink); }

/* ---------- вход */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 26px 24px;
}
.login-card .brand { margin-bottom: 24px; }

/* ---------- шапка */

.top {
  display: flex; align-items: center; gap: 24px;
  padding: 14px max(20px, calc((100vw - 980px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.host { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0 auto 0 0; font-size: 13px; }
.host div { display: flex; gap: 6px; }
.host dt { color: var(--muted); }
.host dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }

main { max-width: 980px; margin: 0 auto; padding: 8px 20px 40px; }
section { margin-top: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 20px; }
.section-tools { display: flex; align-items: center; gap: 12px; }
.empty { color: var(--muted); margin: 0; padding: 18px; background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; }

.notice {
  margin-top: 20px; padding: 12px 16px; border-radius: 10px;
  background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 14px;
}

/* ---------- сервисы: общий блок, строки разделены линиями */

.services { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.service {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 4px 16px;
  padding: 18px 20px;
  align-items: start;
}
.service + .service { border-top: 1px solid var(--line); }
.lamp { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; background: var(--muted); }
.lamp.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.lamp.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.lamp.bad { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
.service-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.service-title h3 { font-size: 16px; }
.service-title .image { color: var(--muted); }
.state { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.meta { margin: 6px 0 0; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 16px; }

.update {
  display: inline-block; margin-top: 10px; padding: 4px 10px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
}
.tone-ok { background: var(--ok-soft); color: var(--ok); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-muted { background: var(--sunken); color: var(--muted); }

.digests { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--muted); }
.digests code { color: var(--ink); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.watched { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 12px; padding: 0 4px; font-size: 13px; color: var(--muted); }
.watched-item { display: inline-flex; align-items: center; gap: 8px; }
.watched-item .lamp { margin: 0; width: 8px; height: 8px; box-shadow: none; }
.watched-item b { color: var(--ink); font-weight: 500; }

/* ---------- сертификаты: полоса срока жизни как главный визуальный элемент */

.certs { display: grid; gap: 12px; }
.cert {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px;
}
.cert h3 { font-size: 16px; word-break: break-all; }
.cert-days { font-size: 14px; color: var(--muted); margin: 2px 0 0; }
.cert-days strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.cert .actions { grid-row: 1 / span 2; grid-column: 2; align-self: start; }

.life {
  grid-column: 1 / -1;
  position: relative; height: 10px; margin: 12px 0 4px;
  background: var(--sunken); border: 1px solid var(--line); border-radius: 5px;
}
.life-fill { position: absolute; inset: -1px auto -1px -1px; border-radius: 5px; background: var(--ok); }
.life.tone-warn .life-fill { background: var(--warn); }
.life.tone-bad .life-fill { background: var(--bad); }
.life-renew {
  position: absolute; top: -5px; bottom: -5px; width: 2px; margin-left: -1px;
  background: var(--ink); border-radius: 1px;
}
.life-scale { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.cert-note { grid-column: 1 / -1; margin: 8px 0 0; font-size: 14px; }
.cert-note.bad { padding: 10px 12px; border-radius: 8px; background: var(--bad-soft); }
.cert-files { grid-column: 1 / -1; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); }

/* ---------- операции */

.jobs { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.jobs .empty { border: 0; background: none; }
.job { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 14px; align-items: center; padding: 12px 20px; font-size: 14px; }
.job + .job { border-top: 1px solid var(--line); }
.job .lamp { width: 8px; height: 8px; margin: 0; box-shadow: none; }
.job-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- консоль операции */

.console {
  position: fixed; right: 16px; bottom: 16px; z-index: 20;
  width: min(760px, calc(100vw - 32px));
  height: min(420px, 60vh);
  display: grid; grid-template-rows: auto 1fr;
  background: var(--log-bg); color: var(--log-ink);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 18px 50px -12px rgba(10, 20, 35, .45);
}
.console-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.console-head h2 { font-size: 14px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.console-head .btn { color: var(--log-ink); border-color: rgba(255,255,255,.18); }
.console-status { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 5px; background: rgba(255,255,255,.08); }
.console-status.running { color: #9DB3FF; }
.console-status.ok { color: #52D69C; }
.console-status.error { color: #FF8A7A; }
.console-log {
  margin: 0; padding: 12px 16px 16px; overflow: auto;
  font: 400 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
}

/* ---------- диалоги и уведомления */

.dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 14px; padding: 24px;
  background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: rgba(12, 20, 30, .45); }
.dialog h2 { font-size: 18px; margin-bottom: 10px; }
.dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed; left: 16px; bottom: 16px; z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  background: var(--ink); color: var(--bg);
}
.toast.bad { background: var(--bad); color: #fff; }

.foot { max-width: 980px; margin: 0 auto; padding: 0 20px 32px; display: flex; gap: 20px; font-size: 13px; }

/* ---------- мобильные */

@media (max-width: 680px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .host { order: 3; width: 100%; }
  main { padding: 0 14px 32px; }
  .service { grid-template-columns: 14px 1fr; padding: 16px; }
  .service .actions { grid-column: 2; justify-content: flex-start; margin-top: 10px; }
  .cert { grid-template-columns: 1fr; padding: 16px; }
  .cert .actions { grid-row: auto; grid-column: 1; justify-content: flex-start; }
  .job { grid-template-columns: 10px 1fr auto; padding: 12px 16px; }
  .job-time { display: none; }
  .console { right: 8px; bottom: 8px; width: calc(100vw - 16px); height: 65vh; }
}

@media (prefers-reduced-motion: no-preference) {
  .console:not([hidden]) { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(12px); opacity: 0; } }
}
