/* Change Lives HQ. Warm near-black console for staff and creators.
   Palette from the existing site: #0C0805 base, #F4EDE0 cream text,
   #E9B640 gold for actions and active states, #E5382B vermilion for
   errors only. Bricolage Grotesque carries headings and the wordmark,
   Instrument Sans carries everything else. Radius 10px controls,
   14px surfaces, spacing on a 4/8px rhythm. */

:root {
  --base: #0C0805;
  --surface: #151009;
  --surface-2: #1D160D;
  --line: #453922;
  --line-soft: #342A19;
  --cream: #F4EDE0;
  --cream-dim: #CBBB93;
  --cream-faint: #A89877;
  --gold: #E9B640;
  --gold-soft: #F5DFA9;
  --gold-deep: #B47E1C;
  --vermilion: #E5382B;
  --vermilion-soft: #FF7A5E;
  --focus: #F0D68A;

  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Instrument Sans', sans-serif;

  --radius-control: 10px;
  --radius-surface: 14px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--base);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-width: 320px;
  min-height: 100vh;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

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

/* ------------------------------------------------------------ boot */
.boot-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.boot-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  padding: var(--sp-6);
}

.boot-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin: var(--sp-2) 0 var(--sp-3);
  color: var(--gold-soft);
}

.boot-note { color: var(--cream-dim); margin: 0 0 var(--sp-4); }

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.04em;
  color: var(--gold-soft);
  margin: 0;
}
.wordmark b { color: var(--vermilion); }

.login-card { max-width: 400px; }
.login-sub { color: var(--cream-dim); margin: 0 0 var(--sp-4); }

/* ------------------------------------------------------------ forms */
.field { margin-bottom: var(--sp-4); }

.field label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--gold-soft);
  margin-bottom: var(--sp-1);
}

.field input,
.field select,
.field textarea,
.control {
  width: 100%;
  background: var(--base);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 9px 12px;
  transition: border-color 160ms var(--ease-out);
}

.field input:hover, .field select:hover, .field textarea:hover, .control:hover {
  border-color: var(--gold-deep);
}

.field input:focus-visible, .field select:focus-visible,
.field textarea:focus-visible, .control:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--gold);
}

.field input[aria-invalid="true"], .field textarea[aria-invalid="true"],
.field select[aria-invalid="true"] {
  border-color: var(--vermilion);
}

.field-hint { font-size: 12px; color: var(--cream-faint); margin: var(--sp-1) 0 0; }

.field-error {
  color: var(--vermilion-soft);
  font-size: 13px;
  font-weight: 500;
  margin: var(--sp-1) 0 0;
}

.form-error {
  background: rgba(229, 56, 43, 0.12);
  border: 1px solid rgba(229, 56, 43, 0.5);
  border-radius: var(--radius-control);
  color: #FFD9CF;
  padding: var(--sp-2) var(--sp-3);
  font-size: 14px;
  margin: 0 0 var(--sp-4);
}

.form-notice {
  background: rgba(233, 182, 64, 0.1);
  border: 1px solid rgba(233, 182, 64, 0.4);
  border-radius: var(--radius-control);
  color: var(--gold-soft);
  padding: var(--sp-2) var(--sp-3);
  font-size: 14px;
  margin: 0 0 var(--sp-4);
}

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), border-color 160ms var(--ease-out),
    background-color 160ms var(--ease-out), color 160ms var(--ease-out);
  min-height: 44px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gold);
  color: #221a06;
}
.btn-primary:hover { background: var(--gold-soft); }

.btn-ghost {
  background: transparent;
  color: var(--gold-soft);
  border-color: var(--line);
}
.btn-ghost:hover { border-color: var(--gold-deep); color: var(--gold-soft); }

.btn-small { padding: 5px 12px; min-height: 36px; font-size: 13px; }
.btn-wide { width: 100%; }

