/* wp-reports staff UI: tokens and base rules. The one stylesheet every page
 * loads (60 Claude/Active/Agency/Pollux/WP-Reports Web UI Design Guide).
 *
 * Templates may add a scoped <style> that uses these custom properties, never a
 * hex value. The PDF report has its own pipeline (report_theme.py, base.css)
 * and never sees this file. */

/* ------------------------------------------------------------------ tokens */
:root {
  --color-primary: #1976d2;
  --color-primary-hover: #1565c0;
  --color-secondary: #00897b;
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-surface-inset: #f1f3f5;
  --color-border: #e0e0e0;
  --color-text: #212121;
  --color-text-secondary: #666666;
  --color-on-primary: #ffffff;

  --color-success: #2e7d32;
  --color-warning: #ed6c02;
  --color-error: #d32f2f;
  --color-info: #0288d1;

  --status-draft: #ed6c02;
  --status-staff-approved: #0288d1;
  --status-shared: #7b1fa2;
  --status-client-approved: #43a047;
  --status-sent: #6d4c41;

  --health-ok: #2e7d32;
  --health-stale: #ed6c02;
  --health-failing: #d32f2f;
  --health-maintenance: #0288d1;

  --severity-critical: #c62828;
  --severity-high: #d32f2f;
  --severity-medium: #ed6c02;
  --severity-low: #0288d1;

  --font-family: 'Roboto', system-ui, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, monospace;
  --text-xs: 0.6875rem;
  --text-sm: 0.75rem;
  --text-md: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --radius: 4px;
  --gutter: 24px;
  --max-width: 1200px;
  --backdrop: rgba(0, 0, 0, 0.5);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #90caf9;
    --color-primary-hover: #42a5f5;
    --color-secondary: #4db6ac;
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-surface-inset: #262626;
    --color-border: #3a3a3a;
    --color-text: #e0e0e0;
    --color-text-secondary: #aaaaaa;
    --color-on-primary: #121212;

    --color-success: #66bb6a;
    --color-warning: #ffa726;
    --color-error: #f44336;
    --color-info: #29b6f6;

    --status-draft: #ffa726;
    --status-staff-approved: #29b6f6;
    --status-shared: #ba68c8;
    --status-client-approved: #81c784;
    --status-sent: #c19a6b;

    --health-ok: #66bb6a;
    --health-stale: #ffa726;
    --health-failing: #f44336;
    --health-maintenance: #29b6f6;

    --severity-critical: #e57373;
    --severity-high: #f44336;
    --severity-medium: #ffa726;
    --severity-low: #29b6f6;
  }
}

/* --------------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: var(--text-md);
  font-weight: 400;
  line-height: 1.45;
}
a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover); }
code, .mono { font-family: var(--font-mono); font-size: 0.95em; }
h1, h2, h3 { font-weight: 600; margin: 0; line-height: 1.25; }
h1 { font-size: var(--text-lg); }
h2 { font-size: var(--text-base); }
h3 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3); }
.muted { color: var(--color-text-secondary); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------- layout */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.topbar-inner, .page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  min-height: 56px;
}
.brandmark { font-weight: 600; font-size: var(--text-base); color: var(--color-text); text-decoration: none; }
.mainnav { display: flex; gap: var(--space-2); flex: 1; }
.mainnav a {
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  font-weight: 600;
}
.mainnav a:hover { background: var(--color-surface-inset); color: var(--color-text); }
.mainnav a.is-active { color: var(--color-primary); }
.userbox { color: var(--color-text-secondary); font-size: var(--text-sm); white-space: nowrap; }

.page { padding-top: var(--space-6); padding-bottom: var(--space-8); }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-head .meta { margin-top: var(--space-1); color: var(--color-text-secondary); font-size: var(--text-sm); }
.crumbs { font-size: var(--text-sm); margin-bottom: var(--space-2); }
.section { margin-bottom: var(--space-8); }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}
.stack > * + * { margin-top: var(--space-4); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }

