/* Тёмная панель состояния. Не «дефолтная Grafana»: спокойный графит, один акцент,
   крупная типографика там, где нужно понять состояние за секунду. */

:root {
  /* Тёплый чёрный: не синеватый графит, а глубокий уголь с коричневым подтоном */
  --bg: #0c0a09;
  --bg-2: #100d0b;
  --surface: #16120f;
  --surface-2: #1d1814;
  --line: #2a231d;
  --line-soft: rgba(190, 160, 130, 0.13);

  --text: #f2ece4;
  --text-dim: #a99c8c;
  --text-faint: #7b6e60;

  --ok: #6ecf87;
  --warn: #e8b04b;
  --crit: #ff6f5e;
  --accent: #f0a04b;

  --radius: 14px;
  --radius-lg: 20px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 560px at 12% -12%, #1e1611 0%, transparent 62%),
    radial-gradient(900px 520px at 108% 6%, #1a1310 0%, transparent 58%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  padding: 0 clamp(12px, 3vw, 28px) 40px;
}

/* Едва заметная зернистость: убирает ощущение «плоской заливки» */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

main, header, footer { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; }

/* ── Шапка ─────────────────────────────────────────────── */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 26px 2px 22px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 {
  margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
  font-family: var(--mono);
}
.brand .sub { margin: 2px 0 0; font-size: 13px; color: var(--text-faint); }

/* Точка-пульс: видно, что страница живая, а не замерла */
.mark {
  width: 11px; height: 11px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(110, 207, 135, .5);
  animation: pulse 2.6s ease-out infinite;
  flex: none;
}
.mark.stale { background: var(--text-faint); animation: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(110, 207, 135, .45); }
  70%  { box-shadow: 0 0 0 12px rgba(110, 207, 135, 0); }
  100% { box-shadow: 0 0 0 0 rgba(110, 207, 135, 0); }
}

.top-meta { display: flex; gap: 16px; font-family: var(--mono); font-size: 13px; }
.meta-item { color: var(--text-dim); }
.dim { color: var(--text-faint); }

/* ── Светофор ──────────────────────────────────────────── */
.verdict {
  display: flex; gap: 18px; align-items: flex-start;
  padding: 22px 24px; margin-bottom: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface) 0%, rgba(18, 25, 36, .55) 100%);
}
.verdict[data-state="ok"]      { border-color: rgba(110, 207, 135, .28); box-shadow: inset 0 1px 0 rgba(110,207,135,.07); }
.verdict[data-state="warn"]    { border-color: rgba(232, 176, 75, .35); box-shadow: 0 0 44px -20px var(--warn); }
.verdict[data-state="crit"]    { border-color: rgba(255, 111, 94, .45); box-shadow: 0 0 48px -16px var(--crit); }
.verdict-icon {
  font-size: 30px; line-height: 1; width: 52px; height: 52px; flex: none;
  display: grid; place-items: center; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
}
.verdict[data-state="ok"]   .verdict-icon { color: var(--ok); }
.verdict[data-state="warn"] .verdict-icon { color: var(--warn); }
.verdict[data-state="crit"] .verdict-icon { color: var(--crit); }
.verdict h2 { margin: 4px 0 0; font-size: 21px; font-weight: 600; letter-spacing: -0.01em; }
.verdict-list { margin: 10px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 14px; }
.verdict-list:empty { display: none; }
.verdict-list li { margin: 3px 0; }

/* ── Сетки и карточки ──────────────────────────────────── */
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid-top { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  min-width: 0;
  transition: border-color .25s ease;
}
.card:hover { border-color: rgba(190, 160, 130, .22); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 {
  margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-faint);
}
.badge {
  font-family: var(--mono); font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line-soft); color: var(--text-dim); background: var(--surface-2);
  white-space: nowrap;
}
.badge.ok   { color: var(--ok);   border-color: rgba(110, 207, 135, .3); }
.badge.warn { color: var(--warn); border-color: rgba(232, 176, 75, .35); }
.badge.crit { color: var(--crit); border-color: rgba(255, 111, 94, .4); }

.note { margin: 12px 0 0; font-size: 12.5px; color: var(--text-dim); }

