:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --border: #e3e6ec;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d6453d;
  --danger-bg: #fdecea;
  --ok: #1f8a4c;
  --ok-bg: #e7f6ed;
  --warn: #b7791f;
  --warn-bg: #fdf3e1;
  --bar-deleted: #2f6fed;
  --bar-service: #a9c0f5;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b2029;
    --text: #e7eaf0;
    --muted: #9099ab;
    --border: #2a303c;
    --accent: #5b8ef5;
    --danger: #f07167;
    --danger-bg: #3a1f1e;
    --ok: #5cc98a;
    --ok-bg: #1b3326;
    --warn: #e0a84f;
    --warn-bg: #3a2e18;
    --bar-deleted: #5b8ef5;
    --bar-service: #34466e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- Каркас ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { font-weight: 700; font-size: 17px; padding: 0 8px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
}
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: var(--accent-text); }

.mode-pill {
  margin-top: auto;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
}
.mode-strict { background: var(--ok-bg); color: var(--ok); }
.mode-filter { background: var(--warn-bg); color: var(--warn); }
.mode-off { background: var(--danger-bg); color: var(--danger); }

.logout { padding: 0 8px; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; font: inherit; }
button.link:hover { color: var(--danger); }

main { flex: 1; min-width: 0; padding: 28px 32px 48px; max-width: 1100px; }
main > h1 + .muted { margin: 0 0 20px; }
main > * + .card, main > .card + * { margin-top: 16px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 20px 0 16px; }
.stat-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.list-grid { grid-template-columns: 3fr 2fr; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: end; }

/* ---------- График ---------- */

.legend { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-deleted { background: var(--bar-deleted); }
.dot-service { background: var(--bar-service); margin-left: 10px; }

.bars { display: flex; gap: 6px; height: 160px; align-items: stretch; }
.bar-col { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bar-stack { flex: 1; display: flex; flex-direction: column-reverse; }
.bar { width: 100%; }
.bar-deleted { background: var(--bar-deleted); border-radius: 4px 4px 0 0; }
.bar-service { background: var(--bar-service); }
.bar-stack .bar:first-child { border-radius: 0; }
.bar-label { text-align: center; font-size: 11px; color: var(--muted); }

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table th, .table td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.events .msg { max-width: 360px; overflow-wrap: anywhere; }

.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--bg); }
.tag-deleted { background: var(--danger-bg); color: var(--danger); }
.tag-service { background: var(--bg); color: var(--muted); }
.tag-muted { background: var(--warn-bg); color: var(--warn); }

.pager { display: flex; justify-content: space-between; margin-top: 12px; }

/* ---------- Формы ---------- */

input[type=search], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label select { display: block; margin-top: 4px; min-width: 160px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.filters { align-items: center; }

.btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }

.options { display: flex; flex-direction: column; gap: 8px; }
.option, .switch-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; }
.option input, .switch-row input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--accent); }
.option > span { display: flex; flex-direction: column; }

.hint { padding-left: 18px; margin: 0 0 12px; }
.hint li { margin-bottom: 6px; }

.flash { padding: 10px 14px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); margin-bottom: 16px; }
.flash-error { background: var(--danger-bg); color: var(--danger); }

.verdict-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.verdict-delete { border-color: var(--danger); background: var(--danger-bg); }
.verdict-keep { border-color: var(--ok); background: var(--ok-bg); }

/* ---------- Вход ---------- */

.center-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { max-width: 420px; width: 100%; }
.login-card .brand { padding: 0; margin-bottom: 12px; }
.login-card ol { padding-left: 20px; }

/* ---------- Телефон ---------- */

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    gap: 10px;
  }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .sidebar nav a { white-space: nowrap; padding: 6px 10px; }
  .mode-pill { margin-top: 0; }
  main { padding: 20px 16px 40px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2, .list-grid { grid-template-columns: 1fr; }
}
