:root {
  --bg: #0f1217;
  --surface: #171b22;
  --surface-2: #1d222b;
  --border: #272d38;
  --text: #e6e9ef;
  --muted: #8b94a3;
  --accent: #4da3ff;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --down: #ff5d5d;
  --stale: #8b94a3;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.6em 0 .6em; }
h3 { margin: 0 0 .4em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.right { text-align: right; }
.center { text-align: center; padding: 20vh 16px; }
.nowrap { white-space: nowrap; }

/* ---- шапка ---- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: rgba(15, 18, 23, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.top nav a:hover { text-decoration: none; color: var(--text); }
.top nav a.active { color: var(--text); background: var(--surface-2); }
.logout { margin: 0; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px; }
.link:hover { color: var(--text); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.wrap-row { flex-wrap: wrap; }
.back { color: var(--muted); }

/* ---- карточки ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; margin-top: 12px; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; color: var(--text);
}
a.card:hover { text-decoration: none; border-color: #3a4352; background: var(--surface-2); }
section.card { margin: 12px 0; }
.card-head { display: flex; align-items: center; gap: 8px; }
.name { font-weight: 600; }
.slug { color: var(--muted); font-size: .8em; background: var(--surface-2); border-radius: 6px; padding: 1px 6px; font-weight: 400; }
.badge { font-size: .75em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--muted); font-weight: 400; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--stale); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 207, 142, .15); }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px rgba(255, 93, 93, .18); }
.state { margin: 4px 0 8px 18px; font-size: .85em; color: var(--muted); }
.state.ok { color: var(--ok); } .state.warn { color: var(--warn); } .state.down { color: var(--down); }
.state.big { margin: 0; font-size: 1.05em; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 12px; margin: 0; }
.stats.big { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); margin: 12px 0; }
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: .75em; text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats dd small { color: var(--muted); font-weight: 400; }
.stats.big dd { font-size: 1.2em; }
.disabled-list { margin-top: 16px; color: var(--muted); }
.disabled-list ul { margin: 6px 0 0; padding-left: 20px; }

/* ---- кнопки и формы ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px; font: inherit; cursor: pointer;
  min-height: 40px;
}
.btn:hover { border-color: #3a4352; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07101a; font-weight: 600; }
.btn.warn { border-color: #5b4a1d; color: var(--warn); }
.btn.danger { border-color: #5e2a2a; color: var(--down); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85em; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; align-items: center; }
.form { margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 14px; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: .85em; }
input, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font: inherit; min-height: 40px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field.has-error input { border-color: var(--down); }
.err { color: var(--down); font-style: normal; font-size: .85em; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.check input { width: auto; min-height: 0; }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit b { color: var(--muted); font-weight: 400; min-width: 2.2em; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 8px 0 14px; }
.filters .field { min-width: 180px; }
.alert { border-radius: 10px; padding: 10px 14px; margin: 10px 0; border: 1px solid var(--border); background: var(--surface-2); }
.alert.ok { border-color: #1f5a41; color: var(--ok); }
.alert.error { border-color: #5e2a2a; color: var(--down); }
.alert.warn { border-color: #5b4a1d; color: var(--warn); }
.alert p { margin: 0 0 .5em; }
pre.code { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; color: var(--text); }

/* ---- таблицы ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .85em; }
.center-cell { text-align: center; }
.events-mini { list-style: none; padding: 0; margin: 0; }
.events-mini li { padding: 6px 0; border-bottom: 1px solid var(--border); }

/* ---- графики ---- */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tab { background: none; border: 0; color: var(--muted); font: inherit; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.tab.active { background: var(--surface-2); color: var(--text); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin-top: 10px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 8px; }
.chart figcaption { color: var(--muted); font-size: .85em; margin-bottom: 4px; }
.chart-box { position: relative; height: 170px; }

/* ---- окна подтверждения ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50;
}
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; width: 100%; max-width: 440px; }

/* ---- вход ---- */
.login { max-width: 380px; margin: 14vh auto 0; text-align: center; }
.login-widget { margin: 22px 0 14px; min-height: 48px; display: flex; justify-content: center; }

/* ---- телефон ---- */
@media (max-width: 640px) {
  .top { gap: 6px; padding: 8px 8px; }
  .brand { font-size: .95em; }
  .top nav { gap: 0; }
  .top nav a { padding: 6px 7px; font-size: .92em; }
  .link { padding: 6px 4px; font-size: .92em; }
  .wrap { padding: 12px; }
  h1 { font-size: 1.35rem; }
  .charts { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  table.events thead { display: none; }
  table.events tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.events td { display: flex; gap: 10px; border: 0; padding: 2px 0; }
  table.events td::before { content: attr(data-label); color: var(--muted); min-width: 72px; font-size: .85em; }
  table.events td.center-cell, table.events td.right { display: block; }
  table.events td.center-cell::before, table.events td.right::before { content: none; }
  .actions .btn { flex: 1 1 100%; justify-content: center; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box { max-width: none; border-radius: 16px 16px 0 0; }
  .modal-box .actions .btn { flex: 1 1 100%; }
}
