:root {
  --accent-hue: 60;
  --accent: oklch(78% 0.16 var(--accent-hue));
  --accent-soft: oklch(28% 0.08 var(--accent-hue));
  --accent-faint: oklch(22% 0.04 var(--accent-hue));
  --bg: oklch(14% 0.008 260);
  --surface: oklch(17% 0.008 260);
  --surface-2: oklch(20% 0.008 260);
  --surface-3: oklch(24% 0.01 260);
  --line: oklch(28% 0.01 260);
  --line-soft: oklch(23% 0.008 260);
  --text: oklch(96% 0.005 260);
  --text-2: oklch(78% 0.01 260);
  --muted: oklch(58% 0.012 260);
  --dim: oklch(42% 0.012 260);
  --green: oklch(72% 0.16 155);
  --green-soft: oklch(28% 0.08 155);
  --red: oklch(68% 0.18 25);
  --red-soft: oklch(28% 0.08 25);
  --amber: oklch(78% 0.15 70);
  --amber-soft: oklch(28% 0.08 70);
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --shadow-1: 0 1px 0 oklch(100% 0 0 / 0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 8px 24px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.2);
  --shadow-pop: 0 24px 80px rgba(0,0,0,0.55), 0 4px 16px rgba(0,0,0,0.3);
  font-family: "Geist", "Inter", -apple-system, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, oklch(22% 0.04 var(--accent-hue) / 0.35), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, oklch(20% 0.02 260 / 0.6), transparent 60%);
  background-attachment: fixed;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.mono { font-family: var(--mono); font-feature-settings: "tnum"; }
.small { font-size: 11px; }
.ml-auto { margin-left: auto; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card, .modal-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow-pop);
}
.modal-card.wide { width: min(1040px, calc(100vw - 32px)); }
.modal-card.test-card { width: min(760px, calc(100vw - 32px)); padding: 28px; }
.test-card #test-body { min-height: 340px; line-height: 1.6; }
.test-card #test-subject,
.test-card #test-domain,
.test-card #test-to { min-height: 44px; font-size: 15px; }
.test-card .modal-actions { justify-content: flex-start; margin-top: 18px; }
.test-card .button.primary { padding: 11px 18px; font-size: 15px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, h3, p { margin-top: 0; }
.error-text { min-height: 20px; color: var(--red); }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}
.side {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  gap: 18px;
  overflow-y: auto;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 8px; border-bottom: 1px solid var(--line-soft); }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), oklch(60% 0.18 calc(var(--accent-hue) + 30)));
  display: grid; place-items: center;
  box-shadow: 0 0 0 1px oklch(100% 0 0 / 0.08), 0 4px 16px oklch(50% 0.16 var(--accent-hue) / 0.4);
}
.brand-mark span { width: 12px; height: 12px; border-radius: 3px; background: oklch(15% 0.01 260); }
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); }
.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-label { text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; color: var(--muted); padding: 4px 8px; font-weight: 600; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.side-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 999px;
}
.side-count.hot { color: var(--accent); background: var(--accent-faint); }
.s-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.s-all { background: var(--text-2); }
.s-sent { background: var(--amber); }
.s-replied { background: var(--green); }
.s-unsub { background: var(--red); }
.s-new { background: var(--text-2); }
.s-hot { background: var(--red); }
.s-warm { background: var(--amber); }
.s-cold { background: #4a90e2; }
.s-skip { background: var(--muted); }

.tier-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-2);
}
.tier-chip i { width: 6px; height: 6px; border-radius: 50%; }
.tier-chip.tier-hot { color: var(--red); border-color: var(--red); }
.tier-chip.tier-hot i { background: var(--red); }
.tier-chip.tier-warm { color: var(--amber); border-color: var(--amber); }
.tier-chip.tier-warm i { background: var(--amber); }
.tier-chip.tier-cold { color: #4a90e2; border-color: #4a90e2; }
.tier-chip.tier-cold i { background: #4a90e2; }
.tier-chip.tier-skip { opacity: 0.55; }
.tier-chip.tier-skip i { background: var(--muted); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 4px; }
.su-name { font-weight: 600; font-size: 13px; }
.su-role { font-size: 11px; }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 12px;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.crumb-sep { color: var(--dim); }
.page-title { margin: 4px 0 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.top-right { display: flex; gap: 8px; align-items: center; }
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 7px 10px;
  width: 320px;
  color: var(--muted);
}
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px oklch(50% 0.18 var(--accent-hue) / 0.18); }
.search-wrap input { border: 0; background: transparent; outline: none; flex: 1; color: var(--text); font-size: 13px; }
.search-wrap kbd { font-family: var(--mono); font-size: 10px; padding: 2px 5px; border-radius: 4px; background: var(--surface-3); color: var(--muted); border: 1px solid var(--line); }

.button, .iconbtn, .tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: 120ms;
}
.button:hover, .iconbtn:hover { background: var(--surface-3); }
.button.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.button.ghost:hover { background: var(--surface-2); color: var(--text); }
.button.primary {
  background: var(--accent);
  color: oklch(15% 0.01 260);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 0 0 1px oklch(100% 0 0 / 0.08) inset, 0 4px 14px oklch(60% 0.18 var(--accent-hue) / 0.3);
}
.button.soft { background: var(--accent-faint); color: var(--accent); border-color: var(--accent-soft); }
.iconbtn { width: 32px; height: 32px; padding: 0; color: var(--text-2); }

