:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-2: #171b25;
  --line: #232936;
  --line-2: #2d3545;
  --text: #e7eaf1;
  --muted: #8b94a7;
  --muted-2: #667088;
  --accent: #4f8cff;
  --accent-2: #7aa9ff;
  --green: #35d07f;
  --yellow: #f2b13c;
  --red: #f2545b;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #16203a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
code, .mono { font-family: var(--mono); }

.app-loading { display: grid; place-items: center; min-height: 100vh; }
.boot { color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 22px;
  background: rgba(12, 15, 21, 0.6);
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px; }
.brand svg { width: 28px; height: 28px; }
.brand b { font-size: 15px; letter-spacing: 0.2px; }
.brand span { display: block; font-size: 11px; color: var(--muted-2); font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px; color: var(--muted);
  font-weight: 500; font-size: 13.5px;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.active { background: #1a2440; color: #cfe0ff; }
.nav svg { width: 17px; height: 17px; opacity: .9; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted-2); padding: 0 8px; }
.sidebar-foot .user { color: var(--muted); margin-bottom: 6px; }

.main { padding: 26px 30px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 21px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- primitives ---------- */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, #10131a 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card.pad-0 { padding: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 14px; color: #cfd6e6; }
.card-head .hint { font-size: 12px; color: var(--muted-2); }
.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }
.grid.kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: 1.55fr 1fr; align-items: start; }
.grid.two-even { grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 1100px) {
  .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.two-even { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 76px 1fr; }
  .sidebar { padding: 16px 8px; }
  .brand span, .brand b, .nav a span, .sidebar-foot { display: none; }
  .brand { justify-content: center; padding: 0; }
  .nav a { justify-content: center; }
  .main { padding: 20px 16px 50px; }
}

