:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2733;
  --muted: #6b7480;
  --accent: #2f6df6;
  --accent-soft: #eaf1ff;
  --sidebar: #11161d;
  --sidebar-text: #c3cbd6;
  --sidebar-active: #2f6df6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 0;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  padding: 6px 22px 18px;
  letter-spacing: 0.2px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
  padding: 10px 22px;
  color: var(--sidebar-text);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar nav a:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }

.sidebar nav a.active {
  color: #fff;
  background: rgba(47, 109, 246, 0.16);
  border-left-color: var(--sidebar-active);
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.topbar-title { font-weight: 600; font-size: 15px; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
}

.topbar-user .user-email { font-size: 13px; }

.topbar-user .logout {
  color: var(--accent);
  font-weight: 500;
}
.topbar-user .logout:hover { text-decoration: underline; }

.content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* --- cards ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* --- KPIs -------------------------------------------------------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.kpi { display: flex; flex-direction: column; gap: 4px; }

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- tables ------------------------------------------------------------ */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

table.data thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbfc; }

table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .empty { color: var(--muted); text-align: center; padding: 18px; }

/* --- pills / badges ---------------------------------------------------- */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: capitalize;
}
.pill-youtube { background: #fdeaea; color: #c4302b; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}
.btn:hover { background: #245ad6; }
/* Disabled but not loading: just dim it. */
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
/* Loading / in-flight: hide the label and show ONLY a centered spinner (htmx sets
   .htmx-request; the global form-submit handler in base.html sets .is-loading).
   Spinner colour defaults to white (works on the accent/grey buttons); light
   buttons set --spinner-color inline so it stays visible. */
.btn.is-loading,
.btn.htmx-request {
  color: transparent !important;
  position: relative;
  pointer-events: none;
  opacity: 0.9;
}
.btn.is-loading::after,
.btn.htmx-request::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1em;
  height: 1em;
  margin: -0.5em 0 0 -0.5em;
  border: 2px solid var(--spinner-color, #fff);
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* --- auth screen ------------------------------------------------------- */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  max-width: 420px;
  text-align: center;
}

.auth-card h1 { margin: 0 0 12px; font-size: 20px; }
.auth-card p { color: var(--muted); margin: 8px 0; }
.auth-card .btn { margin-top: 12px; }

/* --- responsive / mobile ----------------------------------------------- */
@media (max-width: 768px) {
  /* Stack the layout: sidebar becomes a scrollable top nav bar. */
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
  }
  .sidebar .brand { padding: 12px 16px; font-size: 14px; white-space: nowrap; }
  .sidebar nav { flex-direction: row; gap: 0; }
  .sidebar nav a {
    padding: 14px 14px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .sidebar nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--sidebar-active);
  }

  .topbar { height: 50px; padding: 0 16px; }
  .topbar-user .user-email { display: none; }   /* keep the topbar uncluttered */
  .content { padding: 16px; gap: 16px; }
  .card { padding: 14px 16px; }

  /* Wide tables scroll horizontally instead of overflowing the screen. */
  table.data { display: block; overflow-x: auto; white-space: nowrap; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .kpi-value { font-size: 22px; }
}
