/* ==========================================================================
   Citizen Pipeline design system (cpl.css)
   Ported from the ProjectOS system (cpos.css) — same tokens, spacing, and
   components; the module accent is TEAL (ProjectOS is indigo). The accent
   changes in ONE place: --accent* custom properties below.
   ========================================================================== */

:root {
  color-scheme: light;

  --font-sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-serif: 'Instrument Serif', Georgia, serif;

  /* Surfaces & text */
  --bg:        oklch(0.975 0.004 190);
  --surface:   oklch(1 0 0);
  --surface-2: oklch(0.955 0.006 190);
  --border:    oklch(0.90 0.008 190);
  --text:      oklch(0.24 0.015 220);
  --text-muted: oklch(0.52 0.015 220);

  /* Module accent — teal (the ONE thing that differs from ProjectOS) */
  --accent:        oklch(0.62 0.115 190);
  --accent-strong: oklch(0.50 0.11 190);
  --accent-soft:   oklch(0.93 0.035 190);
  --accent-text:   oklch(0.99 0.005 190);

  /* Status family */
  --c-teal:  oklch(0.62 0.115 190);
  --c-sky:   oklch(0.62 0.13 240);
  --c-amber: oklch(0.72 0.14 80);
  --c-green: oklch(0.62 0.15 150);
  --c-gray:  oklch(0.58 0.01 220);
  --c-red:   oklch(0.58 0.19 25);

  --c-teal-soft:  oklch(0.93 0.035 190);
  --c-sky-soft:   oklch(0.93 0.035 240);
  --c-amber-soft: oklch(0.95 0.045 85);
  --c-green-soft: oklch(0.94 0.045 150);
  --c-gray-soft:  oklch(0.94 0.005 220);
  --c-red-soft:   oklch(0.94 0.035 25);

  /* Radii, shadows, spacing */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px oklch(0.2 0.02 220 / 0.06);
  --shadow:    0 1px 3px oklch(0.2 0.02 220 / 0.08), 0 4px 16px oklch(0.2 0.02 220 / 0.05);
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;

  --sidebar-w: 240px;
}

[data-theme='dark'] {
  color-scheme: dark;

  --bg:        oklch(0.18 0.012 220);
  --surface:   oklch(0.225 0.012 220);
  --surface-2: oklch(0.265 0.012 220);
  --border:    oklch(0.32 0.012 220);
  --text:      oklch(0.93 0.005 190);
  --text-muted: oklch(0.66 0.01 210);

  --accent:        oklch(0.75 0.11 190);
  --accent-strong: oklch(0.82 0.10 190);
  --accent-soft:   oklch(0.32 0.045 195);
  --accent-text:   oklch(0.16 0.02 210);

  --c-teal:  oklch(0.75 0.11 190);
  --c-sky:   oklch(0.74 0.11 240);
  --c-amber: oklch(0.80 0.13 85);
  --c-green: oklch(0.74 0.13 150);
  --c-gray:  oklch(0.68 0.01 220);
  --c-red:   oklch(0.70 0.16 25);

  --c-teal-soft:  oklch(0.30 0.04 195);
  --c-sky-soft:   oklch(0.30 0.04 245);
  --c-amber-soft: oklch(0.31 0.05 85);
  --c-green-soft: oklch(0.30 0.05 150);
  --c-gray-soft:  oklch(0.29 0.01 220);
  --c-red-soft:   oklch(0.30 0.05 25);

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow:    0 1px 3px oklch(0 0 0 / 0.35), 0 4px 16px oklch(0 0 0 / 0.25);
}

/* Base ------------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }

em {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
}

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

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

.only-dark { display: none; }
[data-theme='dark'] .only-dark { display: inline-flex; }
[data-theme='dark'] .only-light { display: none; }

.icon { flex: none; vertical-align: -3px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Shell / sidebar -------------------------------------------------------- */

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

.sidebar {
  position: sticky; top: 0;
  width: var(--sidebar-w); height: 100vh;
  flex: none;
  display: flex; flex-direction: column;
  padding: var(--space-5) var(--space-4);
  border-right: 1px solid var(--border);
  background: var(--surface);
  gap: var(--space-5);
}

.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--text);
  font-size: 16px; font-weight: 600;
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__brand em { font-size: 17px; }

.sidebar__logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
}

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

.sidebar__link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}
.sidebar__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar__link.is-active { background: var(--accent-soft); color: var(--accent-strong); }