.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.kpi .delta { font-size: 12px; color: var(--muted-2); margin-top: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.blue { background: var(--accent); }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }
.dot.gray { background: var(--muted-2); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.allow { background: rgba(53, 208, 127, .1); color: #6ee7a8; border-color: rgba(53, 208, 127, .25); }
.badge.challenge { background: rgba(242, 177, 60, .1); color: #f6c86a; border-color: rgba(242, 177, 60, .25); }
.badge.block { background: rgba(242, 84, 91, .1); color: #ff8b90; border-color: rgba(242, 84, 91, .25); }
.badge.monitor { background: rgba(139, 148, 167, .12); color: #b6bfd1; border-color: var(--line-2); }
.badge.mode-challenge { background: rgba(79, 140, 255, .12); color: #9dc0ff; border-color: rgba(79, 140, 255, .3); }
.badge.mode-block { background: rgba(242, 84, 91, .12); color: #ff9b9f; border-color: rgba(242, 84, 91, .3); }
.badge.mode-monitor { background: rgba(139, 148, 167, .12); color: #b6bfd1; border-color: var(--line-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 550; font-size: 13px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #1d2230; border-color: #39435a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5f98ff; }
.btn.danger { color: #ff9b9f; border-color: rgba(242, 84, 91, .35); background: rgba(242, 84, 91, .08); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field .help { font-size: 11.5px; color: var(--muted-2); }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: #0c0f15; border: 1px solid var(--line-2); border-radius: 9px;
  padding: 9px 11px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, .15); }
textarea { resize: vertical; min-height: 74px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field, .row > div:not(.field) { flex: 1 1 180px; min-width: 160px; }
.row > .btn { flex: 0 0 auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.check input { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 420px; }
.events-table { table-layout: fixed; }
.table-wrap table.events-table { min-width: 980px; }
.events-table th:nth-child(1) { width: 76px; }
.events-table th:nth-child(2) { width: 148px; }
.events-table th:nth-child(4) { width: 104px; }
.events-table th:nth-child(5) { width: 70px; }
.events-table th:nth-child(6) { width: 24%; }
.events-table th:nth-child(7) { width: 210px; }
.events-table th, .events-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.events-table td.truncate { max-width: none; }
th {
  text-align: left; font-weight: 550; color: var(--muted-2); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; padding: 9px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid #1a1f29; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
td.num, th.num { text-align: right; }
.ip { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.dim { color: var(--muted-2); }
.small { font-size: 12px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted-2); font-size: 13px; }

.chart { width: 100%; height: 170px; display: block; }
.chart .bar { transition: opacity .15s; }
.chart .bar:hover { opacity: .75; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.reason-list { display: flex; flex-direction: column; }
.reason-row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 7px 0; border-bottom: 1px solid #1a1f29; font-size: 13px; }
.reason-row:last-child { border-bottom: 0; }
.reason-row span { color: var(--muted); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reason-row b { flex: 0 0 auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.code {
  background: #080a0f; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; color: #b9c6e0;
  overflow-x: auto; white-space: pre; position: relative;
}
.code .copy { position: absolute; top: 8px; right: 8px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 6, 10, .72); display: grid; place-items: center; z-index: 50;
  padding: 20px;
}
.modal { width: min(680px, 100%); max-height: 86vh; overflow: auto; }
.modal h2 { font-size: 17px; margin-bottom: 6px; }
.modal p { color: var(--muted); margin: 0 0 12px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); }
.login .brand { justify-content: center; margin-bottom: 18px; }
.login h1 { font-size: 18px; text-align: center; margin-bottom: 4px; }
.login p { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.error { color: #ff9b9f; font-size: 12.5px; min-height: 18px; }

.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 80;
  background: #1b2230; border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
  padding: 11px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 12px 30px rgba(0,0,0,.45);
  animation: slide .18s ease-out;
}
.toast.err { border-left-color: var(--red); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 9px 12px; cursor: pointer; font-size: 13px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.site-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  gap: 8px 12px; padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.site-card:last-child { border-bottom: 0; }
.site-card .grow { min-width: 0; }
.site-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card .domain { color: var(--muted-2); font-size: 12px; font-family: var(--mono); }
.site-card .site-actions { display: flex; align-items: center; gap: 6px; }
.site-card .stat-inline { grid-column: 1 / -1; gap: 14px; }
.stat-inline { display: flex; gap: 18px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.stat-inline b { color: var(--text); font-weight: 600; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.range-hint { font-size: 11.5px; color: var(--muted-2); }

@media (max-width: 700px) {
  .topbar h1 { font-size: 18px; }
  .kpi .label { min-height: 34px; align-items: flex-start; }
  .kpi .value { margin-top: 2px; }
  .main { padding: 16px 12px 44px; }
  .card { padding: 14px; }
  .kpi .value { font-size: 24px; }
  .site-card { grid-template-columns: 1fr; }
  .site-card .site-actions { grid-row: 2; justify-content: flex-start; }
  .site-card .stat-inline { grid-row: 3; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; }
  #ev-q { width: 100% !important; }
  .card-head > div { width: 100%; }
  .topip-table th:nth-child(2), .topip-table td:nth-child(2),
  .topip-table th:nth-child(3), .topip-table td:nth-child(3) { display: none; }
  .table-wrap .topip-table { min-width: 0; }
  /* на телефоне в событиях оставляем время, IP и вердикт */
  .events-table th:nth-child(3), .events-table td:nth-child(3),
  .events-table th:nth-child(5), .events-table td:nth-child(5),
  .events-table th:nth-child(6), .events-table td:nth-child(6),
  .events-table th:nth-child(7), .events-table td:nth-child(7) { display: none; }
  .table-wrap table.events-table { min-width: 0; }
  .events-table th, .events-table td { padding: 8px 8px; }
  .events-table th:nth-child(1) { width: 62px; }
  .events-table th:nth-child(2) { width: auto; }
  .events-table th:nth-child(4) { width: 96px; }
  .events-table td.ip { font-size: 11.5px; }
}
