:root {
  --bg-deep: #070a10;
  --bg: #0c1018;
  --panel: #111827;
  --panel-elevated: #151d2e;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --muted2: #5c6678;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.12);
  --accent-glow: rgba(56, 189, 248, 0.35);
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --danger: #fb7185;
  --ok: #4ade80;
  --sidebar-w: 272px;
  --radius: 14px;
  --radius-sm: 10px;
  --font: "DM Sans", system-ui, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(56, 189, 248, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(14, 165, 233, 0.06), transparent);
}

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

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ——— Sidebar ——— */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.95) 0%, rgba(7, 10, 16, 0.98) 100%);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 20px;
  margin: -4px 0 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.brand:hover {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.03);
}
.brand-mark {
  color: var(--accent);
  flex-shrink: 0;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  margin: 0 -4px;
}
.nav-label {
  margin: 16px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted2);
}
.nav-label:first-child {
  margin-top: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  text-decoration: none;
}
.nav-item.is-active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.2);
}
.nav-item.is-active .nav-ico {
  opacity: 1;
}
.nav-item--external {
  opacity: 0.85;
}
.nav-ico {
  flex-shrink: 0;
  opacity: 0.75;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-item:hover .nav-ico,
.nav-item.is-active .nav-ico {
  opacity: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--muted2);
}

.logout-form {
  margin: 0;
}
.btn-logout {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-logout:hover {
  background: rgba(251, 113, 133, 0.1);
  border-color: rgba(251, 113, 133, 0.35);
  color: var(--danger);
}

/* ——— Main ——— */
.main-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  padding: 28px 32px 48px;
  max-width: 1280px;
}

.main h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.main h1 + .muted {
  margin-top: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}
.panel + .panel {
  margin-top: 16px;
}

.panel h2 {
  margin-top: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  border-bottom: 1px solid var(--border);
  padding: 12px 10px;
  text-align: left;
  font-size: 14px;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}
tbody tr:last-child td {
  border-bottom: none;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}
.badge--ok {
  background: rgba(74, 222, 128, 0.08);
  border-color: rgba(74, 222, 128, 0.25);
  color: var(--ok);
}
.badge--warn {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.25);
  color: #fbbf24;
}
.badge--err {
  background: rgba(251, 113, 133, 0.08);
  border-color: rgba(251, 113, 133, 0.25);
  color: var(--danger);
}
.badge--live {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.row {
  display: grid;
  gap: 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 8px;
}

input,
select,
textarea {
  width: 100%;
  max-width: 720px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-elevated);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover:not(:disabled),
.btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
}
button:active:not(:disabled),
.btn:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary,
.btn.primary {
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
  border-color: rgba(14, 165, 233, 0.5);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 4px 16px rgba(14, 165, 233, 0.25);
}
button.primary:hover:not(:disabled),
.btn.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 100%);
  border-color: rgba(56, 189, 248, 0.6);
}

.flash-ok {
  color: var(--ok);
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.2);
}
.flash-err {
  color: var(--danger);
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(251, 113, 133, 0.08);
  border: 1px solid rgba(251, 113, 133, 0.2);
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.audit-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.audit-toggle-group {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
}

.audit-toggle-group legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.audit-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--text);
}

.audit-toggle input {
  width: auto;
  max-width: none;
  margin: 0;
}

code {
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
}

/* Dashboard cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #6366f1);
  opacity: 0.85;
}
.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted2);
  margin-bottom: 8px;
}
.stat-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.stat-card-value--ok {
  color: var(--ok);
}
.stat-card-value--warn {
  color: #fbbf24;
}

.page-lead {
  margin-bottom: 24px;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-card .muted {
  margin-bottom: 24px;
  font-size: 14px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-brand .brand-mark {
  color: var(--accent);
}
.login-title {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.login-subtitle {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted2);
}
.login-card form.row .primary {
  width: 100%;
  margin-top: 4px;
}
.stat-hint {
  margin: 8px 0 0;
  font-size: 13px;
}

@media (max-width: 900px) {
  :root {
    --sidebar-w: 240px;
  }
  .main {
    padding: 20px 18px 40px;
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px;
    gap: 8px;
  }
  .brand {
    flex: 1;
    min-width: 0;
    padding: 6px 8px 8px;
    margin: 0;
  }
  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    max-height: none;
    order: 3;
    padding: 8px 0 0;
    border-top: 1px solid var(--border);
  }
  .nav-label {
    width: 100%;
    margin: 8px 8px 4px;
  }
  .nav-label:first-child {
    margin-top: 4px;
  }
  .nav-item {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
    justify-content: center;
    font-size: 13px;
    padding: 8px 10px;
  }
  .nav-ico {
    display: none;
  }
  .sidebar-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    width: auto;
    margin: 0;
    padding: 0;
    border: none;
    order: 2;
  }
  .user-chip {
    margin: 0;
    max-width: 160px;
  }
  .logout-form {
    width: auto;
  }
  .btn-logout {
    width: auto;
    padding: 8px 14px;
  }
}
