:root {
  --bg: #080a0f;
  --bg-elevated: #10141c;
  --bg-panel: #141a24;
  --bg-panel-hover: #1a2230;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.24);
  --text: #f3f4f6;
  --text-muted: #94a3b8;
  --accent: #dc2626;
  --accent-soft: rgba(220, 38, 38, 0.14);
  --accent-glow: rgba(220, 38, 38, 0.35);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(220, 38, 38, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 24%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

.sidebar {
  width: var(--sidebar-width);
  padding: 1.5rem 1rem 1.25rem;
  background: linear-gradient(180deg, rgba(16, 20, 28, 0.98), rgba(10, 12, 18, 0.98));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #ef4444, #991b1b);
  box-shadow: 0 10px 24px var(--accent-glow);
}

.sidebar h1 {
  font-size: 1rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.sidebar .muted { color: var(--text-muted); font-size: 0.82rem; }

.sidebar-foot {
  font-size: 0.75rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1.5rem;
}

.nav-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.62rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav-btn.nav-active {
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.18), rgba(220, 38, 38, 0.04));
  border-color: rgba(220, 38, 38, 0.35);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.content {
  flex: 1;
  padding: 1.5rem 1.75rem 2rem;
  max-width: 1400px;
}

.page-head {
  margin-bottom: 1rem;
}

.page-head h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.page-head p {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(20, 26, 36, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.token-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.token-field input,
.token-field input[type='search'] {
  width: min(420px, 90vw);
  padding: 0.62rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 10, 15, 0.8);
  color: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.token-field input:focus {
  outline: none;
  border-color: rgba(220, 38, 38, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  padding: 0.62rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, #ef4444, #dc2626);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 10px 24px var(--accent-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn-outline {
  background: rgba(255, 255, 255, 0.02);
  border-color: var(--border-strong);
  color: #e5e7eb;
  box-shadow: none;
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-1px);
}

.btn:disabled { opacity: 0.6; cursor: wait; transform: none; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.status {
  min-height: 1.25rem;
  margin-bottom: 1rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.9rem;
}

.status.loading { color: var(--warn); background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.18); }
.status.error { color: var(--bad); background: rgba(248, 113, 113, 0.08); border-color: rgba(248, 113, 113, 0.18); }
.status.warn { color: var(--warn); background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.18); }
.status.ok { color: var(--ok); background: rgba(52, 211, 153, 0.08); border-color: rgba(52, 211, 153, 0.18); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: linear-gradient(180deg, rgba(20, 26, 36, 0.95), rgba(14, 18, 26, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(220, 38, 38, 0.65), transparent);
}

.kpi-card strong {
  display: block;
  font-size: 1.55rem;
  margin-top: 0.35rem;
  letter-spacing: -0.03em;
}

.kpi-card span {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.panel {
  background: rgba(20, 26, 36, 0.82);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

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

th, td {
  border-bottom: 1px solid var(--border);
  padding: 0.72rem 0.75rem;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(8, 10, 15, 0.45);
}

tbody tr:last-child td { border-bottom: none; }

tr[data-slug] { cursor: pointer; transition: background 0.12s ease; }
tr[data-slug]:hover, tr.row-selected { background: rgba(220, 38, 38, 0.06); }

.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

.link { color: #fca5a5; text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }

.link-btn,
.handoff-btn {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: #fecaca;
  cursor: pointer;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.15s ease;
}

.link-btn:hover,
.handoff-btn:hover {
  background: rgba(220, 38, 38, 0.22);
  transform: translateY(-1px);
}

#chart {
  width: 100%;
  max-width: 100%;
  background: rgba(8, 10, 15, 0.65);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.form-grid { display: grid; gap: 0.7rem; }

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 10, 15, 0.75);
  color: #fff;
  font: inherit;
}

.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }

.checklist { list-style: none; padding: 0; margin: 0 0 1rem; }
.checklist li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.checklist .done { color: var(--ok); }
.checklist .pending { color: var(--warn); }

.flags-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.panel h3 { margin: 1rem 0 0.5rem; font-size: 0.9rem; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.panel-head h2 { margin: 0; }

.btn-group { display: flex; gap: 0.35rem; }
.chart-days.active { background: rgba(220, 38, 38, 0.16); border-color: rgba(220, 38, 38, 0.45); }

.churn-high { color: var(--bad); }
.churn-medium { color: var(--warn); }
.churn-low { color: var(--ok); }

.badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-owned { background: rgba(52, 211, 153, 0.12); color: var(--ok); border: 1px solid rgba(52, 211, 153, 0.28); }
.badge-franchised { background: rgba(251, 191, 36, 0.12); color: var(--warn); border: 1px solid rgba(251, 191, 36, 0.28); }
.muted-cap { color: #64748b; font-size: 0.8rem; }

code {
  background: rgba(8, 10, 15, 0.7);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  font-size: 0.82rem;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
  }
  .content { padding: 1rem; }
}