.sidebar__section { margin-top: auto; }
.sidebar__section-label {
  padding: 0 var(--space-3) var(--space-2);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar__link--external span:first-of-type { flex: 1; }

.sidebar__footer {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.sidebar__theme {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 8px var(--space-3);
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  font: inherit; font-weight: 500;
  cursor: pointer; text-align: left;
}
.sidebar__theme:hover { background: var(--surface-2); color: var(--text); }

.sidebar__user { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); }
.sidebar__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: 12px; font-weight: 600;
}
.sidebar__username { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sidebar__logout { display: inline-flex; color: var(--text-muted); }
.sidebar__logout:hover { color: var(--c-red); }

.main {
  flex: 1; min-width: 0;
  padding: var(--space-8);
  display: flex; flex-direction: column; gap: var(--space-5);
  max-width: 1200px;
}

/* Page head -------------------------------------------------------------- */

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4);
}
.page-head__title { font-size: 24px; letter-spacing: -0.01em; }
.page-head__sub { margin: var(--space-1) 0 0; color: var(--text-muted); }
.page-head__actions { display: flex; gap: var(--space-2); }

.crumb {
  display: inline-flex; align-items: center; gap: 2px;
  margin-bottom: var(--space-2);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
}
.crumb:hover { color: var(--accent-strong); text-decoration: none; }

/* Cards ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}
.card--narrow { max-width: 560px; }

.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-3);
}
.card__head .card__title { margin-bottom: 0; }
.card__title { font-size: 15px; margin-bottom: var(--space-3); }
.card__subtitle { font-size: 13px; margin: var(--space-4) 0 var(--space-2); color: var(--text-muted); }

.grid-2 {
  display: grid; gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

/* Stats ------------------------------------------------------------------ */

.stat-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat__label {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: 12px; font-weight: 500; color: var(--text-muted);
}
.stat__value {
  font-size: 28px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Dots & pills ----------------------------------------------------------- */

.dot {
  display: inline-block; width: 8px; height: 8px; flex: none;
  border-radius: 50%; background: var(--c-gray);
}
.dot--teal  { background: var(--c-teal); }
.dot--sky   { background: var(--c-sky); }
.dot--amber { background: var(--c-amber); }
.dot--green { background: var(--c-green); }
.dot--gray  { background: var(--c-gray); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.pill--teal  { background: var(--c-teal-soft); }
.pill--sky   { background: var(--c-sky-soft); }
.pill--amber { background: var(--c-amber-soft); }
.pill--green { background: var(--c-green-soft); }
.pill--gray  { background: var(--c-gray-soft); }

/* Buttons ---------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit; font-weight: 500; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { text-decoration: none; }

.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-strong); }

.btn--ghost {
  background: transparent; color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--surface-2); }
.btn--ghost.is-on { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }

.btn--danger { background: var(--c-red-soft); color: var(--c-red); }
.btn--danger:hover { filter: brightness(0.97); }

.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--block { width: 100%; }
.btn--icon { padding: 8px; }
.btn--icon.is-on { color: var(--c-amber); }

/* Forms ------------------------------------------------------------------ */

.stack { display: flex; flex-direction: column; gap: var(--space-4); }

.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field__label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.field__hint { font-size: 12px; color: var(--text-muted); }
.field--check {
  flex-direction: row; align-items: center; gap: var(--space-2);
  font-weight: 500; cursor: pointer;
}
.field--grow { flex: 1; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; }

.input-wrap { position: relative; display: block; }
.input-wrap .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.input--iconed { padding-left: 32px; }

.form-actions { display: flex; gap: var(--space-2); }

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  gap: var(--space-3);
}
.filters .btn { margin-left: auto; }

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.alert--error { background: var(--c-red-soft); color: var(--c-red); }

/* Toasts ----------------------------------------------------------------- */

.toast {
  position: fixed; top: var(--space-5); right: var(--space-5); z-index: 50;
  max-width: 360px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg);
  font-weight: 500; font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease;
}
.toast--error { background: var(--c-red); color: oklch(0.98 0.01 25); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* Tables ----------------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table--clickable tbody tr { cursor: pointer; }
.table--clickable tbody tr:hover { background: var(--surface-2); }
.table tr.is-spam { opacity: 0.55; }

.lead-name { display: flex; align-items: center; gap: var(--space-2); font-weight: 500; }
.lead-name + .muted { display: block; font-size: 12.5px; }
.star-inline { color: var(--c-amber); display: inline-flex; }

.pager {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-4);
  padding-top: var(--space-4);
}
.pager__info { font-size: 12.5px; color: var(--text-muted); }

/* Key/value lists -------------------------------------------------------- */

.kv { margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.kv > div { display: flex; gap: var(--space-3); align-items: baseline; }
.kv dt {
  flex: none; width: 130px;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted);
}
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.mono--wrap { overflow-wrap: anywhere; word-break: break-word; }

