/* Instinly design system (Docs/UI_UX_Improvement_Plan.md, phase U0).
   Every colour is a token. Components and templates use var(--…), never raw
   hex, so the dark theme below covers every page without per-page work.
   Theme: [data-theme] on <html> (set from the "theme" cookie) wins; with no
   attribute the OS preference decides. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --navy: #063A86;
  --accent: #0185DD;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --text: #1a1f2b;
  --heading: #063A86;
  --muted: #5b6475;          /* AA on --bg and --surface; #667085 was 4.4:1 on --bg */
  --border: #d9e0ec;
  --border-strong: #7d8aa0;   /* form-field outlines need 3:1 (WCAG 1.4.11) */
  --link: #0068b8;
  --focus: #0185DD;
  --chart-1: #0068b8;        /* chart line/bar; passes the dataviz checks on --surface */

  --btn-bg: #0072c6;         /* white text ≥ 4.5:1; brand accent itself is 3.6:1 */
  --btn-bg-hover: #063A86;
  --btn-fg: #ffffff;
  --btn-secondary-bg: #e6ebf3;
  --btn-secondary-fg: #1a1f2b;
  --btn-secondary-hover: #d5dce8;

  --info-bg: #eaf6ff;    --info-fg: #0b4a7a;    --info-border: #b9defb;
  --success-bg: #ecfdf3; --success: #067647;    --success-border: #abefc6;
  --warning-bg: #fff8e6; --warning: #b54708;    --warning-border: #fedf89;
  --danger-bg: #fdecec;  --danger: #b42318;     --danger-border: #fecdca;

  --topbar-bg: #063A86;
  --topbar-fg: #ffffff;
  --nav-active-bg: #e3effc;
  --nav-active-fg: #063A86;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .10);

  --radius-sm: 6px;
  --radius: 10px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 12px; --text-sm: 13px; --text-base: 15px; --text-lg: 18px;
  --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1420;
    --surface: #151c2b;
    --surface-2: #1c2536;
    --text: #e6e9ef;
    --heading: #a9cbff;
    --muted: #9aa4b5;
    --border: #2a3447;
    --border-strong: #6b7891;
    --link: #6bbcff;
    --focus: #6bbcff;
    --chart-1: #3492e6;
    --btn-bg: #1f6fc4;
    --btn-bg-hover: #1a66b8;
    --btn-secondary-bg: #253047;
    --btn-secondary-fg: #e6e9ef;
    --btn-secondary-hover: #2f3c57;
    --info-bg: #10263d;    --info-fg: #a9d4ff;    --info-border: #1d4266;
    --success-bg: #0d2a1d; --success: #6fdc9c;    --success-border: #1b5236;
    --warning-bg: #2f220b; --warning: #f5c26b;    --warning-border: #5c4214;
    --danger-bg: #351516;  --danger: #ff9b91;     --danger-border: #6a2525;
    --topbar-bg: #0a1a33;
    --nav-active-bg: #1c3050;
    --nav-active-fg: #cfe2ff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420;
  --surface: #151c2b;
  --surface-2: #1c2536;
  --text: #e6e9ef;
  --heading: #a9cbff;
  --muted: #9aa4b5;
  --border: #2a3447;
  --border-strong: #6b7891;
  --link: #6bbcff;
  --focus: #6bbcff;
    --chart-1: #3492e6;
  --btn-bg: #1f6fc4;
  --btn-bg-hover: #1a66b8;
  --btn-secondary-bg: #253047;
  --btn-secondary-fg: #e6e9ef;
  --btn-secondary-hover: #2f3c57;
  --info-bg: #10263d;    --info-fg: #a9d4ff;    --info-border: #1d4266;
  --success-bg: #0d2a1d; --success: #6fdc9c;    --success-border: #1b5236;
  --warning-bg: #2f220b; --warning: #f5c26b;    --warning-border: #5c4214;
  --danger-bg: #351516;  --danger: #ff9b91;     --danger-border: #6a2525;
  --topbar-bg: #0a1a33;
  --nav-active-bg: #1c3050;
  --nav-active-fg: #cfe2ff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
}

