:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d2321;
  --ink-2: #4b5552;
  --muted: #6f7976;
  --line: #e2ded6;
  --line-strong: #cfcac0;
  --accent: #146356;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ec;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --warn-line: #f0d595;
  --error: #a42b22;
  --error-soft: #fbe7e4;
  --ok: #1f7a3d;
  --ok-soft: #e3f3e8;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .05);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816;
    --surface: #1c2220;
    --surface-2: #212826;
    --ink: #e9eeec;
    --ink-2: #c3cbc8;
    --muted: #93a09b;
    --line: #2f3835;
    --line-strong: #3d4844;
    --accent: #5cc2ad;
    --accent-ink: #0d1f1b;
    --accent-soft: #19332d;
    --warn: #f2c464;
    --warn-soft: #2e2614;
    --warn-line: #574519;
    --error: #ff8f84;
    --error-soft: #36191a;
    --ok: #79d496;
    --ok-soft: #16301f;
    --danger: #ff7a70;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
    --bg: #141816;
    --surface: #1c2220;
    --surface-2: #212826;
    --ink: #e9eeec;
    --ink-2: #c3cbc8;
    --muted: #93a09b;
    --line: #2f3835;
    --line-strong: #3d4844;
    --accent: #5cc2ad;
    --accent-ink: #0d1f1b;
    --accent-soft: #19332d;
    --warn: #f2c464;
    --warn-soft: #2e2614;
    --warn-line: #574519;
    --error: #ff8f84;
    --error-soft: #36191a;
    --ok: #79d496;
    --ok-soft: #16301f;
    --danger: #ff7a70;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--accent); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; fill: none; stroke: var(--accent-ink); stroke-width: 2; stroke-linejoin: round; }
.who { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: .9rem; }

.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-demo { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }

/* Layout */
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 96px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* Sign in */
.signin { display: grid; place-items: center; min-height: calc(100vh - 60px); }
.signin-card { max-width: 480px; text-align: center; padding: 36px 28px; }
.lead { color: var(--ink-2); font-size: 1.05rem; margin-bottom: 1.4em; }

/* Steps */
.steps ol { list-style: none; display: flex; gap: 6px; padding: 0; margin: 0 0 18px; flex-wrap: wrap; }
.steps li {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px;
  border-radius: 999px; color: var(--muted); font-weight: 550; font-size: .92rem;
  background: transparent; border: 1px solid transparent;
}
.steps li .num {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line-strong); font-size: .8rem;
}
.steps li.active { color: var(--ink); background: var(--surface); border-color: var(--line); }
.steps li.active .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.steps li.done { color: var(--ink-2); cursor: pointer; }
.steps li.done .num { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
@media (max-width: 600px) { .steps li .lbl { display: none; } .steps li.active .lbl { display: inline; } }

/* Buttons */
.btn {
  font: inherit; font-weight: 550; font-size: .92rem;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); border-color: var(--danger); }