.btn[disabled], .btn[data-busy] {
  opacity: 0.55;
  cursor: progress;
  transform: none;
}

.btn-close { min-height: 36px; padding: 5px 12px; }

/* ------------------------------------------------------------ chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--cream-dim);
  white-space: nowrap;
}

.chip-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cream-faint);
  flex: none;
}

.chip-gold { border-color: rgba(233, 182, 64, 0.55); color: var(--gold-soft); }
.chip-gold .chip-dot { background: var(--gold); }

.chip-gold-outline { border-color: rgba(233, 182, 64, 0.35); color: var(--gold-soft); }
.chip-gold-outline .chip-dot { background: transparent; border: 1px solid var(--gold); width: 4px; height: 4px; }

.chip-vermilion-outline { border-color: rgba(229, 56, 43, 0.55); color: #FFD9CF; }
.chip-vermilion-outline .chip-dot { background: var(--vermilion); }

.chip-neutral .chip-dot { background: var(--cream-faint); }

/* ------------------------------------------------------------ shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand { display: flex; align-items: baseline; gap: var(--sp-3); }
.topbar-sub {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--cream-faint);
}

.topbar-user { display: flex; align-items: center; gap: var(--sp-3); }

.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.user-chip strong { font-size: 13px; color: var(--gold-soft); }
.user-role {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cream-faint);
}

.shell {
  display: flex;
  align-items: flex-start;
  max-width: 1240px;
  margin: 0 auto;
}

.sidebar {
  width: 200px;
  flex: none;
  padding: var(--sp-5) 0 var(--sp-7) var(--sp-5);
  position: sticky;
  top: 61px;
  border-right: 1px solid var(--line-soft);
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }

.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  color: var(--cream-dim);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  transition: color 160ms var(--ease-out), border-color 160ms var(--ease-out),
    background-color 160ms var(--ease-out);
}

.nav-link:hover { color: var(--cream); }
.nav-link.nav-active {
  color: var(--gold-soft);
  border-left-color: var(--gold);
  background: rgba(233, 182, 64, 0.06);
}

.content {
  flex: 1;
  min-width: 0;
  padding: var(--sp-5) var(--sp-5) var(--sp-7);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.section-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  margin: 0;
  color: var(--gold-soft);
}

.section-sub { color: var(--cream-dim); margin: var(--sp-1) 0 0; max-width: 60ch; }

.section-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------ states */
.state-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  padding: var(--sp-5);
  max-width: 560px;
}

.state-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--gold-soft);
  margin: 0 0 var(--sp-2);
}

.state-body { color: var(--cream-dim); margin: 0 0 var(--sp-3); }
.state-body:last-child { margin-bottom: 0; }
.state-dim { color: var(--cream-faint); font-size: 13px; }

.state-card .btn { margin-top: var(--sp-2); }
.state-card .btn:last-child { margin-bottom: 0; }

.state-empty .state-title { color: var(--cream); }

.loadbar {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: var(--sp-3);
}

.loadbar-fill {
  height: 100%;
  width: 40%;
  border-radius: 2px;
  background: var(--gold);
  animation: loadbar 1.1s var(--ease-out) infinite;
}

@keyframes loadbar {
  from { transform: translateX(-100%); }
  to { transform: translateX(280%); }
}

/* ------------------------------------------------------------ tables */
.table-wrap {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  overflow-x: auto;
  background: var(--surface);
}

.table-count { margin: 0 0 var(--sp-3); }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cream-faint);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table strong { color: var(--gold-soft); font-weight: 600; }

.cell-sub { display: block; font-size: 12px; color: var(--cream-faint); }

.status-cell { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

.data-table a { color: var(--gold); text-decoration: underline; text-underline-offset: 2px; }
.data-table a:hover { color: var(--gold-soft); }

.data-table select { width: auto; min-width: 130px; }

.mono {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--cream-dim);
}