/* -------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs a:hover { color: var(--color-text); }
.tabs a.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tabs .count { font-weight: 400; color: var(--color-text-secondary); margin-left: var(--space-1); }
.tabpanel { display: none; }
.tabpanel.is-active { display: block; }

/* ------------------------------------------------------------- summary row */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-6); }
.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
}
.stat:hover { background: var(--color-surface-inset); }
.stat.is-active { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
.stat .value { display: block; font-size: var(--text-xl); font-weight: 600; line-height: 1.2; }
.stat .label { display: block; font-size: var(--text-sm); color: var(--color-text-secondary); }
.stat.tone-warning .value { color: var(--color-warning); }
.stat.tone-error .value { color: var(--color-error); }
.stat.tone-info .value { color: var(--color-info); }
.stat.tone-critical .value { color: var(--severity-critical); }
.stat.tone-high .value { color: var(--severity-high); }
.stat.tone-medium .value { color: var(--severity-medium); }
.stat.tone-low .value { color: var(--severity-low); }

/* -------------------------------------------------------------------- tables */
.table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: top; }
table.data thead th {
  background: var(--color-surface-inset);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  white-space: nowrap;
}
table.data th[data-sort] { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
table.data th[data-sort][aria-sort="ascending"]::after { content: " \25B2"; }
table.data th[data-sort][aria-sort="descending"]::after { content: " \25BC"; }
table.data tbody td { border-top: 1px solid var(--color-border); font-size: var(--text-md); }
table.data tbody tr:hover { background: var(--color-surface-inset); }
table.data tr.is-resolved { opacity: 0.5; }
table.data tr.is-muted td:first-child { color: var(--color-text-secondary); }
table.data td.empty { text-align: center; color: var(--color-text-secondary); padding: var(--space-6); }
table.data .sub { display: block; font-size: var(--text-xs); color: var(--color-text-secondary); }
table.data a.rowlink { font-weight: 600; text-decoration: none; color: var(--color-text); }
table.data a.rowlink:hover { color: var(--color-primary); }
tr.detail > td { background: var(--color-surface-inset); padding: 0; }
tr.detail table.data thead th { position: static; }

/* ------------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  line-height: 1.2;
  white-space: nowrap;
  vertical-align: middle;
  --tone: var(--color-text-secondary);
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 12%, transparent);
}
.badge + .badge { margin-left: var(--space-1); }
a.badge { text-decoration: none; }
a.badge:hover { background: color-mix(in srgb, var(--tone) 22%, transparent); }
.tone-success { --tone: var(--color-success); }
.tone-warning { --tone: var(--color-warning); }
.tone-error { --tone: var(--color-error); }
.tone-info { --tone: var(--color-info); }
.tone-neutral { --tone: var(--color-text-secondary); }
.status-draft { --tone: var(--status-draft); }
.status-staff_approved { --tone: var(--status-staff-approved); }
.status-shared { --tone: var(--status-shared); }
.status-client_approved { --tone: var(--status-client-approved); }
.status-sent { --tone: var(--status-sent); }
.health-ok { --tone: var(--health-ok); }
.health-stale { --tone: var(--health-stale); }
.health-failing { --tone: var(--health-failing); }
.health-maintenance { --tone: var(--health-maintenance); }
.severity-critical { --tone: var(--severity-critical); }
.severity-high { --tone: var(--severity-high); }
.severity-medium { --tone: var(--severity-medium); }
.severity-low, .severity-none { --tone: var(--severity-low); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  position: relative;
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--color-surface-inset); color: var(--color-text); }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: var(--color-on-primary); }
.btn-danger { border-color: var(--color-error); color: var(--color-error); }
.btn-danger:hover { background: var(--color-error); color: var(--color-on-primary); }
.btn-sm { min-height: 28px; padding: var(--space-1) var(--space-2); font-size: var(--text-sm); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid var(--color-text-secondary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.btn-primary.is-busy::after { border-color: var(--color-on-primary); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.linkbtn { background: none; border: none; padding: 0; font: inherit; color: var(--color-primary); cursor: pointer; text-decoration: underline; }

/* -------------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field + .field, .pair + .field, .field + .pair, .pair + .pair { margin-top: var(--space-4); }
/* Side by side, the grid spaces the fields; the stacking margin above would push
 * the right-hand field down. */
.pair > .field + .field { margin-top: 0; }
.pair { align-items: start; }
.pair.align-end { align-items: end; }
label, .label { font-size: var(--text-md); font-weight: 600; color: var(--color-text); }
.help { font-size: var(--text-xs); color: var(--color-text-secondary); }
input[type=text], input[type=email], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-md);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .stat:focus-visible, .tabs a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: var(--space-2); font-weight: 400; min-height: 32px; }
.check input { width: 18px; height: 18px; }
fieldset { border: none; border-bottom: 1px solid var(--color-border); margin: 0 0 var(--space-6); padding: 0 0 var(--space-6); }
fieldset:last-of-type { border-bottom: none; }
legend { font-size: var(--text-base); font-weight: 600; padding: 0; margin-bottom: var(--space-4); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-3); }
.toolbar input[type=search] { max-width: 320px; }

