:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--ink); color: #fff;
}
.brand { font-weight: 700; font-size: 17px; text-decoration: none; letter-spacing: -0.01em; }
.topbar nav { display: flex; gap: 6px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: 10px; text-decoration: none; font-size: 20px; color: #fff;
}
.icon-btn:active { background: rgba(255,255,255,.12); }
[hidden] { display: none !important; }
.switcher {
  flex: 1; min-width: 0; max-width: 60vw; margin-right: 8px;
  font-weight: 700; font-size: 16px; color: #fff; background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2); border-radius: 10px; padding: 8px 10px;
}
.switcher option { color: var(--ink); }
.lead.paused { opacity: .6; }
.creds { border: 2px solid var(--accent); }
pre.transcript, code { overflow-wrap: anywhere; word-break: break-all; }
pre.transcript { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; }

main { max-width: 720px; margin: 0 auto; padding: 12px 12px calc(32px + var(--safe-bottom)); }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.back { display: inline-block; margin: 2px 0 10px; }

.banner { background: #fef9c3; color: #713f12; padding: 10px 16px; font-size: 14px; }
.banner button { margin-left: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.card h2 { margin: 0 0 8px; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.alert { border-color: #fecaca; background: #fef2f2; }
.stat.alert b { color: #991b1b; }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 12px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .65; margin-left: 4px; font-variant-numeric: tabular-nums; }

.search { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 8px; }

.lead-list { list-style: none; margin: 0; padding: 0; }
.lead {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; text-decoration: none;
}
.lead.is-new { border-left: 4px solid var(--accent); }
.lead .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead .meta { grid-column: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead .when { font-size: 12px; color: var(--muted); text-align: right; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 9px; background: #e2e8f0; color: var(--ink-2); text-transform: capitalize; }
.badge.new { background: #dcfce7; color: #166534; }
.badge.contacted { background: #e0f2fe; color: #075985; }
.badge.quoted { background: #fef3c7; color: #92400e; }
.badge.won { background: #ede9fe; color: #5b21b6; }
.badge.completed { background: #cffafe; color: #155e75; }
.badge.paid { background: #16a34a; color: #fff; }
.badge.lost { background: #f1f5f9; color: #94a3b8; }
.badge.outcome-answered { background: #dcfce7; color: #166534; }
.badge.outcome-missed { background: #fee2e2; color: #991b1b; }
.badge.outcome-voicemail { background: #fef3c7; color: #92400e; }
.lead .who .badge { font-size: 11px; padding: 2px 7px; margin-left: 4px; vertical-align: 1px; }

.call-summary { font-size: 15px; line-height: 1.5; margin: 8px 0; }
.transcript { white-space: pre-wrap; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
details { margin-top: 10px; font-size: 14px; }
details summary { cursor: pointer; color: var(--ink-2); font-weight: 600; min-height: 32px; }
#retranscribe { margin-top: 10px; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail-head h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; }

dl.fields { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
dl.fields dt { color: var(--muted); }
dl.fields dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.field input, label.field textarea, label.field select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; }

.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.timeline li:first-child { border-top: 0; }

audio { width: 100%; margin-top: 8px; }

.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { font-size: 22px; margin: 0 0 16px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(15, 23, 42, .25); z-index: 20;
}
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .actions { grid-template-columns: repeat(4, 1fr); }
}
