/* Affiliate Content Ops — Design System Tokens & Components */

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;

  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,.06);

  --sidebar-w: 240px;
  --sidebar-collapsed: 56px;
  --topbar-h: 48px;

  --transition: 150ms ease;
}

[data-theme="light"] {
  --bg-base: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-sunken: #eceef2;
  --bg-hover: #f0f2f5;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: rgba(37, 99, 235, 0.08);
  --success: #15803d;
  --success-bg: rgba(21, 128, 61, 0.1);
  --warning: #b45309;
  --warning-bg: rgba(180, 83, 9, 0.1);
  --danger: #b91c1c;
  --danger-bg: rgba(185, 28, 28, 0.1);
  --info: #0369a1;
  --info-bg: rgba(3, 105, 161, 0.1);
  --focus-ring: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
}

[data-theme="dark"] {
  --bg-base: #0c0e12;
  --bg-elevated: #141820;
  --bg-sunken: #0a0c10;
  --bg-hover: #1a1f2a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text-primary: #e8ecf1;
  --text-secondary: #9aa5b4;
  --text-muted: #6b7789;
  --accent: #4d8df7;
  --accent-hover: #6ba0f9;
  --accent-subtle: rgba(77, 141, 247, 0.12);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, 0.12);
  --focus-ring: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

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

.tabular { font-variant-numeric: tabular-nums; }

/* Typography */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

h1, .h1 { font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.01em; }
h2, .h2 { font-size: var(--text-md); font-weight: 600; }
h3, .h3 { font-size: var(--text-base); font-weight: 600; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0 var(--space-3);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

@media (pointer: coarse) {
  .btn { min-height: 44px; min-width: 44px; padding: 0 var(--space-4); }
}

.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); }

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

.btn-sm { min-height: 28px; padding: 0 var(--space-2); font-size: var(--text-xs); }
.btn-icon { padding: 0; width: 32px; }
@media (pointer: coarse) { .btn-icon { width: 44px; } }

/* Inputs */
.field { margin-bottom: var(--space-4); }
.field label, .field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }
.field-error { font-size: var(--text-xs); color: var(--danger); margin-top: var(--space-1); }

