/*
 * Belweder Hub stylesheet (doc 09, doc 11).
 * Components use only the tokens below - never raw colors - so light, dark and
 * system themes stay consistent. Theme is selected by <html data-theme>.
 */

/* ---------- Tokens ---------- */

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --surface-3: #e6e9ef;
  --overlay: rgba(20, 22, 30, 0.45);
  --text: #1c2029;
  --text-2: #4b5263;
  --text-3: #7a8193;
  --border: #dde1e8;
  --border-strong: #c5cad5;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eceafd;
  --accent-text: #3f37c9;
  --on-accent: #ffffff;
  --success: #15803d;
  --success-soft: #e3f5e9;
  --warning: #b45309;
  --warning-soft: #fdf1df;
  --danger: #c02633;
  --danger-soft: #fce8ea;
  --info: #0369a1;
  --info-soft: #e1f1fa;
  --focus: rgba(79, 70, 229, 0.45);
  --shadow-1: 0 1px 2px rgba(20, 22, 30, 0.06), 0 1px 3px rgba(20, 22, 30, 0.06);
  --shadow-2: 0 8px 24px rgba(20, 22, 30, 0.12), 0 2px 6px rgba(20, 22, 30, 0.08);
  --skeleton: linear-gradient(90deg, #eceef3 0%, #f6f7fa 50%, #eceef3 100%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --surface: #191c23;
  --surface-2: #20242d;
  --surface-3: #2a2f3a;
  --overlay: rgba(0, 0, 0, 0.6);
  --text: #e7e9ef;
  --text-2: #b4b9c6;
  --text-3: #858b9a;
  --border: #2c313c;
  --border-strong: #3b4150;
  --accent: #8b8cf8;
  --accent-hover: #a3a4fa;
  --accent-soft: #272a4a;
  --accent-text: #aeaffb;
  --on-accent: #11131a;
  --success: #4ade80;
  --success-soft: #16301f;
  --warning: #fbbf24;
  --warning-soft: #33280f;
  --danger: #f87171;
  --danger-soft: #3a1a1d;
  --info: #38bdf8;
  --info-soft: #11293a;
  --focus: rgba(139, 140, 248, 0.55);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  --skeleton: linear-gradient(90deg, #20242d 0%, #2a2f3a 50%, #20242d 100%);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --bg: #111318;
    --surface: #191c23;
    --surface-2: #20242d;
    --surface-3: #2a2f3a;
    --overlay: rgba(0, 0, 0, 0.6);
    --text: #e7e9ef;
    --text-2: #b4b9c6;
    --text-3: #858b9a;
    --border: #2c313c;
    --border-strong: #3b4150;
    --accent: #8b8cf8;
    --accent-hover: #a3a4fa;
    --accent-soft: #272a4a;
    --accent-text: #aeaffb;
    --on-accent: #11131a;
    --success: #4ade80;
    --success-soft: #16301f;
    --warning: #fbbf24;
    --warning-soft: #33280f;
    --danger: #f87171;
    --danger-soft: #3a1a1d;
    --info: #38bdf8;
    --info-soft: #11293a;
    --focus: rgba(139, 140, 248, 0.55);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
    --skeleton: linear-gradient(90deg, #20242d 0%, #2a2f3a 50%, #20242d 100%);
  }
}

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-width: 236px;
  --topbar-height: 56px;
  --tabbar-height: 62px;
  --content-max: 1200px;
  --transition: 140ms ease;
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-sm);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p {
  margin: 0;
}

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

a:hover {
  text-decoration: underline;
}

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

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.noscript {
  max-width: 480px;
  margin: 15vh auto;
  padding: var(--space-5);
  text-align: center;
}

.app-loading::after {
  content: "";
  position: fixed;
  inset: 0;
  margin: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---------- Utilities ---------- */

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: var(--text-xs); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-6); }
.section-gap { margin-top: var(--space-6); }

/* Internal notes: tinted so they never pass for messages to the influencer (doc 08). */
.note-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.note {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
}
.note.is-pinned { box-shadow: inset 3px 0 0 var(--warning); }
.note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-2);
}
.note-meta strong { color: var(--text); }
.note-pin { display: inline-flex; color: var(--warning); }
.note-actions { margin-left: auto; margin-block: -6px; }
.note-body { margin: var(--space-2) 0 0; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- Icons ---------- */

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  vertical-align: -0.25em;
}

