:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --ink: #1c2333;
  --muted: #64708a;
  --faint: #8993ab;
  --accent: #2563eb;
  --accent-soft: #eef2ff;
  --accent-soft-2: #e0e7ff;
  --line: #e3e6ee;
  --line-strong: #cbd2e0;
  --good: #15803d;
  --good-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fffaeb;
  --critical: #b91c1c;
  --critical-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(28, 35, 51, 0.06), 0 1px 8px rgba(28, 35, 51, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1a1d29;
    --surface-2: #20232f;
    --ink: #e7e9f2;
    --muted: #9aa3bd;
    --faint: #6b7290;
    --accent: #6d8dff;
    --accent-soft: #202a4d;
    --accent-soft-2: #28345c;
    --line: #2b2f42;
    --line-strong: #3a3f57;
    --good: #4ade80;
    --good-soft: #12291d;
    --warn: #fbbf24;
    --warn-soft: #2e2410;
    --critical: #f87171;
    --critical-soft: #341717;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}
main { max-width: 900px; margin: 2rem auto; padding: 0 1rem 3rem; }
main.wide { max-width: 1200px; }
main.narrow { max-width: 560px; }

h1, h2, h3 { font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif; font-weight: 400; color: var(--ink); margin: 0; }
h1 { font-size: 1.15rem; }
h1 small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
h2 { font-size: 0.98rem; margin-bottom: 0.7rem; }

/* ---- top nav ---- */
header.app-header { background: var(--surface); padding: 0.9rem 1.5rem; box-shadow: var(--shadow); display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
header.app-header .brand { font-weight: 700; font-family: Georgia, serif; }
header.app-header .nav-collapse { display: flex; align-items: center; gap: 1.5rem; flex: 1; flex-wrap: wrap; }
header.app-header nav { display: flex; gap: 1.1rem; flex: 1; flex-wrap: wrap; }
header.app-header nav a { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
header.app-header nav a.active { color: var(--accent); font-weight: 600; }
header.app-header .user-menu { display: flex; align-items: center; gap: 0.9rem; font-size: 0.82rem; color: var(--muted); }
header.app-header .user-menu a, header.app-header .user-menu button { font: inherit; color: var(--accent); background: none; border: none; cursor: pointer; text-decoration: none; padding: 0; }
header.app-header .nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 6px; font-size: 1.1rem; line-height: 1; padding: 0.3rem 0.55rem; color: var(--ink); cursor: pointer; }

@media (max-width: 720px) {
  header.app-header { gap: 0.75rem; }
  header.app-header .nav-toggle { display: block; }
  header.app-header .nav-collapse { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0.9rem; }
  header.app-header .nav-collapse.open { display: flex; }
  header.app-header nav { flex-direction: column; gap: 0.7rem; }
  header.app-header .user-menu { flex-direction: column; align-items: flex-start; gap: 0.6rem; padding-top: 0.6rem; border-top: 1px solid var(--line); }
}

/* ---- layout ---- */
.card { background: var(--surface); padding: 1.5rem; border-radius: 8px; box-shadow: var(--shadow); margin-bottom: 1.2rem; }
.card:last-child { margin-bottom: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.shell { display: grid; grid-template-columns: 11rem 1fr; gap: 1.5rem; }
.settings-nav, .filters { display: flex; flex-direction: column; gap: 0.15rem; }
.settings-nav .grp, .filters .grp { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin: 0.8rem 0 0.3rem; }
.settings-nav .grp:first-child, .filters .grp:first-child { margin-top: 0; }
.settings-nav a { color: var(--muted); text-decoration: none; font-size: 0.85rem; padding: 0.35rem 0.5rem; border-radius: 5px; }
.settings-nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.subtabs { display: flex; gap: 0.3rem; margin-bottom: 1rem; }
.subtabs a { color: var(--muted); text-decoration: none; font-size: 0.85rem; padding: 0.4rem 0.9rem; border-radius: 6px; }
.subtabs a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.breadcrumb { font-size: 0.72rem; color: var(--faint); margin: 0 0 0.6rem; }
.breadcrumb .sep { margin: 0 0.35rem; }
.filters label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; padding: 0.2rem 0; }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label, label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
label { display: block; margin-bottom: 0.25rem; }
.field label { margin-bottom: 0; }
input, select, textarea {
  font: inherit; font-size: 0.85rem; padding: 0.42rem 0.55rem;
  border: 1px solid var(--line-strong); border-radius: 5px;
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 4.5rem; resize: vertical; font-family: inherit; }
.search-input { min-width: 15rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.grid .span2 { grid-column: 1 / -1; }
.grid input, .grid select, .grid textarea { width: 100%; }
.filters select { width: 100%; }
.actions { margin-top: 1.2rem; display: flex; gap: 0.6rem; }
.error { color: var(--critical); font-size: 0.85rem; margin-bottom: 1rem; }
.success { color: var(--good); font-size: 0.85rem; margin-bottom: 1rem; }

/* ---- buttons ---- */
button, .btn {
  font: inherit; font-size: 0.8rem; font-weight: 600; padding: 0.45rem 0.8rem;
  border-radius: 6px; border: 1px solid transparent; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-danger { color: var(--critical); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
form.inline { display: inline; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
th { text-align: left; font-size: 0.7rem; text-transform: uppercase; color: var(--faint); padding: 0.5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td a { color: var(--accent); text-decoration: none; }
.scroll { overflow-x: auto; }

/* ---- pills / status ---- */
.pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.5rem; border-radius: 99px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
a.pill { text-decoration: none; cursor: pointer; }
.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-accent { background: var(--accent-soft); color: var(--accent); }
.pill-action { background: var(--warn-soft); color: var(--warn); }
.pill-timing, .pill-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.muted { color: var(--faint); }
.faint { color: var(--faint); font-size: 0.8rem; }
.warn-text { color: var(--warn); font-size: 0.78rem; }

/* ---- guidance: banner + hint ---- */
.guide-banner { background: var(--accent-soft); border: 1px solid var(--accent-soft-2); border-radius: 8px; padding: 0.75rem 0.9rem; display: flex; gap: 0.65rem; align-items: flex-start; margin-bottom: 1rem; }
.guide-banner .gi { flex-shrink: 0; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--accent); color: #fff; font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.guide-banner .gt { flex: 1; font-size: 0.79rem; color: var(--ink); }
.guide-banner .gt b { display: block; font-size: 0.82rem; margin-bottom: 0.1rem; }
.guide-banner .gx { color: var(--accent); font-size: 0.72rem; cursor: pointer; flex-shrink: 0; background: none; border: none; font-family: inherit; padding: 0; }
.help-fab { width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font-size: 0.72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; float: right; }
.hint { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; border-radius: 50%; background: var(--line-strong); color: var(--surface); font-size: 0.62rem; font-weight: 700; cursor: help; margin-left: 0.3rem; }

/* ---- toast ---- */
.toast { display: flex; align-items: center; gap: 0.6rem; background: var(--good-soft); border: 1px solid var(--good); color: var(--good); border-radius: 6px; padding: 0.6rem 0.9rem; font-size: 0.85rem; margin-bottom: 1rem; }
.token-reveal { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 5px; padding: 0.5rem 0.7rem; margin-top: 0.5rem; word-break: break-all; user-select: all; color: var(--ink); }

/* ---- cards: stats, modal ---- */
.stat-strip { display: flex; gap: 0.7rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 0.5rem 0.85rem; min-width: 7rem; }
.stat .n { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }
a.stat { display: block; text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--accent); }
.modal { border: 1px dashed var(--line-strong); border-radius: 8px; padding: 1rem; margin-top: 1.2rem; background: var(--surface-2); }

/* ---- day-grouped timeline (Lead Detail + Activity) ---- */
.day-group { margin-bottom: 1rem; }
.day-group:last-child { margin-bottom: 0; }
.day-head { font-weight: 700; font-size: 0.78rem; background: var(--surface-2); border: 1px solid var(--line); border-bottom: none; border-radius: 7px 7px 0 0; padding: 0.4rem 0.8rem; }
.day-entries { border: 1px solid var(--line); border-radius: 0 0 7px 7px; }
.day-entry { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); font-size: 0.83rem; }
.day-entry:last-child { border-bottom: none; }
.day-entry .who { font-size: 0.72rem; color: var(--muted); }
.day-entry .time { color: var(--faint); font-size: 0.74rem; float: right; }
.day-entry .msg { margin-top: 0.4rem; font-size: 0.8rem; white-space: pre-wrap; background: var(--surface-2); border-left: 3px solid var(--accent); padding: 0.55rem 0.75rem; border-radius: 4px; }
.upcoming { border: 1px dashed var(--accent-soft-2); background: var(--accent-soft); border-radius: 8px; padding: 0.65rem 0.9rem; margin-bottom: 1rem; font-size: 0.85rem; }
.upcoming .lbl { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); font-weight: 700; margin-bottom: 0.3rem; }

/* ---- campaign step cards ---- */
.step { border: 1px solid var(--line); border-radius: 8px; padding: 0.8rem 1rem; margin-bottom: 0.8rem; }
.step:last-child { margin-bottom: 0; }
.step-head { display: flex; align-items: center; gap: 0.6rem; }
.step-order { width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.75rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.step-tag { font-weight: 700; font-size: 0.9rem; flex: 1; }
.step-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 0.6rem; }
.step-actions { margin-top: 0.6rem; display: flex; align-items: center; gap: 0.8rem; font-size: 0.78rem; }
.message-box { border: 1px solid var(--line-strong); border-left: 3px solid var(--accent); border-radius: 6px; padding: 0.65rem 0.85rem; background: var(--surface-2); font-size: 0.85rem; line-height: 1.6; white-space: pre-wrap; }
.message-box + .stat-strip, .message-box + .toolbar { margin-top: 1rem; }
.media-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.55rem; font-size: 0.8rem; }
.media-row a { color: var(--accent); }
.fmt-toolbar { display: flex; gap: 0.35rem; margin-bottom: 0.4rem; }
.fmt-toolbar button {
  width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  border-radius: 5px; font-size: 0.82rem; cursor: pointer; padding: 0;
}
.fmt-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.char-count { text-align: right; font-size: 0.7rem; color: var(--faint); margin-top: 0.2rem; }
.current-media { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }

/* ---- export / track calls ---- */
.step-context { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.sc-box { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 0.65rem 0.85rem; background: var(--surface-2); font-size: 0.85rem; }
.sc-box.current { background: var(--accent-soft); border-color: var(--accent-soft-2); }
.sc-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin-bottom: 0.2rem; }
.sc-box.current .sc-label { color: var(--accent); }
.row-check { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 7px; margin-bottom: 0.4rem; }
.row-check:last-child { margin-bottom: 0; }
.row-check .rc-main { flex: 1; font-size: 0.85rem; }
.row-check .rc-sub { font-size: 0.74rem; color: var(--muted); }
.row-check .rc-main a { color: var(--accent); text-decoration: none; font-weight: 600; }
.progress-bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 1rem; }
.progress-bar > div { height: 100%; background: var(--good); }

/* ---- send queue ---- */
.toggle-row { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; margin-bottom: 1rem; }
.toggle-row button { border: none; border-radius: 0; background: var(--surface); padding: 0.4rem 0.8rem; font-size: 0.78rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.toggle-row button.active { background: var(--accent); color: #fff; }
.bucket { margin-bottom: 1.1rem; }
.bucket:last-child { margin-bottom: 0; }
.bucket-head { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.5rem; }
.bucket-head.today { color: var(--accent); }
.bucket-head.overdue { color: var(--critical); }
.queue-item { display: flex; align-items: center; gap: 0.8rem; padding: 0.65rem 0.85rem; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); margin-bottom: 0.5rem; }
.queue-item:last-child { margin-bottom: 0; }
.queue-item.today { border-color: var(--accent); background: var(--accent-soft); }
.queue-item.overdue { border-color: var(--critical); background: var(--critical-soft); }
.queue-item .qcamp { font-weight: 700; font-size: 0.85rem; }
.queue-item .qstepline { color: var(--muted); font-size: 0.76rem; margin-top: 0.1rem; }
.queue-item .qcount { text-align: right; margin-right: 0.3rem; min-width: 4.5rem; }
.queue-item .qcount .n { font-weight: 700; font-variant-numeric: tabular-nums; }
.queue-item .qcount .l { font-size: 0.66rem; color: var(--faint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; font-size: 0.72rem; }
.cal-grid .cal-dow { text-align: center; color: var(--faint); font-size: 0.66rem; text-transform: uppercase; padding-bottom: 0.3rem; }
.cal-cell { border: 1px solid var(--line); border-radius: 5px; min-height: 3.4rem; padding: 0.3rem; background: var(--surface-2); }
.cal-cell.blank { border: none; background: transparent; }
.cal-cell.is-today { border-color: var(--accent); background: var(--accent-soft); }
.cal-cell.is-past { opacity: 0.5; }
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover { border-color: var(--accent); }
.cal-cell.selected { border-color: var(--accent); border-width: 2px; }
.cal-cell .cd { color: var(--faint); font-size: 0.68rem; }
.cal-cell .ctask { margin-top: 0.2rem; font-size: 0.64rem; background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0.05rem 0.25rem; display: inline-block; }
.cal-cell.is-today .ctask { background: var(--accent); color: #fff; }

/* ---- leads selection bar ---- */
.selection-bar { display: flex; align-items: center; gap: 0.9rem; background: var(--accent-soft); border-radius: 7px; padding: 0.55rem 0.9rem; margin-bottom: 0.9rem; font-size: 0.82rem; flex-wrap: wrap; }
.selection-bar .sel-count { font-weight: 600; }

/* ---- lead / business detail field grid ---- */
.field-grid, .field-grid-full { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem 1rem; font-size: 0.83rem; margin-bottom: 1.1rem; }
.field-grid .fk, .field-grid-full .fk { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.field-grid .fv, .field-grid-full .fv { margin-top: 0.1rem; }
.enroll-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.75rem; border: 1px solid var(--line); border-radius: 7px; margin-bottom: 0.4rem; font-size: 0.85rem; }
.enroll-row:last-child { margin-bottom: 0; }

/* ---- auth pages (no nav, centered card) ---- */
.auth-shell { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-shell form { background: var(--surface); padding: 2rem; border-radius: 8px; box-shadow: var(--shadow); width: 320px; }
.auth-shell h1 { font-size: 1.25rem; margin: 0 0 1.25rem; }
.auth-shell input { width: 100%; margin-bottom: 1rem; }
.auth-shell button { width: 100%; justify-content: center; }
.auth-shell a { display: block; margin-top: 1rem; font-size: 0.85rem; text-align: center; color: var(--accent); }

/* ---- definition list summaries (import/report summaries) ---- */
dl { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; margin: 0; font-size: 0.85rem; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 600; }

/* ---- pagination ---- */
.pagination-bar, .pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 0.8rem; font-size: 0.8rem; color: var(--muted); }
.pagination-bar a, .pagination a { color: var(--accent); text-decoration: none; margin: 0 0.2rem; }

/* ---- mobile: Send Queue ---- */
@media (max-width: 720px) {
  main { padding: 0 0.6rem 2rem; }
  .card { padding: 1rem; }
  .queue-item { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .queue-item .qcount { text-align: left; margin-right: 0; }
  .queue-item .btn { justify-content: center; width: 100%; }
  .cal-grid { gap: 3px; font-size: 0.66rem; }
  .cal-cell { min-height: 2.6rem; padding: 0.2rem; }
  .cal-cell .ctask { font-size: 0.58rem; padding: 0.05rem 0.2rem; }

  /* ---- mobile: Track Calls (row-check tap targets) ---- */
  .row-check { flex-wrap: wrap; }
  .row-check .btn-sm { min-height: 44px; padding: 0.5rem 0.9rem; }

  /* ---- mobile: sidebar + content shell (settings, activity) ---- */
  .shell { display: block; }
  .settings-nav, .filters { margin-bottom: 1rem; }
}

/* ---- help / user guide (rendered from docs/USER_GUIDE.md) ---- */
.markdown-body { max-width: 760px; line-height: 1.6; }
.markdown-body h1 { font-size: 1.5rem; margin: 0 0 1rem; }
.markdown-body h2 { font-size: 1.15rem; margin: 1.75rem 0 0.6rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.markdown-body h2:first-of-type { border-top: none; padding-top: 0; }
.markdown-body h3 { font-size: 1rem; margin: 1.2rem 0 0.4rem; }
.markdown-body p, .markdown-body ul, .markdown-body ol { margin: 0 0 0.8rem; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4rem; }
.markdown-body li { margin-bottom: 0.3rem; }
.markdown-body a { color: var(--accent); }
.markdown-body code { background: var(--accent-soft); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.85em; }
.markdown-body hr { border: none; border-top: 1px solid var(--line); margin: 1.5rem 0; }