/* ── ИБП ───────────────────────────────────────────────── */
.ups-body { display: flex; align-items: center; gap: 22px; }
.ring { position: relative; width: 122px; height: 122px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring-bg { stroke: var(--line); }
.ring-fg {
  stroke: var(--ok);
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset .8s cubic-bezier(.4, 0, .2, 1), stroke .4s;
}
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { display: block; font-family: var(--mono); font-size: 27px; font-weight: 600; letter-spacing: -.02em; }
.ring-label span { font-size: 11px; color: var(--text-faint); }

.kv { margin: 0; display: grid; gap: 10px; min-width: 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.kv dt { color: var(--text-faint); font-size: 13px; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 15px; text-align: right; }

/* ── Сайты ─────────────────────────────────────────────── */
.sites { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.sites li { display: flex; align-items: center; gap: 10px; font-size: 14px; min-width: 0; }
.sites .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.sites .dot.up { background: var(--ok); }
.sites .dot.down { background: var(--crit); box-shadow: 0 0 12px -1px var(--crit); }
.sites .host { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sites .when { margin-left: auto; font-size: 12px; color: var(--text-faint); flex: none; }

/* ── Показатели ────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats-2 { grid-template-columns: repeat(2, 1fr); }
.stats-3 { grid-template-columns: repeat(3, 1fr); }
.stat { text-align: center; padding: 10px 4px; border-radius: 10px; background: var(--surface-2); }
.stat-v { display: block; font-family: var(--mono); font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.stat-l { font-size: 11px; color: var(--text-faint); }
.stat.hot .stat-v { color: var(--warn); }
.stat.crit .stat-v { color: var(--crit); }

.fans { display: flex; gap: 3px; margin-top: 14px; height: 34px; align-items: flex-end; }
.fans i {
  flex: 1; border-radius: 2px 2px 0 0; background: linear-gradient(180deg, var(--accent), rgba(240,160,75,.22));
  min-height: 3px; transition: height .5s ease;
}
.fans i.low { background: linear-gradient(180deg, var(--crit), rgba(255,111,94,.25)); }

.bars { display: grid; gap: 13px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 54px; align-items: center; gap: 10px; }
.bar-l { font-size: 13px; color: var(--text-dim); }
.bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .6s ease, background .3s; }
.bar i.warn { background: var(--warn); }
.bar i.crit { background: var(--crit); }
.bar-v { font-family: var(--mono); font-size: 13px; text-align: right; }

/* ── Графики ───────────────────────────────────────────
   Все показатели столбиком, период один на всех: смотреть, а не кликать. */
.chart-card { padding-bottom: 14px; }
.chart-head { flex-wrap: wrap; gap: 12px; }
.switch { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line-soft); }
.switch button {
  appearance: none; border: 0; background: transparent; color: var(--text-dim);
  font-family: var(--sans); font-size: 12.5px; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  transition: background .18s, color .18s;
}
.switch button:hover { color: var(--text); }
.switch button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }

.charts { display: grid; gap: 18px; }
.chart-block { min-width: 0; }
.chart-title {
  display: flex; align-items: baseline; gap: 10px;
  font-size: 13px; color: var(--text-dim); margin-bottom: 4px;
}
.chart-empty-mark { font-size: 11.5px; color: var(--text-faint); }
/* Пик за период и полный объём — справа в строке заголовка, чтобы не мешали названию */
.chart-note {
  margin-left: auto; font-family: var(--mono); font-size: 11.5px;
  color: var(--text-faint); white-space: nowrap;
}
.chart-note b { color: var(--text-dim); font-weight: 600; }
.chart-note .sep { opacity: .45; margin: 0 6px; }
.chart-wrap { position: relative; }
.chart-block canvas { width: 100%; height: 150px; display: block; cursor: crosshair; }

/* Подсказка при наведении: что было в конкретный момент */
.tip {
  position: absolute; z-index: 3; pointer-events: none;
  min-width: 148px; max-width: 260px;
  padding: 9px 11px; border-radius: 10px;
  background: rgba(22, 18, 15, .97);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .8);
  font-size: 12px; line-height: 1.45;
  animation: tip-in .12s ease-out;
}
@keyframes tip-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.tip-time { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-bottom: 5px; }
.tip-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip-name { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }
.tip-row b { margin-left: auto; font-family: var(--mono); font-weight: 600; }
.tip-more { margin-top: 4px; color: var(--text-faint); font-size: 11px; }

.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 6px; font-size: 11.5px; color: var(--text-faint); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; }