/* ---------- Base elements ---------- */
* { box-sizing: border-box; }
/* The hidden attribute must win over component display rules (e.g. button). */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { color: var(--heading); line-height: 1.25; }
h1 { font-size: 26px; margin: 0 0 var(--space-2); }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  overflow-wrap: anywhere;
}

img { max-width: 100%; height: auto; }

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

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

/* ---------- Forms ---------- */
label {
  display: block;
  margin-top: var(--space-4);
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
}

input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], input[type=search], input[type=tel], input[type=date],
input[type=datetime-local], input[type=file], input:not([type]), select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
input[type=file] { padding: 8px; }
textarea { resize: vertical; line-height: 1.5; }
select { width: auto; max-width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--btn-bg); }
input[disabled], select[disabled], textarea[disabled] { opacity: .6; cursor: not-allowed; }

.help { color: var(--muted); font-size: var(--text-sm); margin-top: 4px; }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-5);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid transparent;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
}
button:hover, .btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
button[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
button[disabled]:hover { background: var(--btn-bg); }

.btn-secondary, button.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border-color: var(--border);
}
.btn-secondary:hover, button.btn-secondary:hover { background: var(--btn-secondary-hover); color: var(--btn-secondary-fg); }
.btn-ghost, button.btn-ghost {
  background: transparent;
  color: var(--link);
  border-color: var(--border-strong);
}
.btn-ghost:hover, button.btn-ghost:hover { background: var(--surface-2); color: var(--link); }
.btn-danger, button.btn-danger { background: var(--danger); color: #fff; }
.btn-sm, button.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-4); }
.btn-row > .btn, .btn-row > button, .btn-row > form > button { margin-top: 0; }

/* Set by app.js while a form submits, so a real-world action can't be sent twice. */
button[aria-busy="true"] { opacity: .7; cursor: progress; }
button[aria-busy="true"]::after {
  content: "";
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Alerts ---------- */
.alert, .error {
  display: block;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--info-border);
  background: var(--info-bg);
  color: var(--info-fg);
  font-size: 14px;
  margin: var(--space-3) 0;
}
.alert a, .error a { color: inherit; font-weight: 600; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.alert-error, .error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.alert strong:first-child { margin-right: 2px; }
.alert form { display: inline; }
.alert button { margin: 0 0 0 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}
a.badge { text-decoration: none; }
a.badge:hover { border-color: currentColor; }
.badge-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
.badge-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }

/* "Coming soon" (plan D5 / §6): a badge plus a disabled control. */
.coming-soon { opacity: .75; }
.coming-soon .help { margin-top: 2px; }