.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; padding: 16px 24px 0; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 14px 12px;
  position: relative;
  overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, oklch(100% 0 0 / 0.02), transparent 30%); }
.stat-label { color: var(--muted); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { display: block; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 6px; line-height: 1; font-feature-settings: "tnum"; }
.stat-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 11px; color: var(--muted); }
.stat-delta { font-weight: 600; font-family: var(--mono); }
.stat-delta.up { color: var(--green); }
.tone-amber .stat-value { color: var(--amber); }
.tone-green .stat-value { color: var(--green); }

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 14px 24px 0;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea, .sidebar-input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.field select { min-width: 145px; }
.range-field { min-width: 160px; }
.range-field input[type=range] { padding: 0; height: 4px; accent-color: var(--accent); }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 12px; color: var(--text-2); min-height: 36px; }
.toggle input { display: none; }
.toggle span {
  width: 30px; height: 17px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  position: relative;
}
.toggle span::after {
  content: "";
  position: absolute; top: 1px; left: 1px;
  width: 13px; height: 13px;
  background: var(--muted);
  border-radius: 50%;
  transition: 160ms;
}
.toggle input:checked + span { background: var(--accent-faint); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(13px); background: var(--accent); }

.selbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 24px 0;
  padding: 8px 12px;
  background: oklch(22% 0.05 var(--accent-hue) / 0.6);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 12px;
}
.selbar-count b { color: var(--accent); font-family: var(--mono); }
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 12px;
  padding: 12px 24px 24px;
  flex: 1;
  min-height: 0;
}
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: auto;
  min-height: 0;
}
table.leads { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.leads thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.leads tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.leads tbody tr { cursor: pointer; transition: background 80ms; }
.leads tbody tr:hover { background: oklch(20% 0.008 260 / 0.7); }
.leads tbody tr.active { background: oklch(22% 0.04 var(--accent-hue) / 0.4); }
.leads tbody tr.active td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.col-check { width: 40px; }
.col-score { width: 64px; }
.col-cat { width: 160px; }
.col-city { width: 110px; }
.col-email { width: 200px; }
.col-status { width: 130px; }
.col-last { width: 160px; }
.lead-cell { display: flex; gap: 10px; align-items: center; min-width: 0; max-width: 100%; }
.col-lead { min-width: 0; max-width: 280px; }
.avatar {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  flex: none;
}
.avatar.lg { width: 44px; height: 44px; font-size: 14px; border-radius: 10px; }
.lead-text { min-width: 0; flex: 1; overflow: hidden; }
.lead-name { font-weight: 600; color: var(--text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-domain { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-check, #select-all { width: 16px; height: 16px; accent-color: var(--accent); }
.score {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
}
.score-hot { color: var(--amber); border-color: var(--amber-soft); background: oklch(28% 0.08 70 / 0.3); }
.score-warm { color: oklch(80% 0.1 90); }
.score-cold { color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.pill-amber, .pill.good { color: var(--amber); border-color: var(--amber-soft); background: oklch(28% 0.08 70 / 0.3); }
.pill-green { color: var(--green); border-color: var(--green-soft); background: oklch(28% 0.08 155 / 0.3); }
.pill-red, .pill.bad { color: var(--red); border-color: var(--red-soft); background: oklch(28% 0.08 25 / 0.3); }
.pill-neutral { color: var(--text-2); }
.count-chip { font-family: var(--mono); font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--surface-3); color: var(--muted); margin-left: 6px; }
.empty-row { text-align: center; padding: 40px 20px; color: var(--muted); }

.detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.detail.empty { align-items: center; justify-content: center; padding: 40px; }
.detail-head { padding: 16px 16px 14px; border-bottom: 1px solid var(--line-soft); }
.detail-head-row { display: flex; gap: 12px; align-items: flex-start; }
.detail-head-text { flex: 1; min-width: 0; }
.detail-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.detail-domain { font-size: 11px; color: var(--muted); margin-top: 2px; display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.detail-domain:hover { color: var(--accent); }
.detail-meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.meta-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; font-size: 11px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text-2); }
.meta-chip.strong { background: var(--accent-faint); border-color: var(--accent-soft); color: var(--accent); font-family: var(--mono); font-weight: 600; }
.reply-card { margin: 14px 16px 0; padding: 14px; background: linear-gradient(180deg, oklch(28% 0.08 155 / 0.3), oklch(22% 0.04 155 / 0.15)); border: 1px solid var(--green-soft); border-radius: var(--r); }
.reply-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--green); }
.dot-green { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }
.reply-from { margin-top: 6px; font-size: 11px; color: var(--muted); }
.reply-body { margin-top: 8px; font-size: 12px; line-height: 1.55; font-style: italic; }
.detail-section { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.detail-section h3 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
dl.kv { display: grid; grid-template-columns: 80px 1fr; gap: 6px 10px; margin: 0; font-size: 12px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 8px; align-items: center; padding: 5px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); font-size: 11px; color: var(--text-2); text-decoration: none; }
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip-key { color: var(--muted); }
.timeline { display: flex; flex-direction: column; gap: 10px; position: relative; padding-left: 16px; }
.timeline::before { content: ""; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 1px; background: var(--line); }
.t-row { display: flex; gap: 12px; align-items: flex-start; position: relative; }
.t-dot { position: absolute; left: -16px; top: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--muted); }
.t-replied .t-dot { background: var(--green); border-color: var(--green); }
.t-sent .t-dot { background: var(--amber); border-color: var(--amber); }
.t-title { font-size: 12px; font-weight: 500; }
.t-sub { font-size: 11px; }
.empty-block { color: var(--muted); font-size: 12px; padding: 8px 0; }
.detail-footer { margin-top: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line-soft); }
.button.block { width: 100%; justify-content: center; }
.page-view { padding: 12px 24px 24px; overflow: auto; flex: 1; min-height: 0; }
.page-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.page-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow-1);
}
.page-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.page-card h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: -0.01em; }
.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--r);
  padding: 32px;
  color: var(--muted);
  background: oklch(15% 0.008 260 / .55);
}
.page-list { display: flex; flex-direction: column; gap: 8px; }
.page-row {
  display: grid;
  grid-template-columns: 32px minmax(160px, 240px) 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  padding: 10px;
  text-align: left;
}
.page-row:hover { background: var(--surface-3); }
.page-row strong, .page-row small { display: block; }
.page-row small { color: var(--muted); font-family: var(--mono); }
.page-row em { color: var(--text-2); font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.campaign-stats span { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); padding: 10px; }
.campaign-stats b, .campaign-stats small { display: block; }
.campaign-stats b { font-size: 22px; color: var(--accent); }
.campaign-stats small { color: var(--muted); }
.template-preview {
  margin: 12px 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px;
}

.modal { border: 0; padding: 0; background: transparent; color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(6px); }
.modal-head, .modal-actions, .tabs { display: flex; align-items: center; gap: 8px; }
.modal-head { justify-content: space-between; }
.field.stacked { margin-top: 12px; }
.preview, .progress-log { border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); padding: 12px; min-height: 140px; max-height: 260px; overflow: auto; white-space: pre-wrap; }
.tab.active { color: var(--accent); border-color: var(--accent); }
.progress-log p { margin: 0 0 8px; color: var(--muted); }
.progress-log p.good { color: var(--green); }
.progress-log p.warn { color: var(--amber); }
.progress-log p.bad { color: var(--red); }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: 360px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--text); opacity: 0; transform: translateY(10px); transition: 160ms ease; box-shadow: var(--shadow-2); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; height: auto; overflow: auto; }
  .side { display: none; }
  .top { flex-direction: column; align-items: stretch; }
  .top-right { flex-wrap: wrap; }
  .search-wrap { width: 100%; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 1fr; }
  .page-grid { grid-template-columns: 1fr; }
  .detail { min-height: 420px; }
}
