:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --bad: #b42318;
  --warn: #9a6700;
  --ok-bg: #e7f6ee;
  --bad-bg: #fdecea;
  --warn-bg: #fff6dd;
  --info-bg: #eaf0fd;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--text); letter-spacing: -.01em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .sidebar nav .soon {
  padding: 7px 10px; border-radius: 6px; color: var(--text);
}
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { background: var(--info-bg); color: var(--accent); font-weight: 600; }
.sidebar nav .soon { color: #a7adb8; cursor: default; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.content { flex: 1; padding: 28px 32px; max-width: 1150px; min-width: 0; }

/* Auth pages */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px;
}
.auth-card .brand { margin-bottom: 18px; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.narrow { max-width: 520px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  font: inherit; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; align-self: flex-start;
}
button:hover { background: var(--bg); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

/* Messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }
.flash-info { background: var(--info-bg); color: var(--accent); }
.notice {
  background: var(--warn-bg); border: 1px solid #f1dfa6; border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 20px;
}
.gdpr {
  margin-top: 48px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--muted);
}

/* Cards and panels */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.card, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.panel { margin-bottom: 20px; }
.panel h2 { margin-top: 0; }
.card-label { color: var(--muted); font-size: .85rem; }
.card-value { font-size: 1.25rem; font-weight: 600; margin: 4px 0; }
.card-value.ok { color: var(--ok); }
.card-value.bad { color: var(--bad); }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-info { background: var(--info-bg); color: var(--accent); }
.badge-warning { background: var(--warn-bg); color: var(--warn); }
.badge-error { background: var(--bad-bg); color: var(--bad); }
.filters { margin-bottom: 12px; display: flex; gap: 6px 12px; align-items: center; flex-wrap: wrap; }
.filters a.active { font-weight: 700; text-decoration: underline; }

/* Phase 2: mailboxes */
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .5rem; }
a.button, .button {
  display: inline-block; font: inherit; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
a.button:hover { background: var(--bg); text-decoration: none; }
a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
a.button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.danger-zone { border-color: #f3c3bd; }
.small-btn { padding: 3px 10px; font-size: .85rem; }
form.inline { display: inline; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { max-width: 320px; }
.row-actions { display: flex; gap: 12px; align-items: center; margin: 12px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 2fr; gap: 14px; margin-top: 12px; }
.field-error { color: var(--bad); font-size: .85rem; font-weight: 400; }
details summary { cursor: pointer; font-weight: 600; }
fieldset.days { border: 0; padding: 0; margin: 0; display: flex; gap: 14px; flex-wrap: wrap; }
fieldset.days legend { width: 100%; margin-bottom: 4px; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: #eef0f3; color: var(--muted); }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.error-row td { background: var(--bad-bg); color: var(--bad); font-size: .85rem; }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; }
a.card.choice { color: var(--text); display: block; }
a.card.choice:hover { border-color: var(--accent); text-decoration: none; }
code.record { display: block; margin-top: 4px; white-space: pre-wrap; word-break: break-all; font-size: .78rem; }
code.copy { user-select: all; }
.guide ol li, .guide ul li { margin-bottom: 6px; }
.test-result .flash { margin-bottom: 8px; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
#test-spinner.htmx-request, #send-spinner.htmx-request, #dns-spinner.htmx-request { display: inline; }

/* Phase 3: contacts */
.filters-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.filters-bar input[type=search] { max-width: 320px; }
.filters-bar select { width: auto; }
.bulk-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
input.short, select.short { width: auto; max-width: 180px; padding: 4px 8px; }
input[type=search] { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; width: 100%; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; background: #eef0f3; border-radius: 999px;
  padding: 1px 9px; margin: 1px 3px 1px 0; font-size: .8rem; white-space: nowrap;
}
.tag-x { font-size: 1rem; line-height: 1; color: var(--muted); }
.pager { display: flex; gap: 16px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.push-right { margin-left: auto; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.custom-fields { display: flex; flex-direction: column; gap: 8px; }
.table-wrap { overflow-x: auto; }
.mapping td { vertical-align: middle; }
.mapping select { min-width: 220px; }
.examples div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.progress { height: 12px; background: #eef0f3; border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-bar { height: 100%; background: var(--accent); transition: width .3s; }
button.small-btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }

.contact-details > td { background: var(--bg); }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 18px; margin: 4px 0 10px; }
.facts-grid dt { color: var(--muted); font-size: .75rem; }
.facts-grid dd { margin: 0; font-size: .88rem; overflow-wrap: anywhere; }
.facts-grid .wide { grid-column: 1 / -1; }

/* Phase 4: templates */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.preview-col { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; }
.preview-col .panel { margin-bottom: 0; }
textarea.mono-ish { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9rem; line-height: 1.5; }
.merge-fields { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-weight: 500; }
.toolbar {
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding: 4px;
  border: 1px solid var(--border); border-bottom: 0; border-radius: 6px 6px 0 0; background: var(--bg);
}
.toolbar + textarea { border-top-left-radius: 0; border-top-right-radius: 0; }
.tool { padding: 3px 10px; font-size: .85rem; background: var(--surface); }
.tool-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tool-hint { margin-left: 6px; }
.chip { padding: 2px 9px; font-size: .8rem; border-radius: 999px; background: var(--info-bg); color: var(--accent); border-color: transparent; }
.chip-custom { background: #eef0f3; color: var(--text); }
fieldset.format { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.help ul { margin: 8px 0 0; padding-left: 20px; }
.help li { margin-bottom: 6px; }
.attachments { list-style: none; padding: 0; margin: 0 0 12px; }
.attachments li { padding: 4px 0; }
.email-preview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.email-head { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: .88rem; display: flex; flex-direction: column; gap: 2px; }
.email-subject { font-weight: 700; font-size: 1.05rem; margin-top: 6px; }
.email-body { padding: 16px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.5; }
.email-body .plain { white-space: pre-wrap; }
.email-body p { margin: 0 0 1em; }
.email-body .signature { margin-top: 1em; }
.flash-warning { background: var(--warn-bg); color: var(--warn); }

/* Phase 5: campaigns */
.step-row {
  display: grid; grid-template-columns: 36px auto minmax(180px, 1fr) minmax(180px, 1fr) auto; gap: 12px;
  align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.step-row label { font-weight: 400; font-size: .85rem; }
.step-no {
  width: 28px; height: 28px; border-radius: 50%; background: var(--info-bg); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.add-step .step-no { background: #eef0f3; color: var(--muted); }
.step-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
input.tiny { width: 64px; padding: 4px 6px; }
.plain-fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.plain-fieldset legend { font-weight: 600; margin-bottom: 6px; }
ul.tight { margin: 6px 0 0; padding-left: 20px; }
.summary-line { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; }
.enrollment { padding: 8px 0; border-bottom: 1px solid var(--border); }
.enrollment:last-child { border-bottom: 0; }
.plain { white-space: pre-wrap; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
button[disabled] { opacity: .5; cursor: not-allowed; }

.hours { display: flex; flex-direction: column; gap: 6px; }
.hours-row { display: flex; align-items: center; gap: 10px; }
.hours-row .check { width: 76px; }
.hours-row input[type=time] { width: auto; font: inherit; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; }

/* Phase 6: inbox */
.sidebar nav .count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent);
  color: #fff; font-size: .75rem; text-align: center; margin-left: 4px;
}
table.inbox tr.unread td { background: #fafbff; }
table.inbox tr.unread strong { color: var(--text); }
.snippet { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-buttons { display: flex; gap: 4px; flex-wrap: wrap; }
.label-buttons button.on.label-interested { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.label-buttons button.on.label-not_interested { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.label-buttons button.on.label-later { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }

/* Phase 7: dashboard */
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table.compact td, .table.compact th { padding: 4px 10px; }
.meter { height: 6px; background: #eef0f3; border-radius: 999px; overflow: hidden; margin: 6px 0 4px; }
.meter > div { height: 100%; background: var(--accent); border-radius: 999px; }
.meter-cell { min-width: 150px; }
.meter-cell .meter { margin-top: 2px; }
.barchart { display: flex; align-items: stretch; gap: 2px; height: 170px; padding-top: 8px; border-bottom: 1px solid var(--border); }
.bar-col { flex: 1; display: flex; flex-direction: column; position: relative; outline: none; }
.bar-area { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 70%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-col:hover .bar, .bar-col:focus .bar { filter: brightness(1.15); }
.bar-col:hover .bar-area, .bar-col:focus .bar-area { background: rgba(47, 91, 211, .06); border-radius: 4px; }
.bar-label { text-align: center; font-size: .72rem; color: var(--muted); padding: 4px 0 2px; }
.bar-label.weekend { color: #b3b8c2; }
.bar-tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, 4px); z-index: 5;
  background: var(--text); color: #fff; font-size: .78rem; padding: 6px 9px; border-radius: 6px;
  white-space: nowrap; pointer-events: none; line-height: 1.35;
}
.bar-col:hover .bar-tip, .bar-col:focus .bar-tip { display: block; }
.reply-row { padding: 7px 0; border-bottom: 1px solid var(--border); }
.reply-row:last-child { border-bottom: 0; }
.export-list { margin: 0; padding-left: 20px; }
.export-list li { margin-bottom: 8px; }
.error-page { max-width: 560px; margin: 40px auto; text-align: center; }

@media (max-width: 960px) {
  .two-col, .editor { grid-template-columns: 1fr; }
  .step-row { grid-template-columns: 36px 1fr; }
  .preview-col { position: static; }
}

@media (max-width: 760px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 20px 16px; }
  .table { display: block; overflow-x: auto; }
  .barchart { height: 130px; }
}
