:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --bg-alt: linear-gradient(135deg, #f8f9fb, #eef2f7);
  --text: #1f2933;
  --muted: #5a6774;
  --surface: rgba(255, 255, 255, 0.8);
  --surface-strong: rgba(255, 255, 255, 0.95);
  --border: rgba(31, 41, 51, 0.12);
  --ok: #0f766e;
  --warn: #b45309;
  --shadow: 0 18px 42px rgba(31, 41, 51, 0.08);
  --accent-a: #2563eb;
  --accent-b: #0891b2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --bg-alt: linear-gradient(130deg, #121821, #0d1218);
    --text: #e8eff7;
    --muted: #9fb0c3;
    --surface: rgba(16, 22, 31, 0.78);
    --surface-strong: rgba(16, 22, 31, 0.92);
    --border: rgba(232, 239, 247, 0.14);
    --ok: #22c55e;
    --warn: #f59e0b;
    --shadow: 0 22px 44px rgba(0, 0, 0, 0.35);
    --accent-a: #60a5fa;
    --accent-b: #22d3ee;
  }
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  background: var(--bg-alt);
  color: var(--text);
}

body { line-height: 1.45; }

.shell {
  width: min(1140px, 94vw);
  margin: 0 auto;
  padding: clamp(1.25rem, 1rem + 1.2vw, 2.5rem);
}

.auth-shell { width: min(760px, 94vw); }

.hero {
  padding: clamp(1.2rem, 1rem + 1vw, 2rem);
  border-radius: 22px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.top-actions {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  background: var(--accent-a);
  color: #fff;
  cursor: pointer;
  font: inherit;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  text-decoration: none;
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero h1 {
  margin: 0.3rem 0 0.4rem;
  font-size: clamp(1.8rem, 1.3rem + 2vw, 2.7rem);
  font-weight: 700;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 64ch;
}

.overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.chat-card {
  background: linear-gradient(145deg, rgba(255, 215, 238, 0.9), rgba(255, 178, 220, 0.85));
}

.chat-frame {
  width: 100%;
  min-height: 70vh;
  border: 1px solid rgba(191, 62, 131, 0.35);
  border-radius: 14px;
  background: #fff;
}

@media (prefers-color-scheme: dark) {
  .chat-card {
    background: linear-gradient(145deg, rgba(139, 47, 96, 0.5), rgba(186, 68, 127, 0.48));
  }

  .chat-frame {
    background: #121212;
    border-color: rgba(255, 170, 219, 0.35);
  }
}

.overview .metric,
.auth-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 0.9rem;
}

.metric-label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric-value {
  margin: 0.2rem 0 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.admin-grid { grid-template-columns: 320px 1fr; }

.page-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.page-card {
  display: grid;
  gap: 0.7rem;
}

.card {
  border-radius: 20px;
  padding: 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.card-title { margin: 0; font-size: 1.08rem; }

.pill {
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.22rem 0.65rem;
  border: 1px solid var(--border);
}

.pill.connected { color: var(--ok); }
.pill.disconnected { color: var(--warn); }

.source {
  margin: 0.5rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-word;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.stat {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0.55rem;
}

.stat dt {
  margin: 0;
  font-size: 0.73rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat dd {
  margin: 0.1rem 0 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.chart-wrap { margin-top: 0.9rem; }

.chart {
  width: 100%;
  height: 180px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 68%);
}

.chart.bar-mode {
  height: 240px;
}

.bar-chart {
  width: 100%;
  height: 260px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 68%);
  margin-top: 0.8rem;
}

.insight-panel[hidden] {
  display: none;
}

.legend {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.76rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  display: inline-block;
}

.stack {
  display: grid;
  gap: 0.65rem;
}

.stack.compact { gap: 0.5rem; }

.field {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.page-access {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  display: grid;
  gap: 0.45rem;
}

.page-access legend {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0 0.25rem;
}

.feedback {
  margin-top: 0.9rem;
  min-height: 1.3rem;
  color: var(--muted);
}

.feedback[data-kind="error"] { color: #dc2626; }
.feedback[data-kind="ok"] { color: var(--ok); }

.user-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem;
}

.user-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.reveal {
  opacity: 0;
  transform: translateY(12px);
  animation: rise 440ms ease forwards;
}

.reveal:nth-child(2) { animation-delay: 70ms; }
.reveal:nth-child(3) { animation-delay: 140ms; }

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 820px) {
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}
