:root {
  --bg: #070b14;
  --bg-elevated: #0d1321;
  --card: rgba(17, 24, 39, 0.85);
  --card-border: rgba(148, 163, 184, 0.12);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --sidebar-w: 260px;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(99, 102, 241, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(14, 165, 233, 0.1), transparent);
  pointer-events: none;
  z-index: 0;
}

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

/* —— App shell —— */
.app-shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(10, 15, 28, 0.95);
  border-right: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1.25rem 1.1rem;
  border-bottom: 1px solid var(--card-border);
}

.sidebar__logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.sidebar__brand strong { display: block; font-size: 1rem; }
.sidebar__brand small { color: var(--muted); font-size: 0.72rem; }

.sidebar__nav { flex: 1; padding: 0.75rem 0.6rem; overflow-y: auto; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.sidebar__link:hover { background: rgba(99, 102, 241, 0.1); color: var(--text); text-decoration: none; }
.sidebar__link.is-active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.25), transparent);
  color: #fff;
  border-left: 3px solid var(--accent);
  padding-left: calc(0.85rem - 3px);
}

.sidebar__icon { opacity: 0.85; font-size: 1rem; width: 1.25rem; text-align: center; }

.sidebar__foot {
  padding: 1rem;
  border-top: 1px solid var(--card-border);
}

.sidebar__user {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 110;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-top {
  padding: 1.25rem 1.5rem 0;
  border-bottom: 1px solid transparent;
}

.page-top__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-body { padding: 1.25rem 1.5rem 2rem; flex: 1; }

/* —— Login —— */
.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-wrap { width: 100%; max-width: 420px; padding: 1.5rem; }

.login-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-card .muted { margin-bottom: 1.5rem; }

/* —— Cards & grid —— */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, transform 0.2s;
}

.card:hover { border-color: rgba(99, 102, 241, 0.3); }

.card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; font-weight: 600; }

.grid { display: grid; gap: 1rem; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.stat-card {
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  opacity: 0.6;
}

.stat-num {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(135deg, #fff, var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

.muted { color: var(--muted); }
.lead { font-size: 1rem; color: var(--muted); margin: 0 0 1.25rem; }

/* —— Forms —— */
.form-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.form-card h2, .form-card h3 { margin-top: 0; }

.form-section { margin-bottom: 1.5rem; }
.form-section__title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

label { display: block; margin: 0.75rem 0 0.35rem; font-weight: 500; font-size: 0.85rem; }

input, textarea, select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { min-height: 100px; resize: vertical; font-family: ui-monospace, monospace; font-size: 0.82rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* —— Site picker —— */
.site-picker__toolbar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }

.site-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.site-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.site-chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
}

.site-chip input { width: auto; margin: 0; accent-color: var(--accent); }
.site-chip__label { font-size: 0.8rem; font-weight: 500; }

.site-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 10px;
  background: #334155;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-danger { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.btn-ghost { background: transparent; border: 1px solid var(--card-border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; min-width: 200px; }

.search-input {
  max-width: 320px;
  background: var(--card);
}

/* —— Table —— */
.table-panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

thead { background: rgba(0, 0, 0, 0.25); }

th {
  padding: 0.75rem 0.65rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: rgba(13, 19, 33, 0.98);
  z-index: 2;
}

th.site-col { text-align: center; min-width: 44px; max-width: 52px; padding: 0.5rem 0.25rem; }
th.site-col span { display: block; font-size: 0.65rem; line-height: 1.2; }

td { padding: 0.6rem 0.65rem; border-top: 1px solid var(--card-border); vertical-align: middle; }
td.center { text-align: center; }

tr:hover td { background: rgba(99, 102, 241, 0.04); }

.channel-title { font-weight: 500; }
.channel-slug code {
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  color: #c4b5fd;
}

.row-actions a {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-hover);
  text-decoration: none;
}

.row-actions a:hover { background: rgba(99, 102, 241, 0.28); text-decoration: none; }

/* —— Status dots —— */
.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
}

.status-dot--ok { background: var(--success); box-shadow: 0 0 8px rgba(34, 197, 94, 0.5); }
.status-dot--warn { background: var(--warn); box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); }
.status-dot--off { background: #64748b; }
.status-dot--missing { color: var(--muted); font-size: 0.75rem; background: none; width: auto; height: auto; }

/* —— Alerts —— */
.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.35); color: #fecaca; }
.alert-ok { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.3); color: #bbf7d0; }

.danger-zone {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.05);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.pill-ok { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.pill-warn { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.pill-off { background: rgba(100, 116, 139, 0.3); color: #cbd5e1; }

.result-table td:first-child { font-weight: 500; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .main { margin-left: 0; padding-top: 48px; }
}