.icon-lg { width: 1.6em; height: 1.6em; }
.icon-xl { width: 2.5rem; height: 2.5rem; }
.icon.spin { animation: spin 0.8s linear infinite; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

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

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-icon {
  width: 36px;
  padding: 0;
}

.btn-block { width: 100%; }
.btn-lg { min-height: 44px; font-size: var(--text-md); }

.btn.is-busy {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: var(--text-3);
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
}

.btn-primary.is-busy::after { border-color: var(--on-accent); border-top-color: transparent; }

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

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.label {
  font-weight: 600;
  color: var(--text-2);
  font-size: var(--text-xs);
  text-transform: none;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.textarea { min-height: 96px; resize: vertical; }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--danger);
}

.field-error {
  color: var(--danger);
  font-size: var(--text-xs);
}

.text-pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.field-warning {
  color: var(--warning);
  font-size: var(--text-xs);
}

.help {
  color: var(--text-3);
  font-size: var(--text-xs);
}

.input-group {
  position: relative;
  display: flex;
}

.input-group .input { padding-right: 44px; }

.input-group .btn-icon {
  position: absolute;
  right: 2px;
  top: 2px;
  height: calc(100% - 4px);
  min-height: 0;
  border: 0;
}

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

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* ---------- Cards, badges, misc ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.card-body { padding: var(--space-5); }

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: var(--text-md); font-weight: 650; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 700;
  font-size: var(--text-xs);
  flex: none;
  text-transform: uppercase;
}

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 0;
}

.alert {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--info-soft);
  color: var(--text);
}

.alert .icon { color: var(--info); margin-top: 2px; }
.alert-danger { background: var(--danger-soft); }
.alert-danger .icon { color: var(--danger); }
.alert-success { background: var(--success-soft); }
.alert-success .icon { color: var(--success); }
.alert-warning { background: var(--warning-soft); }
.alert-warning .icon { color: var(--warning); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--text-2);
}

.empty-state .icon-xl { color: var(--text-3); }
.empty-state h2 { color: var(--text); font-size: var(--text-lg); }
.empty-state p { max-width: 460px; }

.skeleton {
  display: block;
  height: 14px;
  border-radius: 4px;
  background: var(--skeleton);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton + .skeleton { margin-top: var(--space-2); }

.kv {
  display: grid;
  grid-template-columns: minmax(120px, max-content) 1fr;
  gap: var(--space-2) var(--space-5);
  margin: 0;
}

.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

/* ---------- View as (admin, plan 08 P7) ---------- */

.view-as-bar {
  position: fixed;
  z-index: 95;
  left: var(--space-4);
  bottom: var(--space-4);
  max-width: calc(100vw - 2 * var(--space-4));
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  box-shadow: var(--shadow-2);
  font-size: var(--text-sm);
  font-weight: 500;
}

.view-as-bar > svg { flex: none; color: var(--warning); }
.view-as-bar .btn { flex: none; }
.is-viewing-as .main { padding-bottom: 160px; }

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

.toast-region {
  position: fixed;
  z-index: 100;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}

.toast {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in 180ms ease-out;
}

.toast .icon { margin-top: 1px; }
.toast-success .icon { color: var(--success); }
.toast-error .icon { color: var(--danger); }
.toast-info .icon { color: var(--info); }
.toast-body { flex: 1; min-width: 0; }
.toast-ref { color: var(--text-3); font-size: var(--text-xs); margin-top: 2px; }
.toast-ref code { user-select: all; }
.toast .btn-icon { width: 28px; min-height: 28px; margin: -4px -8px -4px 0; }

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Toolbars and lists ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.toolbar .input { flex: 1 1 220px; min-width: 0; }
.toolbar .select { flex: 0 1 190px; min-width: 0; }
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 1 150px;
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--text-2);
}
.toolbar .filter-field .input,
.toolbar .filter-field .select { flex: none; width: 100%; }
.match-note { margin: var(--space-3) var(--space-4) 0; }

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

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: 0; }
.list-item.is-muted .list-main { opacity: 0.6; }