/* ---------- Text helpers ---------- */
.muted { color: var(--muted); font-size: 14px; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.small { font-size: var(--text-sm); }
.insight-content { white-space: pre-line; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout: cards, panels ---------- */
.card {
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.card-wide { max-width: 1100px; }
.card-medium { max-width: 820px; }

.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-header h1 { margin: 0; }
.page-header .subtitle { color: var(--muted); font-size: 14px; margin: 6px 0 0; max-width: 68ch; }
.page-header .btn, .page-header button { margin-top: 0; }

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

.section { margin-top: var(--space-6); }
.section > h2:first-child { margin-top: 0; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); margin-top: var(--space-2); }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  text-decoration: none;
  color: var(--text);
}
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.stat .value { display: block; font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat .label { display: block; color: var(--muted); font-size: var(--text-sm); }
.stat .sparkline { display: block; margin-top: 6px; color: var(--link); }

/* ---------- Lists ---------- */
ul.doc-list { list-style: none; padding: 0; margin-top: var(--space-4); }
ul.doc-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
ul.doc-list li:last-child { border-bottom: 0; }

.checklist { list-style: none; padding: 0; margin: var(--space-3) 0 0; }
.checklist li {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: 0; }
.checklist .check {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: transparent;
}
.checklist li.done .check { background: var(--success); border-color: var(--success); color: var(--surface); }
.checklist li.done .title { color: var(--muted); text-decoration: line-through; }
.checklist .title { font-weight: 600; }
.checklist .help { margin: 0; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: var(--text-sm); color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--border); padding: 6px 8px; }
td { border-bottom: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

details > summary { cursor: pointer; color: var(--link); font-weight: 600; }

/* ---------- Onboarding steps ---------- */
.steps { display: flex; gap: 8px; margin-bottom: var(--space-5); flex-wrap: wrap; }
.steps span {
  flex: 1 1 100px;
  text-align: center;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.steps span.active { background: var(--btn-bg); border-color: var(--btn-bg); color: #fff; }

/* ---------- App shell ---------- */
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  background: var(--surface); color: var(--link);
  padding: 8px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
}
.skip-link:focus { top: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  padding: 10px 20px;
  min-height: 56px;
}
.topbar .brand { display: inline-flex; align-items: center; }
.topbar .spacer { flex: 1; }
.topbar a { color: var(--topbar-fg); }
.topbar button { margin: 0; }
.topbar .icon-btn {
  background: transparent; color: var(--topbar-fg);
  border: 1px solid rgba(255, 255, 255, .25);
  padding: 6px 10px; min-height: 36px; font-size: 14px; font-weight: 500;
}
.topbar .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.nav-toggle { display: none; }

.topnav { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.topnav a { text-decoration: none; font-weight: 500; }
.topnav a:hover { text-decoration: underline; }
.topnav .btn { margin: 0; background: #fff; color: var(--navy); }
.topnav .btn:hover { background: #e3effc; color: var(--navy); }

.user-menu { position: relative; }
.user-menu > summary {
  list-style: none; color: var(--topbar-fg); font-weight: 500; font-size: 14px;
  padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid rgba(255, 255, 255, .25);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: rgba(255, 255, 255, .12); }
.user-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: 6px 0; z-index: 40;
}
.user-menu .menu a { display: block; padding: 8px 14px; color: var(--text); text-decoration: none; font-size: 14px; }
.user-menu .menu a:hover { background: var(--surface-2); }
.user-menu .menu .who { padding: 8px 14px; font-size: var(--text-sm); color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-wrap: anywhere; }

.shell {
  display: flex; align-items: stretch; min-height: calc(100vh - 56px);
  background: linear-gradient(to right, var(--surface) calc(var(--sidebar-w) - 1px), var(--border) calc(var(--sidebar-w) - 1px), var(--border) var(--sidebar-w), transparent var(--sidebar-w));
}

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-4) var(--space-3) var(--space-6);
  position: sticky; top: 56px; align-self: flex-start;
  height: calc(100vh - 56px); overflow-y: auto;
}
.sidebar .group { margin-bottom: var(--space-4); }
.sidebar .group-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 0 10px; margin: 0 0 4px;
}
.sidebar a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a[aria-current="page"] { background: var(--nav-active-bg); color: var(--nav-active-fg); font-weight: 700; }

.shell > .content { flex: 1; min-width: 0; }

.content {
  /* Outer wrapper only — the width per page is set by .card (and its
     modifiers). A block child can't exceed its parent's constraint, so this
     must stay wider than the widest card. */
  max-width: 1140px;
  margin: 0 auto;
  padding: var(--space-6) 20px var(--space-7);
}
.content-public { margin: var(--space-6) auto; }

.footer { text-align: center; padding: 20px; font-size: 13px; color: var(--muted); }
.footer a { color: var(--muted); }

.theme-toggle .label-text { margin-left: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { background: none; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 25;
    height: auto; transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-md);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-scrim {
    position: fixed; inset: 56px 0 0 0; z-index: 20; background: rgba(0, 0, 0, .35);
  }
  .theme-toggle .label-text { display: none; }
}

@media (max-width: 640px) {
  .content { padding: var(--space-4) 16px var(--space-6); }
  .card { padding: var(--space-4); border-radius: var(--radius-sm); }
  h1 { font-size: 22px; }
  .topbar { padding: 8px 12px; }
  .topnav { gap: var(--space-3); font-size: 14px; }
  .topnav .hide-sm { display: none; }
  .user-menu > summary { max-width: 120px; }

  /* Tables become stacked rows: each cell shows its column name from
     data-label (set by app.js from the header row). */
  table.stack-sm thead { display: none; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm tr { border-bottom: 1px solid var(--border); padding: 6px 0; }
  table.stack-sm td { border: 0; padding: 3px 0; }
  table.stack-sm td[data-label]::before {
    content: attr(data-label); display: block;
    font-size: var(--text-xs); font-weight: 600; color: var(--muted);
  }
}

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

@media print {
  .topbar, .sidebar, .footer, .nav-scrim, .skip-link { display: none !important; }
  .card { border: 0; box-shadow: none; max-width: none; padding: 0; }
  body { background: #fff; color: #000; }
}

/* ---------- Provider cards (Connections / Integrations) ---------- */
.provider {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5) var(--space-5);
  margin-top: var(--space-5);
  background: var(--surface);
}
.provider-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.provider-head h2 { margin: 0; margin-right: auto; font-size: 18px; }
.provider-does { margin: var(--space-2) 0 0; font-size: 14px; color: var(--muted); }
.provider h3 { font-size: 15px; }
@media (max-width: 640px) { .provider { padding: var(--space-3) var(--space-4) var(--space-4); } }

/* ---------- Background-job progress (U5.1) ---------- */
.job-progress { display: flex; gap: var(--space-3); align-items: flex-start; }
.spinner {
  flex: 0 0 18px; width: 18px; height: 18px; margin-top: 2px;
  border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin: var(--space-5) 0 var(--space-3);
}
.tabs a {
  padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--link); border-bottom-color: var(--link); }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; text-align: center; color: var(--muted);
}

/* ---------- Content queue ---------- */
fieldset.plain { border: 0; padding: 0; margin: var(--space-3) 0 0; }
fieldset.plain legend { font-weight: 600; font-size: 14px; padding: 0; }
.check-grid { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 6px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
details.generate > summary { padding: 2px 0; }
details.generate[open] > summary { margin-bottom: var(--space-2); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.filters label { margin: 0; }
.filters select { padding: 6px 10px; }
.filters button { margin: 0; }
.bulk { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.bulk button { margin: 0; }

.step-group { margin-top: var(--space-5); }
.step-group > h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 17px; }
.step-group > .help { margin: 4px 0 var(--space-3); max-width: 80ch; }

.draft-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4); margin-top: var(--space-3); background: var(--surface);
}
.draft-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.draft-head h3 { margin: 0; font-size: 15px; }
.draft-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.draft-body { margin-top: var(--space-2); font-size: 14px; }
.draft-more { margin-top: var(--space-2); }
.draft-more > summary { color: var(--text); font-weight: 400; font-size: 14px; list-style: none; }
.draft-more > summary::-webkit-details-marker { display: none; }
.draft-more > summary .more-label { color: var(--link); font-weight: 600; white-space: nowrap; }
.draft-more > summary .opened,
.draft-more[open] > summary .preview,
.draft-more[open] > summary .closed { display: none; }
.draft-more[open] > summary .opened { display: inline; }
.draft-actions { margin-top: var(--space-3); }
.draft-actions form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
.draft-actions button { margin: 0; }
.schedule-form input[type=datetime-local] { width: auto; padding: 6px 8px; }
.draft-image { display: block; margin-top: var(--space-2); max-height: 320px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.inline-upload { margin-top: var(--space-2); }
.inline-upload input[type=file] { width: auto; }
.inline-upload button { margin-top: 6px; }
.draft-done { background: var(--surface-2); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.draft-done p { margin: 0; font-size: 14px; }
.draft-done form { margin: 0; }
.draft-done button { margin: 0; }
.mono { font-family: var(--mono); }
.empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }

/* ---------- Confirmation dialog (U5.4) ---------- */
dialog.confirm {
  border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-5);
  max-width: 460px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-md);
}
dialog.confirm::backdrop { background: rgba(0, 0, 0, .45); }
dialog.confirm h2 { margin: 0 0 var(--space-2); font-size: 18px; }
dialog.confirm p { margin: 0; font-size: 14px; }
dialog.confirm .btn-row { justify-content: flex-end; margin-top: var(--space-5); }
@media (max-width: 640px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs a { white-space: nowrap; padding: 8px 10px; }
}

