/* APEX GUARD admin — единая тема (день/ночь), акцент: красный/чёрный.
   Один CSS на весь /admin: не дублировать стили в шаблонах. */

:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-soft: #f3f3f6;
  --hover: #f8f8fb;
  --table-line: #efeff4;
  --border: #e7e7ec;
  --border-strong: #d8d8e0;
  --text: #111114;
  --muted: #70707c;
  --nav-label: #a0a0ad;
  --badge-bg: #f1f1f5;
  --accent: #e11d2e;
  --accent-2: #ff4d3d;
  --accent-soft: #ffecef;
  --accent-ink: #b31222;
  --ok: #15803d;
  --ok-soft: #e8f7ee;
  --danger: #c81e1e;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff6e6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 17, 20, 0.04), 0 18px 40px -28px rgba(17, 17, 20, 0.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08080a;
  --surface: #111114;
  --surface-soft: #17171d;
  --hover: #1a1a21;
  --table-line: #22222a;
  --border: #25252e;
  --border-strong: #353541;
  --text: #f3f3f6;
  --muted: #9898a6;
  --nav-label: #6f6f7d;
  --badge-bg: #1d1d24;
  --accent: #ff3347;
  --accent-2: #ff5a3c;
  --accent-soft: #2b1115;
  --accent-ink: #ff8a94;
  --ok: #38d17f;
  --ok-soft: #0f2a1c;
  --danger: #ff6b6b;
  --danger-soft: #2b1416;
  --warn: #f2a64b;
  --warn-soft: #2b1f10;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.55), 0 22px 44px -28px rgba(0, 0, 0, 0.95);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font: 14px/1.5 var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background 0.18s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }

code, .key, .mono { font-family: var(--mono); font-size: 12.5px; }

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

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 252px;
  padding: 22px 16px 18px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 8px 22px;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px -10px rgba(225, 29, 46, 0.8);
}

.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-section {
  margin: 14px 10px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nav-label);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-soft);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent-ink);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-link .icon { width: 18px; height: 18px; flex: none; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid var(--border);
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  color: #fff;
  font-weight: 650;
  font-size: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------------- main */
.main { flex: 1; min-width: 0; margin-left: 252px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 68px;
  padding: 0 30px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-title { font-size: 15px; font-weight: 650; }
.topbar-sub { margin-left: 8px; font-size: 12px; color: var(--muted); }
.topbar .spacer { flex: 1; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.content {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 30px 64px;
}

h1 {
  margin: 0 0 20px;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 { margin: 0 0 14px; font-size: 19px; }
h3 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }

p { margin: 8px 0; }

.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }

/* ------------------------------------------------------------------ cards */
.card {
  padding: 20px;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.card-title { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.grid .card {
  position: relative;
  margin: 0;
  padding: 18px 18px 20px;
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--accent);
  background: var(--accent-soft);
}

.stat-icon svg { width: 18px; height: 18px; }

.metric {
  margin-top: 4px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.funnel { display: flex; align-items: center; gap: 12px; min-width: 240px; max-width: 420px; }

progress {
  flex: 1;
  height: 8px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

progress::-webkit-progress-bar { background: var(--surface-soft); border-radius: 999px; }
progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.funnel-count {
  min-width: 28px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- tables */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 2px 0;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--table-line);
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }

table.kv th { width: 220px; }
table.kv th, table.kv td { padding-top: 11px; padding-bottom: 11px; }

tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }

td code { padding: 2px 6px; border-radius: 6px; background: var(--surface-soft); }

/* ------------------------------------------------------------------ forms */
form { margin: 0; }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.form-stack { display: grid; gap: 12px; }
.mt { margin-top: 12px; }

label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

label input, label select { margin-top: 6px; }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}

input::placeholder { color: var(--muted); opacity: 0.7; }

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(225, 29, 46, 0.18);
  outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent);
  outline-offset: 0;
  border-color: var(--accent);
}

.input-sm { width: 112px; }
.input-md { width: 150px; }
.input-search { min-width: 300px; }
.input-block { width: 100%; }

button {
  cursor: pointer;
  font-weight: 550;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover { background: var(--surface-soft); border-color: var(--border-strong); }
button:active { transform: translateY(1px); }

button.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 20px -12px rgba(225, 29, 46, 0.9);
}

button.primary:hover { filter: brightness(1.06); }

button.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: var(--surface);
}

button.danger:hover { background: var(--danger-soft); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.icon-btn:hover { color: var(--text); background: var(--surface-soft); }
.icon-btn .icon { width: 18px; height: 18px; }

.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ------------------------------------------------------------------ parts */
.key {
  padding: 16px;
  border: 1px solid var(--border);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  word-break: break-all;
  font-size: 14px;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 550;
  white-space: nowrap;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.breadcrumb { margin: -6px 0 16px; font-size: 13px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }

.empty { padding: 22px; color: var(--muted); text-align: center; }

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 0;
}

.page-btn {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.page-btn:hover {
  color: var(--text);
  background: var(--surface-soft);
  text-decoration: none;
}

.page-btn.disabled { opacity: 0.4; pointer-events: none; }
.page-info { color: var(--muted); font-size: 12.5px; margin: 0 auto; }

/* ------------------------------------------------------------------- auth */
.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
  background:
    radial-gradient(900px 500px at 10% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, color-mix(in srgb, var(--accent-2) 9%, transparent), transparent 60%),
    var(--bg);
}

.auth-wrap { width: min(420px, 100%); }

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  margin-bottom: 20px;
}

.auth-theme { position: fixed; top: 20px; right: 20px; z-index: 30; }

.login-card {
  width: 100%;
  margin: 0;
  padding: 26px;
  border-radius: 20px;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.45);
}

.login-sub { margin: -6px 0 18px; font-size: 13px; }
.login-card button { width: 100%; margin-top: 4px; }
.login-card p { margin: 0 0 12px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.login-hint { margin: 6px 0 14px; font-size: 12px; }

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-left: 3px solid var(--accent);
}

.notice strong { display: block; margin-bottom: 2px; }
.notice form { flex: none; }

/* ------------------------------------------------------------------- 404 */
.not-found { padding: 34px 28px; text-align: center; }

.not-found-code {
  font-size: 84px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.not-found h2 { margin: 12px 0 6px; }
.not-found p { max-width: 320px; margin: 0 auto 20px; }

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 20px -12px rgba(225, 29, 46, 0.9);
}

.btn-link:hover { color: #fff; text-decoration: none; filter: brightness(1.06); }

/* --------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .app { display: block; }

  .sidebar {
    position: static;
    width: 100%;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand { padding: 0 0 12px; }
  .nav-section, .sidebar-footer { display: none; }

  .sidebar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-bottom: 2px;
  }

  .nav-link { white-space: nowrap; padding: 8px 11px; }

  .main { margin-left: 0; }
  .topbar { position: static; height: auto; padding: 14px 18px; }
  .content { padding: 20px 18px 48px; }
}

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  .card { padding: 16px; border-radius: 14px; }
  .input-search { min-width: 100%; }
  .status-pill { display: none; }
  .topbar-sub { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid .card { padding: 14px; }
  .metric { font-size: 24px; }
  .stat-icon { width: 32px; height: 32px; margin-bottom: 10px; }
  table.kv th { width: 140px; }
  .notice { align-items: stretch; flex-direction: column; }
  .notice form button { width: 100%; }
  th, td { padding: 9px; }
}