.list-main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1 1 auto;
  min-width: 0;
}

.list-text { min-width: 0; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-sub { color: var(--text-3); font-size: var(--text-sm); overflow-wrap: anywhere; }

.list-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  color: var(--text-3);
  font-size: var(--text-sm);
}

.list-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: var(--text-sm);
}

.subnav {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.subnav a {
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
}

.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a[aria-current="page"] { color: var(--accent-text); border-bottom-color: var(--accent); }

.check-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
  cursor: pointer;
}

.check-field input { width: 18px; height: 18px; accent-color: var(--accent); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  align-items: start;
}

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }

.chip span {
  padding: 4px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
}

.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.score { display: inline-flex; gap: 3px; vertical-align: middle; }
.score i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); }
.score i.on { background: var(--accent); }

.sparklines { gap: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.sparkline { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: var(--accent); overflow: visible; }
.sparkline polyline { fill: none; }

.copy-field { display: flex; gap: var(--space-2); }
.copy-field .input { flex: 1; min-width: 0; font-family: var(--font-mono); }

/* Tracked links: short URLs wrap anywhere on phones; click bars are an inline SVG (no style attributes under the CSP). */
.link-url { overflow-wrap: anywhere; }
.click-bars { display: block; width: 100%; max-width: 360px; height: 32px; color: var(--accent); }
.click-bars rect { fill: currentColor; }
.click-bars rect.is-zero { fill: var(--surface-3); }
.result-lines { list-style: none; margin: var(--space-1) 0 0; padding: 0; }
.result-line { display: flex; align-items: center; gap: var(--space-2); color: var(--text-2); font-size: var(--text-sm); }
.result-line > span:first-child { flex: 1 1 auto; min-width: 0; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-3); }
.metric-label { color: var(--text-3); font-size: var(--text-xs); }
.metric-value { color: var(--text); font-size: var(--text-lg); font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-sub { color: var(--text-3); font-size: var(--text-xs); }
.figures { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin-top: var(--space-2); font-size: var(--text-sm); }
.figure-label { color: var(--text-3); }
.figures strong { font-variant-numeric: tabular-nums; }
.card-header > .select { width: auto; flex: 0 1 200px; min-width: 0; }

/* ---------- Pipeline (board, stepper, timeline) ---------- */

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(232px, 1fr);
  gap: var(--space-3);
  align-items: start;
  overflow-x: auto;
  padding-bottom: var(--space-3);
}

.board-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 160px;
  padding: var(--space-2);
  border: 1px dashed transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.board-col.is-target { border-color: var(--border-strong); }
.board-col.is-over { border-color: var(--accent); background: var(--accent-soft); }

.board-col-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
}

.board-cards { display: flex; flex-direction: column; gap: var(--space-2); }

.board-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.board-card[draggable="true"] { cursor: grab; }
.board-card.is-dragging { opacity: 0.5; }
.board-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
.board-card-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.board-card-sub { color: var(--text-3); overflow-wrap: anywhere; }
.move-buttons { display: flex; justify-content: flex-end; gap: 2px; }
.board-card .move-buttons { margin: 0 calc(-1 * var(--space-2)) calc(-1 * var(--space-2)); }
.board-card .move-buttons .btn-icon { width: 32px; min-height: 32px; }

.avatar-sm { width: 24px; height: 24px; font-size: 10px; }

.follow-up {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-2);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.follow-up.is-overdue,
.due.is-overdue { color: var(--danger); font-weight: 600; }

.stepper {
  display: flex;
  margin: 0;
  padding: 0 0 var(--space-1);
  list-style: none;
  overflow-x: auto;
}

.stepper li {
  position: relative;
  flex: 1 0 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-3);
  font-size: var(--text-xs);
  text-align: center;
}

.stepper li::before {
  content: "";
  position: absolute;
  top: 13px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
}

.stepper li:first-child::before { display: none; }
.stepper li.is-done::before, .stepper li.is-current::before, .stepper li.is-stopped::before { background: var(--accent); }