/* ------------------------------------------------------------ cards */
.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-4);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  padding: var(--sp-4);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-1);
}

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--gold-soft);
}

.card-meta { font-size: 12px; color: var(--cream-faint); margin: 0 0 var(--sp-2); }

.card-body { margin: 0; color: var(--cream-dim); white-space: pre-line; }

.card-actions { margin-top: var(--sp-3); }

.msg-details { margin-top: var(--sp-2); }
.msg-details summary {
  cursor: pointer;
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
}
.msg-details summary:hover { color: var(--gold-soft); }
.msg-details[open] summary { margin-bottom: var(--sp-2); }

/* ------------------------------------------------------------ overview */
.count-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
  margin: 0 0 var(--sp-4);
}

.count-cell {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  padding: var(--sp-3) var(--sp-4);
}

.count-cell dt {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cream-faint);
}

.count-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  margin: var(--sp-1) 0 0;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-surface);
  padding: var(--sp-4);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 var(--sp-2);
  color: var(--gold-soft);
}

.panel .state-body { margin-bottom: var(--sp-1); }

/* creator profile (creator.js reuses the count-cell grid) */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3);
  margin: 0 0 var(--sp-4);
}

.profile-value { font-size: 15px; margin: var(--sp-1) 0 0; color: var(--cream); overflow-wrap: anywhere; }

/* ------------------------------------------------------------ dialogs */
.dlg {
  background: var(--surface);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius-surface);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.dlg::backdrop {
  background: rgba(6, 4, 2, 0.72);
}

@starting-style {
  .dlg[open] { opacity: 0; transform: translateY(8px) scale(0.97); }
}

.dlg[open] {
  opacity: 1;
  transform: none;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out),
    overlay 200ms allow-discrete, display 200ms allow-discrete;
}

.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5) 0;
}

.dlg-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--gold-soft);
}

.dlg-intro { color: var(--cream-dim); font-size: 14px; margin: var(--sp-2) var(--sp-5) 0; }

.dlg form { padding: var(--sp-4) var(--sp-5) var(--sp-5); }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

/* ------------------------------------------------------------ mobile */
@media (max-width: 767px) {
  .topbar { padding: var(--sp-3) var(--sp-4); }
  .user-chip strong { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .shell { flex-direction: column; }

  .sidebar {
    position: static;
    width: 100%;
    padding: var(--sp-3) var(--sp-4) 0;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .sidebar ul {
    display: flex;
    overflow-x: auto;
    gap: var(--sp-1);
    padding-bottom: var(--sp-2);
    border-bottom: 0;
    /* right-edge fade hints that the tab bar scrolls */
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
  }

  .nav-link {
    white-space: nowrap;
    border-left: 0;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-control) var(--radius-control) 0 0;
    padding: 10px 12px;
  }

  .nav-link.nav-active {
    border-left: 0;
    border-bottom-color: var(--gold);
    background: none;
  }

  .content { padding: var(--sp-4); }

  .section-head { align-items: flex-start; flex-direction: column; }
  .section-actions { width: 100%; }

  /* stacked tables: each row becomes a labelled card */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; }
  .data-table tr {
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-surface);
    padding: var(--sp-3);
    margin-bottom: var(--sp-3);
    background: var(--surface);
  }
  .data-table td { border: 0; padding: var(--sp-1) 0; }
  .data-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cream-faint);
  }
  .data-table td[data-label="Status"]::before { margin-bottom: var(--sp-1); }
  .data-table select { width: 100%; margin-top: var(--sp-1); }
}

@media (max-width: 389px) {
  .topbar { flex-wrap: wrap; }
  .boot-card { padding: var(--sp-5); }
  .count-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1440px) {
  .shell { max-width: 1320px; }
  .content { padding: var(--sp-6) var(--sp-6) var(--sp-7); }
}

/* ------------------------------------------------------------ motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .loadbar-fill { animation: none; width: 100%; opacity: 0.4; }
}