.message-body {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* Status changer --------------------------------------------------------- */

.status-changer { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.status-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit; font-weight: 500; font-size: 13px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.status-btn:hover { background: var(--surface-2); color: var(--text); }
.status-btn.is-current { border-color: transparent; color: var(--text); font-weight: 600; }
.status-btn--teal.is-current  { background: var(--c-teal-soft); }
.status-btn--sky.is-current   { background: var(--c-sky-soft); }
.status-btn--amber.is-current { background: var(--c-amber-soft); }
.status-btn--green.is-current { background: var(--c-green-soft); }
.status-btn--gray.is-current  { background: var(--c-gray-soft); }

/* Status list (dashboard) ------------------------------------------------ */

.status-list { display: flex; flex-direction: column; }
.status-list__row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.status-list__row:hover { background: var(--surface-2); text-decoration: none; }
.status-list__name { flex: 1; font-weight: 500; }
.status-list__count { font-variant-numeric: tabular-nums; color: var(--text-muted); }

/* Bar chart -------------------------------------------------------------- */

.bars { display: flex; flex-direction: column; gap: var(--space-2); }
.bars__row { display: flex; align-items: center; gap: var(--space-3); }
.bars__label {
  flex: none; width: 110px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; font-weight: 500;
}
.bars__track {
  flex: 1; height: 10px;
  background: var(--surface-2);
  border-radius: 999px; overflow: hidden;
}
.bars__fill {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 3px;
}
.bars__value {
  flex: none; width: 32px; text-align: right;
  font-size: 12.5px; font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Notes & timeline ------------------------------------------------------- */

.note-form { margin-bottom: var(--space-4); }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.note {
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.note p { margin: 0 0 var(--space-1); }
.note .muted { font-size: 12px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline__item {
  position: relative;
  display: flex; align-items: baseline; gap: var(--space-3);
  padding: var(--space-2) 0 var(--space-2) var(--space-5);
}
.timeline__item::before {
  content: '';
  position: absolute; left: 5px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline__item:first-child::before { top: 50%; }
.timeline__item:last-child::before { bottom: 50%; }
.timeline__dot {
  position: absolute; left: 1px; top: 50%; transform: translateY(-50%);
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}
.timeline__label { flex: 1; font-weight: 500; }
.timeline__time { font-size: 12px; }

/* Sites ------------------------------------------------------------------ */

.site-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.site-card { display: flex; flex-direction: column; gap: var(--space-2); }
.site-card.is-inactive { opacity: 0.6; }
.site-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.site-card__name { font-size: 15px; font-weight: 600; color: var(--text); }
.site-card__name:hover { color: var(--accent-strong); text-decoration: none; }
.site-card__domain { font-size: 12.5px; display: inline-flex; align-items: center; gap: 4px; }
.site-card__meta { display: flex; gap: var(--space-2); }
.site-card__stats {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: auto; padding-top: var(--space-2);
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}

/* Switch ----------------------------------------------------------------- */

.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track {
  width: 34px; height: 20px;
  border-radius: 999px;
  background: var(--c-gray-soft);
  transition: background 0.15s ease;
  position: relative;
}
.switch__track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }

/* Token & code ----------------------------------------------------------- */

.token-row {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-3) 0 var(--space-4);
}
.token-value {
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  user-select: all;
}

.code-block {
  margin: 0;
  padding: var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px; line-height: 1.6;
  white-space: pre;
}
.code-block code { font-size: inherit; }

/* Empty states ----------------------------------------------------------- */

.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}
.empty .icon { color: var(--text-muted); opacity: 0.7; }
.empty p { margin: 0; max-width: 380px; }
.empty--sm { padding: var(--space-5) var(--space-4); }

/* Auth pages ------------------------------------------------------------- */

.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  padding: var(--space-5);
}
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: var(--space-5); }
.auth-card__brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.auth-card__logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
}
.auth-card__brand h1 { font-size: 22px; }
.auth-card__brand em { font-size: 24px; }
.auth-card__tag { margin: 0; color: var(--text-muted); }

/* Responsive ------------------------------------------------------------- */

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%; height: auto;
    flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: var(--space-3);
    border-right: none; border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
  }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__section { margin-top: 0; }
  .sidebar__section-label { display: none; }
  .sidebar__footer {
    flex-direction: row; align-items: center;
    border-top: none; padding-top: 0;
    margin-left: auto;
  }
  .sidebar__theme span:last-child { display: none; }
  .sidebar__username { display: none; }
  .main { padding: var(--space-4); }
  .page-head { flex-direction: column; align-items: flex-start; }
  .kv dt { width: 105px; }
}