.stepper-dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  font-weight: 700;
}

.stepper-dot .icon { width: 16px; height: 16px; }
.stepper li.is-done .stepper-dot { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.stepper li.is-current { color: var(--text); font-weight: 600; }
.stepper li.is-current .stepper-dot { border-color: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 4px var(--accent-soft); }
.stepper li.is-stopped .stepper-dot { border-color: var(--danger); color: var(--danger); }

.checklist { display: flex; flex-direction: column; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.checklist li { display: flex; align-items: center; gap: var(--space-2); }
.checklist li .icon { color: var(--danger); }
.checklist li.is-met .icon { color: var(--success); }

.timeline { display: flex; flex-direction: column; gap: var(--space-4); margin: 0; list-style: none; }
.timeline-item { display: flex; gap: var(--space-3); }

.timeline-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
}

.timeline-icon .icon { width: 16px; height: 16px; }
.timeline-item[data-event-type="guard_override"] .timeline-icon { background: var(--warning-soft); color: var(--warning); }
.timeline-item[data-event-type="outreach"] .timeline-icon { background: var(--accent-soft); color: var(--accent-text); }
.offer-list { display: flex; flex-direction: column; gap: var(--space-3); margin: 0; list-style: none; }

.offer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.offer.is-accepted { border-color: var(--success); box-shadow: inset 3px 0 0 var(--success); }
.offer.is-old { padding-block: var(--space-2); border-style: dashed; color: var(--text-2); }
.offer-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.offer-head .badge { margin-left: auto; }
.offer-terms { font-weight: 600; }
.offer.is-old .offer-terms { font-weight: 400; }
.offer-plan { margin: 0; padding-left: var(--space-5); }
.offer-text { overflow-wrap: anywhere; }

.plan-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 80px minmax(0, 1.2fr) 36px;
  gap: var(--space-2);
  align-items: start;
}

.plan-row > .btn-icon { margin-top: 22px; }

/* Feedback on a draft (portal pieces, staff review). */
.callout {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.callout-warning { background: var(--warning-soft); border-color: transparent; box-shadow: inset 3px 0 0 var(--warning); }
.callout.is-pending { box-shadow: inset 3px 0 0 var(--accent); }
.callout p { margin: var(--space-1) 0 0; }

/* Draft history of a piece. */
.proof-history { margin-top: var(--space-2); font-size: var(--text-sm); }
.proof-history summary { cursor: pointer; color: var(--text-2); }
.proof-history ul { margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.proof-history li { padding: var(--space-2) 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.proof-history p { margin: var(--space-1) 0 0; }

/* Report import preview. */
.import-columns summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.import-columns .form-grid { margin-top: var(--space-3); }
.import-assign { margin-top: var(--space-2); max-width: 28rem; }

/* Portal counter-offer: one count input per planned format. */
.plan-count { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: var(--space-3); align-items: center; }

/* ---------- Message threads ---------- */

.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-scroll { overflow-y: auto; max-height: min(64vh, 640px); padding: var(--space-4); overscroll-behavior: contain; }
.thread.is-compact .thread-scroll { max-height: 360px; }
.thread-more { display: flex; justify-content: center; margin-bottom: var(--space-3); }
.thread-empty { margin: 0; text-align: center; padding: var(--space-4) 0; }
.msg-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.msg {
  align-self: flex-start;
  max-width: min(85%, 560px);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-wrap: anywhere;
}
.msg.is-mine { align-self: flex-end; background: var(--accent-soft); }
.msg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--space-2); color: var(--text-3); font-size: var(--text-xs); }
.msg-author { font-weight: 650; color: var(--text-2); }
.msg-tag { display: inline-flex; align-items: center; gap: 2px; }
.msg-tag .icon { width: 12px; height: 12px; }
.msg-body { margin-top: 2px; white-space: pre-wrap; }
.msg-files { margin: var(--space-2) 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-1); }
.msg-file a, .composer-file { display: flex; align-items: center; gap: var(--space-2); min-width: 0; font-size: var(--text-sm); }
.msg-file img { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); flex: none; }
.msg-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer { border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4); }
.composer-row { display: flex; align-items: flex-end; gap: var(--space-2); }
.composer-input { flex: 1 1 auto; min-width: 0; resize: vertical; min-height: 44px; }
.composer-files { margin: 0 0 var(--space-2); padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-1); }
.composer-file progress { width: 80px; flex: none; }
.composer .field-error { margin-top: var(--space-2); }
.thread-about { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); background: var(--accent-soft); color: var(--accent-text); font-size: var(--text-sm); }
.thread-about .btn { margin-left: auto; }

