:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #16202c;
  --muted: #6b7a8d;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-dark: #1e3a8a;
  --teal: #0f766e;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }

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

a { color: var(--brand); }

/* ---------------- layout ---------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 20px 18px 16px; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  background: var(--brand); color: #fff; font-weight: 700; font-size: 12px;
  letter-spacing: .06em; padding: 5px 8px; border-radius: 6px;
}
.brand-name { color: #f1f5f9; font-weight: 600; font-size: 14px; }

.sidebar nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #cbd5e1; text-decoration: none; padding: 9px 12px; border-radius: 7px; font-size: 14px;
}
.sidebar nav a:hover { background: #1e293b; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-divider { height: 1px; background: #1e293b; margin: 10px 12px; }

.sidebar-foot {
  border-top: 1px solid #1e293b; padding: 14px; display: grid;
  grid-template-columns: 34px 1fr; gap: 10px; align-items: center;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #334155; color: #e2e8f0;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.who-name { color: #f1f5f9; text-decoration: none; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout { grid-column: 1 / -1; color: #94a3b8; font-size: 12px; text-decoration: none; }
.signout:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 22px 28px 48px; }

/* ---------------- components ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h2 { margin: 0; font-size: 15px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .value { font-size: 27px; font-weight: 650; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1000px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  background: #fafbfc; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 7px;
  font-size: 14px; cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-teal:hover { filter: brightness(.92); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=url], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 7px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.help { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox input { width: auto; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.role-pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.role-super_admin { background: #fee2e2; color: #991b1b; }
.role-super_user { background: #ede9fe; color: #5b21b6; }
.role-user { background: #dbeafe; color: #1e40af; }

.status-new { background: #e2e8f0; color: #334155; }
.status-contacted { background: #dbeafe; color: #1e40af; }
.status-applied { background: #fef3c7; color: #92400e; }
.status-skill_scan_complete { background: #ccfbf1; color: #115e59; }
.status-enrolled { background: #dcfce7; color: #166534; }
.status-not_interested { background: #f1f5f9; color: #64748b; }

.tag-sent { background: #dcfce7; color: #166534; }
.tag-failed { background: #fee2e2; color: #991b1b; }
.tag-blocked { background: #fef3c7; color: #92400e; }

.flashes { padding: 14px 28px 0; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; border: 1px solid; }
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.banner { padding: 11px 14px; border-radius: 8px; font-size: 13.5px; border: 1px solid; margin-bottom: 16px; }
.banner-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.banner-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ---------------- filters ---------------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.filters .actions { display: flex; gap: 8px; }

.bulkbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius); margin-bottom: 14px;
}
.bulkbar.hidden { display: none; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 14px 4px 0; }

/* ---------------- login ---------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: #0f172a; padding: 20px; }
.auth-card {
  background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 40px rgba(2, 6, 23, .35);
}
.auth-card h1 { margin: 0 0 4px; font-size: 21px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.demo-creds { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; font-size: 12.5px; color: var(--muted); }
.demo-creds code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 10px 12px;
  border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; }

/* ---------------- email preview ---------------- */
.preview-frame {
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 20px;
  max-height: 520px; overflow: auto;
}
.preview-meta { background: #f8fafc; border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; padding: 12px 16px; font-size: 13px; }
.preview-meta + .preview-frame { border-radius: 0 0 8px 8px; }

.recipient-row { cursor: pointer; }
.recipient-row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.recipient-row.is-selected > td { background: #eff6ff; }
.recipient-row.is-selected > td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
#preview-body.is-loading { opacity: .45; }

.merge-list { display: flex; flex-wrap: wrap; gap: 6px; }
.merge-list code { background: #f1f5f9; border: 1px solid var(--line); padding: 2px 7px;
  border-radius: 5px; font-size: 12px; cursor: pointer; }
.merge-list code:hover { background: #e2e8f0; }

.detail-json { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--muted); font-size: 12px; }

.template-card { border-left: 3px solid var(--brand); }
.template-row { display: flex; gap: 24px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.template-actions { display: flex; gap: 8px; flex-shrink: 0; }

.link-map { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.link-map-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; font-weight: 600;
}
.link-map table { table-layout: auto; }
.link-map th, .link-map td { padding: 7px 10px; }
.link-map th:first-child, .link-map td:first-child { padding-left: 0; }
.link-map tbody tr:last-child td { border-bottom: none; }
.link-map .mono { color: var(--muted); word-break: break-all; }

.shared-link {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  background: #ede9fe; color: #5b21b6; padding: 2px 9px; border-radius: 999px;
}

.error-page { max-width: 520px; margin: 80px auto; text-align: center; }
.error-page .code { font-size: 54px; font-weight: 700; color: var(--muted); }

/* ---------------- visual template editor ---------------- */
.rt-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 8px 8px 0 0; background: #f8fafc; padding: 6px 8px;
}
.rt-btn {
  border: 1px solid transparent; background: transparent; color: var(--ink);
  border-radius: 6px; padding: 4px 9px; font-size: 13px; line-height: 1.4;
  cursor: pointer; min-width: 30px;
}
.rt-btn:hover { background: #e2e8f0; }
.rt-btn:active { background: #cbd5e1; }
.rt-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.rt-btn.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.rt-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.rt-spacer { flex: 1 1 auto; }
.rt-toggle { font-size: 11.5px; letter-spacing: .04em; color: var(--muted); }

.rt-editor {
  border: 1px solid var(--line); border-radius: 0 0 8px 8px;
  background: #fff; padding: 14px 16px; min-height: 320px;
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-wrap: anywhere;
}
.rt-editor:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12); }
.rt-editor > :first-child { margin-top: 0; }
.rt-editor > :last-child { margin-bottom: 0; }
.rt-editor h2 { font-size: 19px; margin: 16px 0 8px; }
.rt-editor h3 { font-size: 16px; margin: 14px 0 6px; }
.rt-editor p { margin: 0 0 10px; }
.rt-editor a { color: var(--brand); }
.rt-editor ul, .rt-editor ol { margin: 0 0 10px; padding-left: 22px; }

textarea.rt-source {
  width: 100%; min-height: 340px; border-radius: 0 0 8px 8px;
  border: 1px solid var(--line); padding: 12px 14px;
}

.rt-warning {
  background: #fef3c7; border: 1px solid #f59e0b; color: #92400e;
  border-radius: 8px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px;
}

.merge-list code { cursor: pointer; user-select: none; }

/* merge fields shown as plain-language chips inside the message */
.rt-chip {
  display: inline-block; background: #dbeafe; color: #1e40af;
  border: 1px solid #bfdbfe; border-radius: 12px;
  padding: 1px 9px; font-size: 13px; font-weight: 500;
  cursor: pointer; user-select: none; white-space: nowrap;
  vertical-align: baseline;
}
.rt-chip:hover { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }

.merge-list code {
  background: #eff6ff; border-color: #bfdbfe; color: #1e40af;
  font-family: inherit; font-size: 13px; border-radius: 12px; padding: 2px 10px;
}
.merge-list code:hover { background: #dbeafe; }

.block-list { display: flex; flex-wrap: wrap; gap: 7px; }
.block-chip {
  background: #fff; border: 1px dashed #94a3b8; color: var(--ink);
  border-radius: 20px; padding: 5px 13px; font: inherit; font-size: 13.5px;
  cursor: pointer;
}
.block-chip:hover { border-style: solid; border-color: var(--brand); color: var(--brand); background: #eff6ff; }

.editor-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.enrolled-note {
  background: #ecfdf5; border: 1px solid #6ee7b7; color: #065f46;
  border-radius: 8px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px;
}

/* --- drag and drop into the message --- */
.rt-editor.is-drop-target { border-color: var(--brand); background: #fbfdff; }

.rt-drop-line {
  height: 0; border-top: 2px solid var(--brand); margin: 6px 0;
  position: relative; pointer-events: none;
}
.rt-drop-line::before {
  content: ""; position: absolute; left: -4px; top: -5px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--brand);
}

.rt-chip[draggable="true"], .merge-list code, .block-chip { cursor: grab; }
.rt-chip:active, .merge-list code:active, .block-chip:active { cursor: grabbing; }

/* --- audit trail, read by people rather than developers --- */
.when-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.when-date { font-size: 12px; }

.action-label {
  display: inline-block; background: #f1f5f9; border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 9px; font-size: 12.5px;
  font-weight: 500; color: var(--ink); white-space: nowrap;
}

.detail-list { margin: 6px 0 0; padding-left: 17px; }
.detail-list li { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }

.routine-toggle { display: flex; align-items: center; gap: 7px; margin-top: 10px; flex-basis: 100%; }

/* Sign in with Microsoft */
.ms-signin {
  width: 100%;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  font-size: 15px;
}
.break-glass {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border, #d8dee4);
}
.break-glass > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted, #667);
}
.break-glass .help { margin: 8px 0 14px; }