/* ---------- Charts and meters (U4.11, U4.12) ---------- */
.chart { margin: var(--space-4) 0 0; }
.chart figcaption { font-size: var(--text-sm); font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.chart-box { position: relative; height: 220px; }
.chart-table { margin-top: 6px; }
.chart-table table { max-width: 360px; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented a { padding: 6px 12px; font-size: 13px; font-weight: 600; text-decoration: none; color: var(--text); background: var(--surface); }
.segmented a + a { border-left: 1px solid var(--border-strong); }
.segmented a[aria-current="true"] { background: var(--btn-bg); color: #fff; }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; min-width: 100px; }
.meter > span { display: block; height: 100%; background: var(--success); }
.meter.warning > span { background: var(--warning); }
.meter.danger > span { background: var(--danger); }
.section h3 { margin-top: var(--space-5); }
.needs-you .doc-list li { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; }
@media print {
  .daily-report details { display: block; }
  .daily-report details > summary { display: none; }
  .daily-report .page-header .btn-row { display: none; }
  .badge { border: 1px solid #000; }
}

/* ---------- Research report (U4.7) ---------- */
.report-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-6); margin-top: var(--space-4); }
.report-toc { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 88px); overflow-y: auto; }
.report-toc ol { list-style: none; padding: 0; margin: 0; }
.report-toc a { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; border-radius: var(--radius-sm); font-size: 14px; text-decoration: none; color: var(--text); }
.report-toc a:hover { background: var(--surface-2); }
.report-body section { scroll-margin-top: 72px; padding-bottom: var(--space-3); }
.report-body section + section { border-top: 1px solid var(--border); margin-top: var(--space-5); padding-top: var(--space-2); }
.report-body h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.facts-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: var(--space-2) 0 0; }
.facts-list dt { font-weight: 600; color: var(--muted); }
.facts-list dd { margin: 0; }
.facts-list ul { margin: 0; padding-left: 18px; }
.competitor h3, .report-body .draft-card h3 { margin: 0 0 4px; font-size: 15px; }
.sources { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 4px; }
.sources-label { font-size: var(--text-xs); color: var(--muted); }
.chip { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
        padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: var(--text-xs); color: var(--muted); text-decoration: none; }