/* ── События ───────────────────────────────────────────── */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 340px; overflow-y: auto; }
.events li { display: grid; grid-template-columns: 128px 1fr; gap: 12px; padding: 7px 8px; border-radius: 8px; font-size: 13.5px; align-items: baseline; }
.events li:nth-child(odd) { background: rgba(255,255,255,.015); }
.events time { font-family: var(--mono); font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.events .lvl-crit { color: var(--crit); }
.events .lvl-warn { color: var(--warn); }

footer { margin-top: 26px; text-align: center; font-size: 12px; color: var(--text-faint); display: grid; gap: 4px; }
footer .ver { font-family: var(--mono); font-size: 11px; opacity: .7; }

/* Бэкапы */
.backups { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.backups li { display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
.backups .b-app { font-family: var(--mono); font-size: 13px; }
.backups .b-when { margin-left: auto; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.backups .b-when.stale { color: var(--warn); }
.backups .b-when.bad { color: var(--crit); }
.backups .b-size { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }

/* ── Телефон ───────────────────────────────────────────── */
@media (max-width: 860px) {
  .grid-top, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .top { padding-top: 18px; }
  .verdict { padding: 18px; gap: 14px; }
  .verdict h2 { font-size: 18px; }
  .ups-body { gap: 16px; }
  .ring { width: 104px; height: 104px; }
  .events li { grid-template-columns: 1fr; gap: 2px; }
  .events time { font-size: 11px; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .stat-v { font-size: 18px; }
  .top-meta { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Страница входа ────────────────────────────────────
   Своя форма вместо браузерного окна basic auth: то окно выглядит как ошибка,
   не запоминает пароль по-человечески и не даёт выйти. */
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: 100%; max-width: 380px; }
.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 34px 30px 26px;
  text-align: center;
  box-shadow: 0 40px 80px -50px rgba(0, 0, 0, .9);
}
.login-mark {
  width: 54px; height: 54px; margin: 0 auto 16px;
  display: grid; place-items: center; font-size: 26px;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line-soft);
}
.login-card h1 { margin: 0; font-family: var(--mono); font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.login-sub { margin: 6px 0 24px; font-size: 12.5px; color: var(--text-faint); line-height: 1.5; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; box-sizing: border-box;
  padding: 11px 13px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); font-family: var(--mono); font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.field input::placeholder { color: var(--text-faint); font-family: var(--sans); font-size: 14px; }
.field input:focus {
  outline: none; border-color: rgba(240, 160, 75, .55);
  box-shadow: 0 0 0 3px rgba(240, 160, 75, .12);
}

.login-btn {
  width: 100%; margin-top: 6px; padding: 12px 16px;
  border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(180deg, #f0a04b, #d9873a);
  color: #1a1207; font-family: var(--sans); font-size: 15px; font-weight: 600;
  transition: filter .2s, transform .06s;
}
.login-btn:hover { filter: brightness(1.07); }
.login-btn:active { transform: translateY(1px); }

.login-error {
  margin: 0 0 16px; padding: 10px 12px; border-radius: 10px;
  background: rgba(255, 111, 94, .09); border: 1px solid rgba(255, 111, 94, .32);
  color: var(--crit); font-size: 13px; text-align: left;
}
.login-note { margin: 18px 0 0; font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }

/* Кнопка выхода в шапке панели */
.logout {
  appearance: none; border: 1px solid var(--line-soft); background: var(--surface-2);
  color: var(--text-dim); font-family: var(--sans); font-size: 12px;
  padding: 5px 11px; border-radius: 8px; cursor: pointer; text-decoration: none;
  transition: color .2s, border-color .2s;
}
.logout:hover { color: var(--text); border-color: rgba(190, 160, 130, .3); }