/* ----------------------------------------------------------- flash / alerts */
.flashes { position: sticky; top: 0; z-index: 20; }
.alert {
  --tone: var(--color-info);
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3);
  border-radius: var(--radius);
  border-left: 1px solid var(--tone);
  background: color-mix(in srgb, var(--tone) 12%, var(--color-surface));
  color: var(--tone);
  margin-bottom: var(--space-3);
}
.alert .text { flex: 1; color: var(--color-text); }
.alert .close { background: none; border: none; color: var(--tone); cursor: pointer; font-size: var(--text-base); line-height: 1; padding: 0 var(--space-1); }
.alert.tone-success { --tone: var(--color-success); }
.alert.tone-warning { --tone: var(--color-warning); }
.alert.tone-error { --tone: var(--color-error); }
.alert.tone-info { --tone: var(--color-info); }

/* --------------------------------------------------------- workflow stepper */
.stepper { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: var(--space-3) 0 0; padding: 0; list-style: none; }
.stepper li { font-size: var(--text-sm); color: var(--color-text-secondary); opacity: 0.6; }
.stepper li.done { opacity: 1; color: var(--color-success); }
.stepper li.done::before { content: "\2713  "; }
.stepper li.current { opacity: 1; color: var(--color-text); font-weight: 600; }
.stepper li + li::before { content: "\203A"; margin-right: var(--space-2); color: var(--color-text-secondary); }
.stepper li.done + li::before { color: var(--color-text-secondary); }

/* ------------------------------------------------------------------ dialogs */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: var(--space-4);
  max-width: 480px;
  width: calc(100% - 2 * var(--space-4));
  background: var(--color-surface);
  color: var(--color-text);
}
dialog::backdrop { background: var(--backdrop); }
dialog h2 { font-size: var(--text-base); margin-bottom: var(--space-2); }
dialog .body { color: var(--color-text-secondary); margin-bottom: var(--space-4); }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }

/* ------------------------------------------------------------ misc patterns */
.spinner {
  width: 40px; height: 40px; margin: var(--space-8) auto;
  border: 3px solid var(--color-primary); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.empty-state { text-align: center; color: var(--color-text-secondary); padding: var(--space-8) var(--space-4); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--color-text-secondary); }
.kv dd { margin: 0; }
.errtext { color: var(--color-error); font-size: var(--text-sm); }
.pager { display: flex; gap: var(--space-3); align-items: center; margin-top: var(--space-3); font-size: var(--text-sm); }
.suggestion { background: var(--color-surface-inset); border-left: 1px solid var(--color-info); border-radius: var(--radius); padding: var(--space-3); margin-top: var(--space-2); }
.suggestion .actions { margin-top: var(--space-2); }
.chk { font-size: var(--text-sm); color: var(--color-success); font-weight: 600; }
.chk.pending { color: var(--color-warning); }
.admin { border-top: 1px solid var(--color-border); padding-top: var(--space-6); margin-top: var(--space-8); }
.login-card { max-width: 420px; margin: 15vh auto 0; text-align: center; }

/* ---------------------------------------------------------- mobile (768px) */
@media (max-width: 767px) {
  :root { --gutter: 16px; }
  .topbar-inner { gap: var(--space-3); flex-wrap: wrap; padding-top: var(--space-2); padding-bottom: var(--space-2); }
  .userbox { width: 100%; order: 3; }
  .split, .pair { grid-template-columns: 1fr; }
  .btn { min-height: 44px; }
  .actions .btn, .page-head .btn, form .btn { width: 100%; }
  .stat { min-height: 64px; }
  /* Tables become stacked cards: each row a card, each cell labelled. */
  table.stack-mobile thead { display: none; }
  table.stack-mobile, table.stack-mobile tbody, table.stack-mobile tr, table.stack-mobile td { display: block; width: 100%; }
  table.stack-mobile tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
  }
  table.stack-mobile tbody td { border-top: none; padding: var(--space-1) 0; }
  table.stack-mobile td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
  }
  table.stack-mobile td:first-child { font-size: var(--text-base); }
  table.stack-mobile td:first-child::before { display: none; }
  .table-wrap:has(table.stack-mobile) { background: transparent; border: none; }
}
