/* Holt: OTTER dashboard styles. Tokens first, then components. */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --fg: #14232b;
  --muted: #566872;
  --line: #d9e1e5;
  --accent: #0d7d8a;
  --accent-fg: #ffffff;
  --accent-soft: #dff1f3;
  --good: #1a7f4b;
  --good-soft: #def3e7;
  --warn: #9a6200;
  --warn-soft: #fcefd2;
  --critical: #b3261e;
  --critical-soft: #fbe3e1;
  --info: #1d5fa8;
  --info-soft: #e0ecf9;
  --radius: 8px;
  --gutter: 16px;
  --shadow: 0 1px 2px rgba(20, 35, 43, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a20;
    --surface: #17262e;
    --surface-2: #1d2f38;
    --fg: #e6eef1;
    --muted: #93a7b0;
    --line: #2a3e48;
    --accent: #3cb6c4;
    --accent-fg: #06171b;
    --accent-soft: #14383e;
    --good: #5fd08f;
    --good-soft: #143523;
    --warn: #f0b94d;
    --warn-soft: #3d2f10;
    --critical: #ff8a80;
    --critical-soft: #43201d;
    --info: #7fb4f0;
    --info-soft: #17304d;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1a20;
  --surface: #17262e;
  --surface-2: #1d2f38;
  --fg: #e6eef1;
  --muted: #93a7b0;
  --line: #2a3e48;
  --accent: #3cb6c4;
  --accent-fg: #06171b;
  --accent-soft: #14383e;
  --good: #5fd08f;
  --good-soft: #143523;
  --warn: #f0b94d;
  --warn-soft: #3d2f10;
  --critical: #ff8a80;
  --critical-soft: #43201d;
  --info: #7fb4f0;
  --info-soft: #17304d;
  --shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }
a:hover { text-decoration: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.num, table, .stat-value { font-variant-numeric: tabular-nums; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.skip-link {
  position: absolute; left: var(--gutter); top: -48px; z-index: 100;
  background: var(--accent); color: var(--accent-fg); padding: 8px 12px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

/* Header and nav */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 8px var(--gutter);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; }
.brand-sub { font-weight: 500; font-size: 0.7rem; color: var(--muted); letter-spacing: 0.08em; margin-left: 2px; }
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; }
.nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius);
  white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.who { color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-form { display: inline; margin: 0; }
@media (max-width: 760px) {
  .nav { order: 3; flex: 0 0 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .who { display: none; }
}

.main { max-width: 1240px; margin: 0 auto; padding: 20px var(--gutter) 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Flash and toast */
.flash-region { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter); }
.flash, .callout {
  padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--info-soft); color: var(--fg); margin: 12px 0 0;
}
.callout { margin: 0 0 16px; border-left-width: 4px; }
.callout-info { border-left-color: var(--info); background: var(--info-soft); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout-critical { border-left-color: var(--critical); background: var(--critical-soft); }
.toasts { position: fixed; right: var(--gutter); bottom: var(--gutter); display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 2 * var(--gutter)); }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }

/* Layout components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.6rem; font-weight: 650; line-height: 1.2; }
.stat-sub { color: var(--muted); font-size: 0.82rem; }
.stat-good .stat-value { color: var(--good); }
.stat-warn .stat-value { color: var(--warn); }
.stat-critical .stat-value { color: var(--critical); }
.empty { text-align: center; padding: 40px 16px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
.empty-title { font-weight: 600; margin-bottom: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th.num, td.num { text-align: right; }

/* Pills, badges */
.pill {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap; line-height: 1.6;
}
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-critical { background: var(--critical-soft); color: var(--critical); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-neutral { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.badge {
  display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 999px; text-align: center;
  font-size: 0.72rem; font-weight: 700; background: var(--surface-2); color: var(--fg); line-height: 1.6;
}
.badge-nav { background: var(--critical); color: #fff; margin-left: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  min-height: 36px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { background: var(--critical); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); }
.btn-sm { padding: 3px 10px; min-height: 28px; font-size: 0.85rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* Forms */
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 7px 10px; width: 100%; max-width: 100%; min-height: 36px;
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; }
input:invalid:not(:placeholder-shown), textarea:invalid:not(:placeholder-shown), [aria-invalid="true"] { border-color: var(--critical); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field-help { color: var(--muted); font-size: 0.82rem; margin: 0; }
.field-error { color: var(--critical); font-size: 0.85rem; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters > * { flex: 0 1 180px; min-width: 120px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button {
  padding: 8px 14px; color: var(--muted); text-decoration: none; border: 0; background: none; font: inherit;
  border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer;
}
.tabs a[aria-current="page"], .tabs [aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline > li { position: relative; padding: 0 0 16px 16px; }
.timeline > li::before {
  content: ""; position: absolute; left: -26px; top: 4px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
}
.timeline > li[data-channel="email"]::before { border-color: var(--accent); }
.timeline > li[data-channel="linkedin"]::before { border-color: var(--info); }
.timeline > li[data-channel="system"]::before { border-color: var(--muted); }
.timeline .meta { color: var(--muted); font-size: 0.82rem; }

/* Key/value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: 8px; } }

/* Funnel: set --w (0-100%) on each .funnel-bar */
.funnel { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 10px; }
.funnel-label { color: var(--muted); font-size: 0.88rem; }
.funnel-track { background: var(--surface-2); border-radius: 4px; height: 20px; overflow: hidden; }
.funnel-bar { width: var(--w, 0%); height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.funnel-value { text-align: right; font-variant-numeric: tabular-nums; }

/* Merge-field diff */
.diff { white-space: pre-wrap; font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 12px; border-radius: var(--radius); }
.hl-missing { background: var(--warn-soft); color: var(--warn); border-radius: 3px; padding: 0 3px; outline: 1px solid var(--warn); }

/* Dialog */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--fg);
  padding: 20px; max-width: min(560px, calc(100vw - 2 * var(--gutter))); width: 100%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

/* Login / error */
.login-wrap { display: flex; justify-content: center; padding: 48px 0; }
.login-card { max-width: 420px; width: 100%; text-align: center; }
.login-card .btn { margin-top: 8px; }
.error-code { font-size: 2.5rem; color: var(--muted); margin: 0; }
.legal-links { margin-top: 16px; font-size: 0.875rem; }

/* Privacy and terms */
.legal { max-width: 720px; margin: 0 auto; line-height: 1.6; }
.legal h2 { font-size: 1.1rem; margin: 24px 0 8px; }

.htmx-request { opacity: 0.7; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* == settings == */
.setting-list { list-style: none; margin: 0; padding: 0; }
.setting-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.setting-input { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.setting-input textarea, .setting-input input[type="text"] { flex: 1 1 220px; }
.setting-input fieldset { border: 0; padding: 0; margin: 0; }
.overrides { margin: 6px 0 0; padding-left: 18px; font-size: 0.85rem; }
.switch { display: inline-flex; gap: 6px; align-items: center; margin-right: 12px; }
.safety-form h3 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.persona { margin-bottom: 16px; }
/* == end settings == */
