*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #ffffff;
    --surface: #f5f5f5;
    --surface2: #ebebeb;
    --border: rgba(0,0,0,0.08);
    --border-hi: rgba(0,0,0,0.18);
    --text: #0e0e0f;
    --muted: #6b6a66;
    --accent: #402dab;
    --accent-dim: rgba(64,45,171,0.1);
    --danger: #dc2626;
    --danger-dim: rgba(220,38,38,0.08);
    --mono: 'DM Mono', monospace;
    --sans: 'DM Sans', sans-serif;
    --radius: 8px;
  }

  html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.6;
  }

/* ── Layout ── */
.app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.wordmark {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-meta {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ── Tabs ── */
nav {
  display: flex;
  align-items: flex-end;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  position: relative;
  padding: 12px 20px 11px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--sans);
  transition: color 0.15s;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--text);
  font-weight: 500;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.tab-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
}

/* ── Panels ── */
.panels { flex: 1; overflow-y: auto; }

.panel { display: none; padding: 40px 32px; max-width: 780px; }
.panel.active { display: block; }

/* ── Form ── */
.panel-title {
  font-size: 20px;
  font-weight: 300;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
}

.field { margin-bottom: 20px; }

label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 7px;
}

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: var(--border-hi);
}

input::placeholder, textarea::placeholder { color: var(--muted); }

textarea { resize: vertical; min-height: 96px; line-height: 1.7; }

.field-hint {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.row { display: grid; grid-template-columns: 1fr 140px; gap: 12px; }

.run-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.run-btn:hover:not(:disabled) { opacity: 0.9; }
.run-btn:active:not(:disabled) { transform: scale(0.99); }
.run-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Status ── */
.status {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.status.visible { display: flex; }

.status.error {
  border-color: rgba(240,110,110,0.3);
  background: var(--danger-dim);
  color: var(--danger);
}

.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 36px 0;
}

/* ── Results ── */
#results { display: none; }
#results.visible { display: block; }

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

.results-title {
  font-size: 13px;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.results-count {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
}

.results-count span {
  color: var(--accent);
  font-weight: 500;
}

.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 10px;
  animation: fadeUp 0.25s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.review-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.review-stars { font-size: 13px; letter-spacing: 1px; }
.star-filled { color: var(--accent); }
.star-empty  { color: var(--surface2); }

.review-score {
  font-family: var(--mono);
  font-size: 11px;
  color: #0e0e0f;
  background: var(--accent);
  border-radius: 4px;
  padding: 2px 8px;
}

.review-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.review-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 12px;
}

.review-reason {
  font-size: 12px;
  font-family: var(--mono);
  color: rgba(64,45,171,0.1);;
  padding: 8px 12px;
  background: var(--accent-dim);
  border-radius: 4px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.pain-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pain-tag {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 9px;
}

/* ── Coming soon ── */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  gap: 12px;
  color: var(--muted);
}

.coming-soon-icon {
  font-size: 32px;
  opacity: 0.3;
}

.coming-soon p {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Export ── */
.export-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.export-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
}

/* ── Comments button ── */
.comments-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.comments-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
}

.comments-btn-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ── Overlay ── */
.comments-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}

.comments-overlay.visible { display: block; }

/* ── Drawer ── */
.comments-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.comments-drawer.open { transform: translateX(0); }

.comments-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.comments-drawer-title {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.comments-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
}

.comments-close:hover { color: var(--text); }

/* ── Comment list ── */
.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comments-empty {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

.comment-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.comment-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(212,240,110,0.2);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.comment-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.comment-meta {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
}

.comment-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ── Compose ── */
.comments-compose {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.comments-compose input,
.comments-compose textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.comments-compose input:focus,
.comments-compose textarea:focus {
  border-color: var(--border-hi);
}

.comments-compose textarea {
  resize: none;
  height: 80px;
  line-height: 1.6;
}

.comments-compose input::placeholder,
.comments-compose textarea::placeholder { color: var(--muted); }

.comment-submit {
  align-self: flex-end;
  background: var(--accent);
  color: #0e0e0f;
  border: none;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.comment-submit:hover:not(:disabled) { opacity: 0.85; }
.comment-submit:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Direct Mail table ── */
.dm-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead tr {
  border-bottom: 1px solid var(--border);
}

thead th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 12px 10px 0;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  animation: fadeUp 0.2s ease both;
}

tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 12px 12px 12px 0;
  color: var(--text);
  vertical-align: top;
  line-height: 1.5;
}

.status-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.active {
  background: rgba(64,45,171,0.1);
  color: #402dab;
}

.status-badge.inactive {
  background: var(--danger-dim);
  color: var(--danger);
}

#dm-results { display: none; }
#dm-results.visible { display: block; }

/* ── Field Sales ── */
.fs-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 20px;
    align-items: start;
  }
  
  #fs-map {
    display: none;
    width: 100%;
    height: 520px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: sticky;
    top: 20px;
  }
  
  #fs-results { display: none; }
  #fs-results.visible { display: block; }
  
  .fs-card { transition: border-color 0.15s; }
  .fs-card:hover { border-color: var(--border-hi); }
  .fs-card.fs-active { border-color: var(--accent) !important; }