.input, .select, .textarea {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input { min-height: 32px; }
@media (pointer: coarse) { .input, .select { min-height: 44px; } }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.input.error { border-color: var(--danger); }

.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* Checkbox / toggle */
.checkbox-row { display: flex; align-items: center; gap: var(--space-2); min-height: 32px; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.toggle[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(16px); background: #fff; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-default { background: var(--bg-sunken); color: var(--text-secondary); border-color: var(--border); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-subtle); color: var(--accent); }

/* Cards & surfaces */
.surface {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card { padding: var(--space-4); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-title { font-size: var(--text-sm); font-weight: 600; }

/* Tables */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.data-table th:hover { color: var(--text-secondary); }
.data-table th.sorted { color: var(--accent); }
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .cell-thumb { width: 36px; height: 36px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg-sunken); }

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}
.segmented button {
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-1) var(--space-3);
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 28px;
}
@media (pointer: coarse) { .segmented button { min-height: 40px; padding: var(--space-2) var(--space-4); } }
.segmented button[aria-selected="true"] {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.segmented button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Filter chips */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent); }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}
.kpi {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.kpi-label { font-size: var(--text-xs); color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: var(--space-1); }
.kpi-delta { font-size: var(--text-xs); margin-top: var(--space-1); }

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(480px, 100vw);
  height: 100%;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 250ms ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-body { flex: 1; overflow: auto; padding: var(--space-4); }
.drawer-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(440px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.modal-header { padding: var(--space-4); border-bottom: 1px solid var(--border); }
.modal-body { padding: var(--space-4); }
.modal-footer { padding: var(--space-4); border-top: 1px solid var(--border); display: flex; gap: var(--space-2); justify-content: flex-end; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: slideIn 200ms ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--bg-hover) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-text { height: 12px; margin-bottom: var(--space-2); }
.skeleton-title { height: 20px; width: 60%; margin-bottom: var(--space-3); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2rem; margin-bottom: var(--space-3); opacity: 0.5; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: var(--space-2); }

/* Kanban */
.kanban {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  min-height: 400px;
}
.kanban-col {
  flex: 0 0 260px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col-header {
  padding: var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}
.kanban-col-body { flex: 1; overflow: auto; padding: var(--space-2); display: flex; flex-direction: column; gap: var(--space-2); }
.kanban-card {
  padding: var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: grab;
  font-size: var(--text-sm);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.5; }

/* Chart placeholder */
.chart-area {
  height: 160px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: var(--space-3) 0;
}
.chart-bar {
  flex: 1;
  background: var(--accent-subtle);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 4px;
  transition: height var(--transition);
}
.chart-bar:hover { background: var(--accent); opacity: 0.8; }

/* Tooltip */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  background: var(--text-primary);
  color: var(--bg-elevated);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 50;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; }

/* Divider */
.divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
@media (max-width: 1024px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.toolbar-spacer { flex: 1; }

/* Activity feed */
.activity-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.activity-item:last-child { border-bottom: none; }
.activity-time { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--bg-base);
}
.login-card {
  width: min(380px, 100%);
  padding: var(--space-6);
}

/* Status page */
.status-grid { display: grid; gap: var(--space-3); max-width: 640px; margin: 0 auto; padding: var(--space-6); }

/* Help docs */
.help-layout { display: grid; grid-template-columns: 220px 1fr; gap: var(--space-6); }
@media (max-width: 768px) { .help-layout { grid-template-columns: 1fr; } }
.help-nav a {
  display: block;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
}
.help-nav a:hover, .help-nav a.active { background: var(--accent-subtle); color: var(--accent); }
.help-content h2 { margin: var(--space-6) 0 var(--space-3); }
.help-content h3 { margin: var(--space-4) 0 var(--space-2); }
.help-content p, .help-content li { font-size: var(--text-sm); color: var(--text-secondary); margin-bottom: var(--space-2); }
.help-content img { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius-md); margin: var(--space-3) 0; }
.control-ref { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-4); }
.control-ref h4 { margin-bottom: var(--space-2); }

/* Workbench */
.workbench {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: var(--space-3);
  height: calc(100vh - var(--topbar-h) - var(--space-8));
  min-height: 500px;
}
@media (max-width: 1280px) { .workbench { grid-template-columns: 240px 1fr; } .workbench-preview { display: none; } }
@media (max-width: 768px) { .workbench { grid-template-columns: 1fr; height: auto; } }

.workbench-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.workbench-panel-header {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.workbench-panel-body { flex: 1; overflow: auto; padding: var(--space-3); }
.editor-area { min-height: 200px; }
.autosave-indicator { font-size: var(--text-xs); color: var(--text-muted); }
.autosave-indicator.saving { color: var(--warning); }
.autosave-indicator.saved { color: var(--success); }

/* Calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.cal-cell {
  background: var(--bg-elevated);
  min-height: 80px;
  padding: var(--space-2);
  font-size: var(--text-xs);
}
.cal-cell-head { background: var(--bg-sunken); min-height: auto; text-align: center; font-weight: 600; color: var(--text-muted); padding: var(--space-2); }
.cal-event {
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.scheduled { background: var(--info-bg); color: var(--info); }
.cal-event.published { background: var(--success-bg); color: var(--success); }

/* Channel preview */
.channel-preview {
  padding: var(--space-4);
  background: var(--bg-sunken);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.channel-constraints { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-3); padding: var(--space-2); background: var(--bg-elevated); border-radius: var(--radius-sm); }

/* Mobile card list */
.card-list { display: none; }
@media (max-width: 768px) {
  .table-wrap.desktop-only { display: none; }
  .card-list { display: flex; flex-direction: column; gap: var(--space-3); }
  .mobile-card {
    padding: var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  }
  .mobile-card-header { display: flex; gap: var(--space-3); align-items: flex-start; margin-bottom: var(--space-2); }
}

/* Visually hidden */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
