:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --ink: #1b1f27;
  --ink-2: #5a6372;
  --line: #d9dde4;
  --accent: #0f6cbd;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --error-bg: #fbeaea;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --s-contact: #66707f;
  --s-prospect: #0f6cbd;
  --s-warm: #c46a00;
  --s-client: #1a7f4b;
  --test: #f0b429;
  --test-bg: #fff4d6;
  --test-ink: #6b4e00;
  --shadow: 0 1px 2px rgb(20 25 35 / 10%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e;
    --surface: #1f232b;
    --surface-2: #2a2f39;
    --ink: #eceff4;
    --ink-2: #a2abb9;
    --line: #363c47;
    --accent: #4aa3e8;
    --accent-ink: #08131f;
    --danger: #f2877f;
    --error-bg: #3c2020;
    --warn-bg: #3a2f10;
    --warn-ink: #f2d98a;
    --s-contact: #98a2b1;
    --s-prospect: #4aa3e8;
    --s-warm: #eda04a;
    --s-client: #4cc38a;
    --test: #f0b429;
    --test-bg: #3a2f10;
    --test-ink: #f2d98a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 600; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }

.link { padding: 0; border: 0; background: none; color: var(--accent); text-align: left; text-decoration: underline; cursor: pointer; }
.link.strong { font-weight: 600; text-decoration: none; }
.link.strong:hover { text-decoration: underline; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
textarea { resize: vertical; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.field-link { font-weight: 400; }

.lede { margin: 4px 0 14px; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 13px; }

.msg { margin-bottom: 12px; padding: 9px 12px; border-radius: 6px; background: var(--surface-2); }
.msg.error { background: var(--error-bg); color: var(--danger); }
.msg.warn { display: flex; flex-wrap: wrap; gap: 4px 10px; background: var(--warn-bg); color: var(--warn-ink); }

/* ---------------------------------------------------------------- header */

.brand { font-size: 17px; font-weight: 700; letter-spacing: .04em; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.search { flex: 1 1 220px; max-width: 460px; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.page { max-width: 1500px; margin: 0 auto; padding: 16px 20px 40px; }

/* ---------------------------------------------------------------- stage colors */

.stage-all { --stage: var(--ink-2); }
.stage-contact { --stage: var(--s-contact); }
.stage-prospect { --stage: var(--s-prospect); }
.stage-warm { --stage: var(--s-warm); }
.stage-client { --stage: var(--s-client); }

/* ---------------------------------------------------------------- tiles */

.bar { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.tiles { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 8px; }

.tile {
  display: flex;
  flex: 0 1 132px;
  flex-direction: column;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--stage);
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.tile:hover { background: var(--surface-2); }
.tile.on { border-color: var(--stage); box-shadow: inset 0 0 0 1px var(--stage); }
.tile-count { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-label { color: var(--ink-2); font-size: 13px; }

.view-toggle { display: inline-flex; align-self: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.toggle { min-height: 36px; padding: 4px 14px; border: 0; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.toggle.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- board */

/* Columns stretch to the tallest one, so a card from far down a long column still has somewhere to land. */
.board { display: grid; align-items: stretch; gap: 12px; }
.board.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.board.cols-1 { grid-template-columns: minmax(0, 520px); }

.column { min-height: 140px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.column.drop { border-color: var(--stage); box-shadow: inset 0 0 0 1px var(--stage); }
.column-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding-left: 8px; border-left: 3px solid var(--stage); font-size: 14px; font-weight: 600; }
.count { color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.column-empty { margin: 14px 0; color: var(--ink-2); font-size: 13px; text-align: center; }

.card {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}
.card:hover { border-color: var(--stage); }
.card:last-child { margin-bottom: 0; }
.card-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.card-sub { display: block; font-size: 13px; overflow-wrap: anywhere; }
.card-sub.dim { color: var(--ink-2); }

/* ---------------------------------------------------------------- list */

.table-wrap { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.stage-select { width: auto; min-width: 118px; min-height: 34px; padding: 4px 8px; }

.empty { padding: 56px 20px; border: 1px dashed var(--line); border-radius: 8px; text-align: center; }
.empty p { color: var(--ink-2); }

/* ---------------------------------------------------------------- dialogs */

.dlg {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.dlg::backdrop { background: rgb(10 14 20 / 50%); }
.dlg h2 { margin-bottom: 4px; font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.dlg #contact-form > h2 { margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }

.photo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.preview { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.preview img { max-width: 240px; max-height: 150px; border: 1px solid var(--line); border-radius: 6px; }

/* ---------------------------------------------------------------- page links */

.nav { display: flex; gap: 4px; }
.nav-link { padding: 6px 10px; border-radius: 6px; color: var(--ink-2); font-weight: 500; text-decoration: none; white-space: nowrap; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- the hourglass */

.card-name { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.name-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.seq-badges { display: inline-flex; flex: none; gap: 4px; }
.seq-icon { font-size: 15px; line-height: 1.3; cursor: help; }
.seq-icon.paused { opacity: .5; }
.seq-icon.replied { color: var(--s-client); }
.tip { position: fixed; z-index: 50; max-width: min(320px, calc(100vw - 16px)); padding: 7px 10px; border-radius: 6px; background: var(--ink); color: var(--bg); font-size: 13px; line-height: 1.35; pointer-events: none; }
.seq-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }

/* ---------------------------------------------------------------- email sequences */

.tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab { min-height: 42px; margin-bottom: -1px; padding: 8px 14px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--ink-2); font-weight: 500; cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab.on { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.tab-count { margin-left: 2px; padding: 0 7px; border-radius: 10px; background: var(--surface-2); font-size: 12px; font-variant-numeric: tabular-nums; }

.btn.small { min-height: 32px; padding: 3px 10px; font-size: 13px; }
.btn.test-btn { background: var(--test); border-color: var(--test); color: #1b1200; }
.btn.send { background: var(--danger); border-color: var(--danger); color: var(--accent-ink); }
.btn.send:disabled, .btn.test-btn:disabled { opacity: .55; }
.confirm-dlg:not(.live) .btn.send { background: var(--test); border-color: var(--test); color: #1b1200; }
.danger-text { color: var(--danger); }
.center { text-align: center; }

.table .cell-sub, .cell-sub { display: block; color: var(--ink-2); font-size: 13px; overflow-wrap: anywhere; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { margin-left: 6px; }
.row-off td { color: var(--ink-2); }
.check-cell { width: 40px; }
.check-cell input { width: 18px; min-height: 18px; height: 18px; display: block; margin: 0; }
.cell-note { font-size: 13px; }
.reply-subject { overflow-wrap: anywhere; }

.pill { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 10px; font-size: 12px; font-weight: 600; vertical-align: 1px; }
.pill.test { background: var(--test-bg); color: var(--test-ink); }
.pill.auto { background: var(--surface-2); color: var(--ink-2); }

.start-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 12px; }
.field.inline { flex: 0 1 380px; margin: 0; min-width: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-weight: 500; cursor: pointer; }
.switch.on { border-color: var(--test); background: var(--test-bg); color: var(--test-ink); }
.switch input { width: 18px; min-height: 18px; height: 18px; margin: 0; padding: 0; }
.msg.test-banner { background: var(--test-bg); color: var(--test-ink); }
.msg.live-banner { background: var(--error-bg); color: var(--danger); font-weight: 600; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }

.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.list-head h2, .panel h2 { font-size: 17px; font-weight: 600; }
.seq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; margin-bottom: 24px; }
.seq-card, .panel { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.seq-card { display: flex; flex-direction: column; }
.seq-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.seq-card h3 { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.seq-card-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px; align-items: start; }
.panel .hint { display: block; margin: 6px 0 10px; }
.blocked-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; padding: 4px 0; overflow-wrap: anywhere; }

.plan { margin: 0 0 8px; padding-left: 20px; }
.plan li { margin-bottom: 6px; overflow-wrap: anywhere; }
.who { margin: 0 0 12px; padding: 0; list-style: none; max-height: 240px; overflow-y: auto; }
.who li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.who li:last-child { border-bottom: 0; }
.dlg-sub { margin: 12px 0 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.msg.notes { display: block; margin-top: 10px; font-size: 13px; }
.confirm-dlg.live { border: 2px solid var(--danger); }
.confirm-dlg.live h2 { color: var(--danger); }
.dlg.wide { width: min(760px, calc(100vw - 24px)); }
.step { margin: 0 0 12px; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: 8px; }
.step legend { padding: 0 6px; font-weight: 600; }
.step-when { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.step-value { width: 84px; }
.step-unit { width: auto; }

/* ---------------------------------------------------------------- sign-in */

.auth-page { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.auth-card { width: min(380px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.auth-card .brand { margin-bottom: 18px; }
.code-input { font-size: 22px; letter-spacing: .3em; text-align: center; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 14px; font-size: 13px; }

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 1000px) {
  .board.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .top { padding: 10px 16px; }
  .page { padding: 12px 16px 32px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .top-actions { margin-left: 0; }
  .row-actions { white-space: normal; }
  .row-actions .btn { margin: 0 0 4px 4px; }
  .tab { padding: 8px 9px; font-size: 14px; }
  .start-bar .spacer { display: none; }
  .field.inline { flex-basis: 100%; }
  .top-actions .btn:not(.primary) { padding: 6px 10px; }
  .tile { flex: 1 1 28%; }
  .view-toggle { margin-left: auto; }
  .board.cols-4, .board.cols-1 { grid-template-columns: minmax(0, 1fr); }
  .column { min-height: 0; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .hide-narrow { display: none; }
}