.btn-link { border: none; background: none; color: var(--accent); padding: 4px 6px; text-decoration: underline; text-underline-offset: 2px; }
.btn-link:hover { background: none; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; font-size: 1.2rem; line-height: 1; }
.btn-sm { padding: 4px 10px; font-size: .82rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.sticky-actions {
  position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; margin: 0;
  justify-content: space-between; border-top: 1px solid var(--line); z-index: 10;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; border: none; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: .9rem; color: var(--ink-2); padding: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline input { width: 80px; }
input[type=text], input[type=url], input[type=email], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0 10px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 36px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  background: var(--surface-2); text-align: center; transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone svg { width: 36px; height: 36px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 6px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: .85rem; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip input { accent-color: var(--accent); margin: 0; }
.chip.on, .chip[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.chip .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.insert-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: -4px 0 14px; }

.summary-line { margin-top: 8px; padding: 12px 14px; background: var(--accent-soft); border-radius: 8px; font-weight: 550; }

/* Notices */
.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid; margin: 12px 0; text-align: left; }
.notice-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.notice-error { background: var(--error-soft); color: var(--error); border-color: var(--error); }
.notice-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

/* Progress */
.progress { width: 220px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 10px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 260px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--ink-2); background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.col-check { width: 36px; }
.col-check input, td.col-check input { width: 17px; height: 17px; accent-color: var(--accent); }
.col-actions { width: 1%; white-space: nowrap; }
.people td .sub { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.people .modules { color: var(--ink-2); font-size: .85rem; max-width: 260px; }
.people tr.unselected td { opacity: .62; }
.people tr.unselected td.col-check, .people tr.unselected td.col-actions { opacity: 1; }
.row-actions { display: flex; gap: 6px; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-ready { color: var(--ok); background: var(--ok-soft); }
.status-warn { color: var(--warn); background: var(--warn-soft); }
.status-error { color: var(--error); background: var(--error-soft); }
.status-pending { color: var(--muted); background: var(--surface-2); }
.status-sent { color: var(--accent); background: var(--accent-soft); }
.reason { display: block; color: var(--muted); font-size: .8rem; margin-top: 3px; max-width: 220px; }
.fixed-tag { font-size: .75rem; color: var(--accent); font-weight: 600; }

/* Compose */
.compose { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .compose { grid-template-columns: 1fr; } }
.preview-card { position: sticky; top: 72px; }
.preview-nav { display: flex; align-items: center; gap: 8px; }

/* Email preview */
.email {
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface);
}
.email-head { padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: .88rem; }
.email-head div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 2px 0; }
.email-head dt { color: var(--muted); }
.email-head .subj { font-weight: 650; color: var(--ink); }
.email-frame { width: 100%; border: 0; min-height: 360px; background: #fff; display: block; }
.email-warn { padding: 8px 14px; background: var(--warn-soft); color: var(--warn); font-size: .85rem; border-bottom: 1px solid var(--warn-line); }

/* Send */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.stat .n { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.send-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .send-grid { grid-template-columns: 1fr; } }
.send-box { display: flex; flex-direction: column; margin-bottom: 0; }
.send-box .btn { margin-top: auto; }
.send-box p { flex: 0; }
.send-grid + .card { margin-top: 16px; }

/* Modals */
.modal {
  border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(720px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-sm { width: min(460px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 20, 18, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.search-results { list-style: none; padding: 0; margin: 0 0 10px; max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.search-results:empty { display: none; }
.search-results li { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.search-results li:last-child { border-bottom: none; }
.search-results li:hover, .search-results li:focus { background: var(--accent-soft); outline: none; }
.search-results .sub { color: var(--muted); font-size: .82rem; }
.search-results li.note { cursor: default; color: var(--muted); }
.search-results li.note:hover { background: none; }

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 100; max-width: calc(100vw - 32px);
}

/* Section tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: .9rem; font-weight: 550; color: var(--ink-2);
  background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--accent-soft); color: var(--ink); border-color: var(--accent-soft); }
.tab-count { background: var(--warn); color: var(--surface); font-size: .72rem; font-weight: 700; padding: 0 7px; border-radius: 999px; line-height: 1.6; }
@media (max-width: 760px) { .topbar { gap: 8px; } .tabs { order: 3; width: 100%; } }

.small-check { font-size: .9rem; color: var(--ink-2); }
.small-check input[type=number] { width: 58px; padding: 2px 6px; margin: 0 2px; display: inline-block; }
.toolbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar-right .check { margin: 0; }
.actions.no-top { margin-top: 0; }
.last-sent { font-size: .85rem; white-space: nowrap; }
.last-sent .sub { display: block; }
.last-sent.recent { color: var(--warn); font-weight: 600; }
td.nowrap { white-space: nowrap; }
.people .mod + .mod { margin-top: 6px; }
.people .mod .sub { display: block; font-size: .78rem; }
.people .mod .sub.recent { color: var(--warn); font-weight: 600; }
.modules-box { margin-top: 4px; }
.modules-box legend { margin-bottom: 8px; line-height: 1.4; }
.module-table td { vertical-align: middle; }
.module-table td:first-child { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .8rem; color: var(--ink-2); overflow-wrap: anywhere; max-width: 180px; }
.module-table input { padding: 6px 8px; font-size: .88rem; min-width: 140px; }