.inbox-snippet { overflow-wrap: anywhere; }
.thread-help { padding-bottom: 0; font-size: var(--text-sm); }
.list-item.is-unread .list-title { font-weight: 700; }

.notify-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-3);
}
.notify-item.is-unread .notify-icon { background: var(--accent-soft); color: var(--accent-text); }
.notify-item .list-title { white-space: normal; }
.notify-item:not(.is-unread) .list-title a { color: var(--text-2); font-weight: 500; }
.list-more { display: flex; justify-content: center; padding-top: var(--space-3); }

.share-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 280px;
  overflow-y: auto;
}
.share-option .muted { font-size: var(--text-sm); font-weight: 400; }
.share-results { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.share-results:empty { display: none; }

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.nav-badge[hidden] { display: none; }

@media (max-width: 639px) {
  .plan-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 36px;
  gap: var(--space-2);
  align-items: start;
}

.item-row > .btn-icon { margin-top: 22px; }

.cost-amount { color: var(--text); font-weight: 600; white-space: nowrap; }

.cost-total {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--text);
}

.list-action { margin-top: var(--space-2); }
.list-item[data-shipment] .list-meta,
.list-item[data-file] .list-meta { flex-wrap: nowrap; }

.timeline-body { min-width: 0; }
.timeline-meta { color: var(--text-3); font-size: var(--text-xs); }
.timeline-detail { margin-top: var(--space-1); color: var(--text-2); }

/* ---------- Dialogs and menus ---------- */

dialog.modal {
  width: min(520px, calc(100vw - 2 * var(--space-4)));
  max-height: calc(100vh - 2 * var(--space-6));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}

dialog.modal.modal-wide { width: min(760px, calc(100vw - 2 * var(--space-4))); }

dialog.modal::backdrop {
  background: var(--overlay);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.modal-body { padding: var(--space-5); overflow: auto; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}

.menu {
  position: fixed;
  z-index: 90;
  min-width: 220px;
  max-width: calc(100vw - 2 * var(--space-4));
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.menu-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  color: var(--text-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); text-decoration: none; outline: none; }
.menu-item .icon { color: var(--text-2); }
.menu-item .check { margin-left: auto; color: var(--accent); }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }

/* ---------- App frame (staff) ---------- */

.frame {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100vh;
}

.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: calc(var(--topbar-height) - var(--space-3));
  padding: 0 var(--space-2) var(--space-3);
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--text);
}

.brand img { width: 28px; height: 28px; }
.brand:hover { text-decoration: none; }

