:root {
  --bg: #0e1016;
  --surface: #171a23;
  --surface-2: #1f2330;
  --line: #2a2f3d;
  --text: #e7e9ef;
  --muted: #929aad;
  --accent: #6ea8fe;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eef0f5;
    --line: #dcdfe8;
    --text: #1a1d26;
    --muted: #666e80;
    --accent: #2563eb;
    --ok: #16a34a;
    --warn: #b45309;
    --bad: #dc2626;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой display из этого файла. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 760px;
  margin-inline: auto;
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.center { text-align: center; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }

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

.login { min-height: 82vh; display: grid; place-items: center; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: min(100%, 340px);
  display: grid;
  gap: 10px;
}
.login-card h1 { text-align: center; }
.login-card .muted { text-align: center; margin-bottom: 8px; }

input[type=password] {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input[type=password]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.error { color: var(--bad); font-size: 14px; text-align: center; margin: 2px 0 0; }

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

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top-right { display: flex; align-items: center; gap: 10px; }

.pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  transition: background .3s, opacity .3s;
}
.pulse.stale { background: var(--bad); }
.pulse.beat { opacity: .35; }

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 17px; white-space: nowrap; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .bar { height: 3px; border-radius: 2px; background: var(--surface-2); margin-top: 7px; overflow: hidden; }
.stat .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s; }
.stat .bar > i.warn { background: var(--warn); }
.stat .bar > i.bad { background: var(--bad); }

/* --- карточки сервисов --- */

.services { display: grid; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card.busy { opacity: .65; }

.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-icon { font-size: 26px; line-height: 1.1; }
.card-title { flex: 1; min-width: 0; }
.card-title h2 { font-size: 17px; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-title .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; word-break: break-word; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.off { background: var(--muted); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.dot.wait { background: var(--warn); animation: blink 1s infinite; }

@keyframes blink { 50% { opacity: .25; } }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }

.btn {
  flex: 1 1 auto;
  min-width: 92px;
  min-height: 44px;
  padding: 10px 14px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #0b1020; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-width: 0; min-height: 34px; padding: 5px 12px; font-size: 13px; flex: 0 0 auto; }
.btn.link { flex: 0 0 auto; }

.btn.icon-btn {
  min-width: 0;
  min-height: 36px;
  width: 36px;
  padding: 0;
  flex: 0 0 auto;
  color: var(--muted);
}
.btn.icon-btn:hover { color: var(--bad); border-color: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: transparent; color: #fff; font-weight: 600; }

/* --- «вы уверены?» --- */

.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 22px 22px 18px;
  width: min(92vw, 380px);
  margin: auto;
}
.modal::backdrop { background: rgb(0 0 0 / .55); }
.modal h2 { font-size: 19px; margin: 0 0 8px; }
.modal .muted { font-size: 14px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; }

/* align-content, а не place-items: иначе строки растянутся по всей высоте. */
.bye {
  min-height: 70vh;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 6px;
}

/* --- всплывашка --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 15px;
  font-size: 14px;
  white-space: pre-wrap;
  box-shadow: 0 10px 30px rgb(0 0 0 / .35);
}
.toast.bad { border-left-color: var(--bad); }