a.chip:hover { color: var(--link); border-color: var(--link); }
ol.ranked { list-style: decimal; padding-left: 22px; }
ol.ranked li { padding-left: 4px; }
.history-item { margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--border); }
.menu-button { position: relative; }
.menu-button > summary { list-style: none; margin: 0; }
.menu-button > summary::-webkit-details-marker { display: none; }
.menu-button .menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 180px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 4px 0; }
.menu-button .menu a { display: block; padding: 8px 14px; color: var(--text); text-decoration: none; font-size: 14px; }
.menu-button .menu a:hover { background: var(--surface-2); }
@media (max-width: 900px) {
  .report-layout { grid-template-columns: 1fr; }
  .report-toc { position: static; max-height: none; }
  .report-toc ol { display: flex; flex-wrap: wrap; gap: 4px; }
  .report-toc a { border: 1px solid var(--border); }
}

/* ---------- Campaigns (U4.8) ---------- */
.approvals { border: 1px solid var(--warning-border); background: var(--warning-bg); border-radius: var(--radius); padding: var(--space-3) var(--space-4) var(--space-4); margin-top: var(--space-4); }
.approvals h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.approval h3 { margin: 0; font-size: 15px; font-weight: 400; }
.campaigns td { vertical-align: middle; }
.budget-form input[type=number] { width: 120px; padding: 6px 8px; }
.budget-preview { flex-basis: 100%; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.inline-form label { margin: 0; }
.inline-form button { margin: 0; }
dialog.confirm p { white-space: pre-line; }
fieldset.form-section { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-4) var(--space-4); margin: var(--space-4) 0 0; }
fieldset.form-section legend { font-weight: 700; color: var(--heading); padding: 0 6px; }
.breadcrumb { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--space-2); }
.breadcrumb a { color: var(--link); }

