:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #667085;
  --border: #dde1e7;
  --accent: #0f6cbd;
  --accent-text: #ffffff;
  --to: #0f6cbd;
  --cc: #7a4fd1;
  --bcc: #8a5a00;
  --to-bg: #e6f0fb;
  --cc-bg: #f0eafb;
  --bcc-bg: #fbf1df;
  --bad: #b42318;
  --warn-bg: #fff4e5;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2126;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #33373e;
    --accent: #4c9bf0;
    --accent-text: #0b0d10;
    --to: #6aaef5;
    --cc: #b49af0;
    --bcc: #e0b25a;
    --to-bg: #1b2a3c;
    --cc-bg: #2a2340;
    --bcc-bg: #3a2e17;
    --bad: #f97066;
    --warn-bg: #3a2e17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; }
.privacy { margin: 0; color: var(--muted); flex: 1; }

main { padding: 20px 24px; max-width: 1500px; margin: 0 auto; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); font-weight: 600; }
.warn { background: var(--warn-bg); padding: 8px 10px; border-radius: var(--radius); }

.drop {
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 48px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop p { margin: 4px 0; }
.drop.over, .drop:focus-visible { border-color: var(--accent); outline: none; }
.drop.compact { padding: 12px 16px; margin-bottom: 16px; }
.drop.compact .muted { display: none; }
.link { color: var(--accent); text-decoration: underline; cursor: pointer; }

.btn {
  font: inherit;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn:hover { filter: brightness(1.08); }

select, input[type=search] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}

.mapping {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.mapping summary { cursor: pointer; font-weight: 600; }
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.mapping-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  align-items: start;
}

.people {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.filters input[type=search] { flex: 1 1 220px; }
.bulk {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.bulk-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.table-wrap { overflow: auto; max-height: calc(100vh - 290px); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface); font-size: 12px; color: var(--muted); font-weight: 600; z-index: 1; }
td.email { word-break: break-all; }
td.extra { color: var(--muted); }
tr.invalid td { color: var(--muted); }
tr.assigned-to td:first-child { box-shadow: inset 3px 0 var(--to); }
tr.assigned-cc td:first-child { box-shadow: inset 3px 0 var(--cc); }
tr.assigned-bcc td:first-child { box-shadow: inset 3px 0 var(--bcc); }
.assign-col { width: 1%; white-space: nowrap; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--warn-bg);
}
.tag.bad { color: var(--bad); }

.segs { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg {
  font: inherit;
  font-size: 12px;
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 3px 10px;
  cursor: pointer;
}
.seg:first-child { border-left: 0; }
.seg:disabled { cursor: not-allowed; opacity: .4; }
.seg.on.to { background: var(--to-bg); color: var(--to); font-weight: 600; }
.seg.on.cc { background: var(--cc-bg); color: var(--cc); font-weight: 600; }
.seg.on.bcc { background: var(--bcc-bg); color: var(--bcc); font-weight: 600; }

.output {
  position: sticky;
  top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.check { display: flex; align-items: center; gap: 6px; }
.field-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.field-head h2 { font-size: 14px; margin: 0; }
.field[data-out=to] h2 { color: var(--to); }
.field[data-out=cc] h2 { color: var(--cc); }
.field[data-out=bcc] h2 { color: var(--bcc); }
.count { color: var(--muted); font-weight: 400; }
textarea {
  width: 100%;
  resize: vertical;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .layout { grid-template-columns: 1fr; }
  .output { position: static; }
  .table-wrap { max-height: none; }
}
