* { box-sizing: border-box; }

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --accent: #16a34a;
  --warn: #f59e0b;
  --danger: #dc2626;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
}

header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  margin: 8px 0 0;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 56px;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.bar-label {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  background: #eef0f3;
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

.bar-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 6px;
  transition: width 600ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

.bar-row[data-tone="success"] .bar-fill { background: var(--accent); }
.bar-row[data-tone="warn"] .bar-fill { background: var(--warn); }
.bar-row[data-tone="danger"] .bar-fill { background: var(--danger); }

.bar-count {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.empty {
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
  padding: 8px 0;
}

footer {
  margin-top: 32px;
  text-align: center;
  padding-bottom: 32px;
}

footer a {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
}

footer a:hover {
  text-decoration: underline;
}

.error {
  color: var(--danger);
}

.meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 16px;
}

table.leads {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table.leads th,
table.leads td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: top;
}

table.leads th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

table.leads tr:last-child td {
  border-bottom: none;
}

table.leads tr:hover {
  background: #f9fafb;
}

table.leads td.email a {
  color: var(--primary);
  text-decoration: none;
}

.leads-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  min-width: 240px;
}

.search-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover {
  color: var(--primary);
}

/* Header layout with window control */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.window-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.window-control label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  font-size: 11px;
}

.window-control select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.refresh-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  transition: all 200ms;
}

.refresh-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.refresh-btn:active {
  transform: rotate(180deg);
}

/* Card header with legend */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-0 { background: #dc2626; }
.swatch-1 { background: #f59e0b; }
.swatch-2 { background: #2563eb; }
.swatch-3 { background: #16a34a; }

/* Per-question grid */
.q-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 12px;
}

.q-card {
  background: #f9fafb;
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
}

.q-card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.q-num {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  letter-spacing: 0.02em;
}

.q-cat {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.q-text {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  margin-bottom: 10px;
}

.q-row {
  display: grid;
  grid-template-columns: 64px 1fr 44px 38px;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.q-scope {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.q-bar {
  display: flex;
  height: 18px;
  background: #eef0f3;
  border-radius: 4px;
  overflow: hidden;
}

.q-bar .seg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 0;
  text-shadow: 0 1px 1px rgba(0,0,0,0.15);
}

.q-bar .seg-0 { background: #dc2626; }
.q-bar .seg-1 { background: #f59e0b; }
.q-bar .seg-2 { background: #2563eb; }
.q-bar .seg-3 { background: #16a34a; }

.q-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.q-avg {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 14px;
}

.q-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}

.meta-inline {
  margin-left: 12px;
  color: var(--muted);
  font-size: 12px;
}