/* ---------- Auth and onboarding (U3) ---------- */
.card-center { margin: 0 auto; max-width: 560px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  margin: var(--space-4) 0 0; padding: var(--space-6) var(--space-4);
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  font-weight: 400; cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--link); background: var(--info-bg); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone-title { font-weight: 600; }
.link-like { color: var(--link); text-decoration: underline; }
.dropzone input[type=file] { margin-top: var(--space-2); width: auto; max-width: 100%; background: transparent; border: 0; }
.file-row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.file-row button { margin: 0; }
.reveal-wrap { position: relative; }
.reveal-wrap input { padding-right: 76px; }
.reveal-wrap button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  margin: 0; min-height: 30px; padding: 4px 10px; font-size: 13px;
}
.alert .dismiss { float: right; margin: -2px -4px 0 8px; background: transparent; color: inherit; border: 0; min-height: 0; padding: 2px 6px; font-size: 18px; line-height: 1; }

/* ---------- Sidebar counts (U1.4) ---------- */
.nav-count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; text-align: center;
  background: var(--btn-bg); color: #fff; font-size: 12px; font-weight: 700; line-height: 1.6;
}

/* ---------- Experiments (U4.14) ---------- */
.experiment h3 { margin: 0; font-size: 15px; }
.exp-section { scroll-margin-top: 72px; margin-top: var(--space-5); }
.exp-section > h2 { display: flex; align-items: center; gap: 8px; }
.log-result { margin-top: var(--space-3); }
.log-result > summary { font-size: 14px; }
.log-result form { margin-top: var(--space-2); }
p.tight { margin: 6px 0 0; }
.learning-meta { display: flex; align-items: center; gap: var(--space-2); margin-top: 6px; }
.learning-meta .meter { width: 160px; min-width: 0; }
.interview-progress { margin-bottom: var(--space-2); }
.interview-progress .meter > span { background: var(--btn-bg); }
.interview-progress p { margin: 4px 0 0; }
.interview-nav button { margin: 0; }

/* ---------- Content map (U4.17) ---------- */
.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.funnel-stage { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: var(--space-3); display: flex; flex-direction: column; }
.funnel-stage h2 { font-size: 16px; margin: 0; display: flex; align-items: center; gap: 6px; }
.funnel-stage ul { list-style: none; padding: 0; margin: var(--space-2) 0; flex: 1; }
.funnel-stage li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; margin-bottom: 6px; }
.funnel-stage form button { margin: 0; width: 100%; justify-content: center; }

.plan-card h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.plan-card .price { font-size: 18px; font-weight: 700; margin: 6px 0 0; }
.plan-card.featured { border-color: var(--btn-bg); box-shadow: 0 0 0 1px var(--btn-bg); }
.usage .meter { margin-top: 6px; max-width: 320px; }
.help-link { margin: 6px 0 0; font-size: var(--text-sm); }
.help-search input { max-width: 480px; }
.error-page { text-align: center; }
.error-page .btn-row { justify-content: center; }
.error-code { font-size: 48px; font-weight: 800; color: var(--muted); margin: 0; line-height: 1; }
.field-error { color: var(--danger); font-size: var(--text-sm); font-weight: 600; margin: 4px 0 0; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }

/* Long URLs and IDs (often inside API error messages) must wrap, not push
   the page sideways on phones (found by tests/ui/screenshots.py). */
.content { overflow-wrap: break-word; }
.alert, .error, .help, td { overflow-wrap: anywhere; }