.nav-section {
  margin-top: var(--space-4);
  padding: 0 var(--space-3) var(--space-1);
  color: var(--text-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 38px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 550;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.nav-item .icon { width: 20px; height: 20px; }

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 650;
  font-size: var(--text-md);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .menu-toggle { display: none; }

.topbar-bell { position: relative; flex: none; }
.topbar-bell[aria-current="page"] { color: var(--accent); }
.topbar-bell .nav-badge { position: absolute; top: 2px; right: 0; margin: 0; padding: 0 5px; min-width: 18px; line-height: 18px; font-size: 10px; }

.user-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 8px 4px 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  color: var(--text);
}

.user-button:hover { background: var(--surface-2); }
.user-button .user-name { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  grid-area: main;
  min-width: 0;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

.view {
  max-width: var(--content-max);
  margin: 0 auto;
}

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

.page-header p { color: var(--text-2); margin-top: var(--space-1); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: var(--overlay);
}

/* ---------- Portal frame (influencers) ---------- */

.portal {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.portal .topbar {
  position: sticky;
  padding: 0 var(--space-4);
  height: var(--topbar-height);
}

.portal-nav {
  display: flex;
  gap: var(--space-1);
  margin-left: var(--space-4);
}

.portal-nav .nav-item { min-height: 36px; }

.portal .main {
  flex: 1;
  padding: var(--space-5) var(--space-4) calc(var(--tabbar-height) + var(--space-6));
}

.portal .view { max-width: 920px; }

.tabbar {
  display: none;
  position: fixed;
  z-index: 25;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  min-width: 0;
}

.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tabbar a .icon { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent-text); }
.tabbar a:hover { text-decoration: none; }
.tabbar a { position: relative; }
.tabbar a .nav-badge { position: absolute; top: 4px; left: calc(50% + 6px); margin: 0; padding: 0 5px; min-width: 18px; line-height: 18px; font-size: 10px; }

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

.auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.auth-top {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.auth-main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh var(--space-4) var(--space-7);
}

.auth-card {
  width: min(420px, 100%);
}

.auth-card .card-body { padding: var(--space-6); }

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  text-align: center;
}

.auth-brand img { width: 48px; height: 48px; }
.auth-brand p { color: var(--text-2); }

/* ---------- Dashboard ---------- */

.stage-counts { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; list-style: none; }

.stage-counts li {
  display: grid;
  grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) 2.5rem;
  gap: var(--space-3);
  align-items: center;
  font-size: var(--text-sm);
}

.list-icon { flex: none; color: var(--text-3); }

/* Admin repair console. */
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.repair-json { min-height: 360px; font-family: var(--font-mono); font-size: var(--text-xs); white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.repair-targets { margin-top: var(--space-2); font-size: var(--text-sm); }
.repair-change { color: var(--text-2); font-size: var(--text-xs); overflow-wrap: anywhere; }
.repair-action + .repair-action, [data-form=run-job] { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.repair-action-title { margin: 0; font-size: var(--text-md); }
.repair-result { margin: 0; padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--text-xs); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Admin log viewer. */
.log-line .list-text { min-width: 0; }
.log-sub { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); }
.log-details { margin-top: var(--space-1); font-size: var(--text-sm); }
.log-details summary { cursor: pointer; color: var(--text-2); }
.log-json { margin: var(--space-2) 0 0; padding: var(--space-3); max-height: 480px; overflow: auto; border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--font-mono); font-size: var(--text-xs); white-space: pre-wrap; overflow-wrap: anywhere; }
.list-item[data-upload] .list-text { flex: 1 1 auto; }
.file-preview { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; }

.stage-count { text-align: right; }

.stage-bar {
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  appearance: none;
  overflow: hidden;
}

.stage-bar::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.stage-bar::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.stage-bar::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.tile {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

a.tile:hover {
  text-decoration: none;
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}

.tile .tile-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-text);
  flex: none;
}

.tile h3 { font-size: var(--text-sm); }
.tile p { color: var(--text-2); font-size: var(--text-xs); margin-top: 2px; }

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

@media (max-width: 1023px) {
  .frame {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "topbar" "main";
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    left: 0;
    top: 0;
    width: min(var(--sidebar-width), 85vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }

  .frame.nav-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-2);
    transition: transform 180ms ease;
  }
  .topbar .menu-toggle { display: inline-flex; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .main { padding: var(--space-5) var(--space-4) var(--space-7); }
}

@media (max-width: 639px) {
  h1 { font-size: var(--text-xl); }
  .user-button .user-name { display: none; }
  .portal-nav { display: none; }
  .tabbar { display: flex; }
  .portal .view-as-bar { bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-2)); }
  .card-body { padding: var(--space-4); }
  .auth-card .card-body { padding: var(--space-5); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: var(--space-2); }
  .form-actions .btn { flex: 1; }
  .segmented { display: flex; }
  .segmented button { flex: 1 1 auto; justify-content: center; }
  .toolbar .select { flex: 1 1 140px; }
  .filter-field { flex: 1 1 130px; }
  .list-item { flex-wrap: wrap; align-items: flex-start; }
  .list-main { flex-basis: calc(100% - 48px); }
  .list-meta { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .list-item:has(.avatar) .list-meta { padding-left: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