/* ---------- Public homepage (U8) ---------- */
.landing { max-width: 980px; margin: 0 auto; }
.hero { text-align: center; padding: var(--space-6) 0 var(--space-5); }
.hero h1 { font-size: 40px; max-width: 22ch; margin: 0 auto var(--space-3); }
.hero .lead { font-size: 19px; max-width: 60ch; margin: 0 auto; color: var(--text); }
.hero-actions { justify-content: center; }
.hero-actions .btn { font-size: 16px; padding: 12px 22px; }
.landing-section { margin-top: var(--space-7); }
.landing-section > h2 { font-size: 26px; text-align: center; margin-bottom: var(--space-5); }
.how-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.how-steps li, .feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow-sm); }
.how-steps h3, .feature h3 { margin: 8px 0 6px; font-size: 17px; }
.how-steps p, .feature p { margin: 0; color: var(--muted); font-size: 14px; }
.step-num { display: inline-flex; width: 32px; height: 32px; border-radius: 50%; align-items: center; justify-content: center; background: var(--btn-bg); color: #fff; font-weight: 700; }
.control .doc-list { max-width: 720px; margin: 0 auto; }
.landing-section details { max-width: 720px; margin: 0 auto var(--space-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.landing-section details p { margin: var(--space-2) 0 0; }
.landing-section > p { max-width: 68ch; margin: 0 auto; text-align: center; }
.cta-band { margin: var(--space-7) 0 var(--space-4); text-align: center; background: var(--topbar-bg); color: #fff; border-radius: var(--radius); padding: var(--space-6) var(--space-4); }
.cta-band h2 { color: #fff; margin: 0 0 var(--space-3); }
.cta-band .btn { background: #fff; color: var(--navy); margin: 0; }
.cta-band .btn:hover { background: #e3effc; color: var(--navy); }
@media (max-width: 640px) { .hero h1 { font-size: 30px; } .hero .lead { font-size: 17px; } }

/* ---------- Small utilities (U0.12) ---------- */
.section-title { margin-top: 28px; }
h3.subsection { margin-top: var(--space-5); font-size: 15px; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.m-0 { margin: 0; }
.d-block { display: block; }
.grow { flex: 1; }
.w-full { width: 100%; }
.w-140 { max-width: 140px; }
.w-360 { max-width: 360px; }
code.copyable { display: inline-block; padding: 4px 8px; margin-top: 4px; }
label.check.mt-4 { margin-top: var(--space-4); }
label.check.mt-2 { margin-top: var(--space-2); }

/* ---------- Toasts (U5.2) ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 10px 12px; font-size: 14px;
  transition: opacity .3s ease, transform .3s ease;
}
.toast:empty { display: none; }
.toast a { color: inherit; font-weight: 600; }
.toast .toast-text { flex: 1; }
.toast .dismiss { position: static; margin: -2px -4px 0 0; background: transparent; color: inherit; border: 0; min-height: 0; padding: 2px 6px; font-size: 18px; line-height: 1; }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }
@media print { .toasts { display: none; } }

/* ---------- Icons (U0.8) ---------- */
.icon { width: 1em; height: 1em; flex-shrink: 0; vertical-align: -0.125em; }
.topbar .icon-btn .icon { width: 18px; height: 18px; }
.user-menu > summary .icon, .menu-button > summary .icon { width: 14px; height: 14px; vertical-align: -2px; }
.checklist .check .icon { width: 14px; height: 14px; }

/* ---------- Glossary terms (U6.3) ---------- */
.term { position: relative; display: inline; }
.term-help {
  display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px;
  border-radius: 50%; border: 1px solid var(--border-strong); font-size: 11px; font-weight: 700; line-height: 1;
  text-decoration: none; color: var(--muted); vertical-align: 2px;
}
.term-help:hover, .term-help:focus-visible { color: var(--link); border-color: var(--link); }
.term-tip {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30; width: max-content; max-width: min(320px, 80vw);
  background: var(--text); color: var(--surface); font-size: 13px; font-weight: 400; line-height: 1.45;
  padding: 8px 10px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  visibility: hidden; opacity: 0; transition: opacity .15s ease; pointer-events: none; text-transform: none; letter-spacing: 0;
}
.term:hover .term-tip, .term-help:focus-visible + .term-tip { visibility: visible; opacity: 1; }
.glossary dt { font-weight: 700; margin-top: var(--space-3); scroll-margin-top: 72px; }
.glossary dd { margin: 2px 0 0; }
