:root {
  --bg: #F7F6F2;
  --surface: #F9F8F5;
  --surface-alt: #FBFBF9;
  --surface-elevated: #FFFFFF;
  --border: #D4D1CA;
  --border-strong: #B8B5AD;
  --text: #28251D;
  --text-muted: #7A7974;
  --text-faint: #BAB9B4;
  --primary: #01696F;
  --primary-hover: #0C4E54;
  --primary-tint: rgba(1, 105, 111, 0.08);
  --accent: #964219;
  --accent-tint: rgba(150, 66, 25, 0.08);
  --error: #A12C7B;
  --warning: #964219;
  --success: #437A22;
  --success-tint: rgba(67, 122, 34, 0.1);

  --dem: #2E5A9E;
  --rep: #A13544;
  --npa: #7A7974;
  --other: #7A39BB;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.16), 0 4px 12px rgba(0,0,0,0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input, select, textarea { font: inherit; color: inherit; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* ---------- Gate ---------- */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  z-index: 3000;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px 28px;
  box-shadow: var(--shadow-sm);
}
.logo { color: var(--primary); margin-bottom: 16px; display: flex; justify-content: center; }
.gate-card h1 { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.gate-card .tagline { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.gate-card label { display: block; font-size: 14px; font-weight: 500; color: var(--text-muted); margin-bottom: 14px; }
.gate-card input, .gate-card select {
  display: block; width: 100%; padding: 12px 14px; margin-top: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 16px;
}
.gate-card input:focus, .gate-card select:focus { outline: none; border-color: var(--primary); background: var(--surface-elevated); }
.gate-card select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237A7974' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }
.gate-card .primary { width: 100%; margin-top: 8px; }
.gate-card .error { color: var(--error); font-size: 14px; margin-top: 10px; min-height: 20px; text-align: center; }
.admin-badge { display: inline-block; margin-left: 6px; padding: 2px 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; background: var(--accent); color: white; border-radius: 999px; vertical-align: middle; }

/* ---------- Buttons ---------- */
.primary {
  background: var(--primary); color: white;
  padding: 12px 20px; border-radius: var(--radius);
  font-weight: 600; font-size: 15px;
  min-height: 44px;
  transition: background 0.15s;
}
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.secondary {
  background: transparent; color: var(--text);
  padding: 12px 20px; border: 1px solid var(--border);
  border-radius: var(--radius); font-weight: 500; font-size: 15px;
  min-height: 44px;
}
.secondary:hover { background: var(--surface); }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--radius);
  color: var(--text);
}
.icon-btn:hover { background: var(--surface); }

/* ---------- Topbar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding-left: 4px; padding-right: 4px;
  z-index: 100;
}
.topbar-title { flex: 1; text-align: center; padding: 0 8px; overflow: hidden; }
.topbar-turf { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-stats { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Callback banner ---------- */
.callback-banner {
  position: fixed;
  top: calc(56px + var(--safe-top));
  left: 0; right: 0;
  background: var(--accent-tint);
  border-bottom: 1px solid var(--border);
  z-index: 90;
}
.callback-banner-inner {
  padding: 10px 16px; display: flex; align-items: center; gap: 8px;
  font-size: 14px;
}
.callback-banner-inner strong { color: var(--accent); font-weight: 700; }
.callback-banner-inner button {
  margin-left: auto;
  background: var(--accent); color: white;
  padding: 6px 14px; border-radius: 100px;
  font-size: 13px; font-weight: 600;
}

/* ---------- List view ---------- */
.list-view {
  position: fixed;
  top: calc(56px + var(--safe-top));
  bottom: 0; left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px calc(var(--safe-bottom) + 20px);
}
.list-view.has-banner { top: calc(56px + var(--safe-top) + 42px); }

.contact-list { display: flex; flex-direction: column; gap: 8px; }

.contact-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.contact-card:active { background: var(--surface); }
.contact-card.status-not-called { border-left: 3px solid var(--text-faint); }
.contact-card.status-no-answer { border-left: 3px solid #FFC553; }
.contact-card.status-left-voicemail { border-left: 3px solid #DA7101; }
.contact-card.status-spoke-to { border-left: 3px solid var(--success); }
.contact-card.status-wrong-number { border-left: 3px solid var(--text-muted); }
.contact-card.status-do-not-call { border-left: 3px solid var(--error); }
.contact-card.status-callback { border-left: 3px solid var(--accent); background: var(--accent-tint); }

.contact-row { display: flex; align-items: baseline; gap: 8px; }
.contact-name { font-weight: 700; font-size: 15px; }
.contact-age { color: var(--text-muted); font-size: 13px; }
.contact-party {
  margin-left: auto;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 100px;
  color: white;
}
.contact-party.DEM { background: var(--dem); }
.contact-party.REP { background: var(--rep); }
.contact-party.NPA { background: var(--npa); }
.contact-party.OTHER { background: var(--other); }

.contact-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 13px; color: var(--text-muted); }
.contact-phone { color: var(--primary); font-weight: 500; font-variant-numeric: tabular-nums; }

.contact-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.contact-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 100px;
  background: var(--primary-tint); color: var(--primary); font-weight: 600;
}
.contact-tag.tag-supporter { background: var(--success-tint); color: var(--success); }
.contact-tag.tag-follow-up { background: var(--accent-tint); color: var(--accent); }

.contact-status-note {
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.empty-state {
  padding: 60px 24px; text-align: center; color: var(--text-muted);
}

/* ---------- Side menu ---------- */
.side-menu { position: fixed; inset: 0; z-index: 1500; }
.side-menu-scrim {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  animation: fade-in 0.15s;
}
.side-menu-inner {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: min(320px, 85vw);
  background: var(--surface-elevated);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  display: flex; flex-direction: column;
  animation: slide-in-left 0.2s;
  z-index: 2;
}
.side-menu-header {
  padding: 12px 12px 12px 20px;
  display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
}
.side-menu-title { font-weight: 700; font-size: 17px; flex: 1; }
.side-menu-caller {
  padding: 12px 20px; background: var(--surface);
  font-size: 13px; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.side-menu-caller strong { color: var(--text); font-weight: 600; }
.side-menu-section-label {
  padding: 16px 20px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600;
}
.turf-list { list-style: none; overflow-y: auto; flex: 1; padding-bottom: 12px; }
.turf-item {
  padding: 12px 20px; display: flex; align-items: center; gap: 10px;
  cursor: pointer; font-size: 15px;
  border-left: 3px solid transparent;
}
.turf-item.active { background: var(--primary-tint); border-left-color: var(--primary); font-weight: 600; }
.turf-item:hover { background: var(--surface); }
.turf-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.turf-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turf-count { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.side-menu-actions { border-top: 1px solid var(--border); padding: 8px 0; }
.side-action {
  width: 100%; padding: 12px 20px; text-align: left;
  display: flex; align-items: center; gap: 12px;
  font-size: 15px;
}
.side-action:hover { background: var(--surface); }

/* ---------- Sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 2000; }
.sheet-scrim {
  position: absolute; inset: 0; background: rgba(0,0,0,0.4);
  animation: fade-in 0.15s;
}
/* When the script panel is open, let clicks fall through the sheet scrim so
   the floating/docked/drawer script window stays interactive. The voter card
   content itself (.sheet-inner) stays clickable because it has its own
   pointer-events. Users close the voter card via the X button. */
body[data-script-open="true"] .sheet-scrim {
  pointer-events: none;
}
body[data-script-open="true"] .sheet-inner {
  pointer-events: auto;
}
.sheet-inner {
  position: absolute; bottom: 0; left: 0; right: 0;
  max-height: 92vh; max-height: 92dvh;
  background: var(--surface-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: var(--safe-bottom);
  display: flex; flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slide-up 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
  z-index: 2;
  box-shadow: var(--shadow-lg);
}
.sheet-header {
  padding: 12px 12px 12px 20px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
}
.sheet-header::before {
  content: ''; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong);
}
.sheet-header h2 { font-size: 17px; font-weight: 700; flex: 1; padding-left: 4px; }
.sheet-body { padding: 16px 20px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.sheet-footer button { flex: 1; }

/* Filter chips */
.filter-group { margin-bottom: 20px; }
.filter-group > label {
  display: block; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 8px 14px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; font-weight: 500;
  min-height: 40px; display: inline-flex; align-items: center;
  transition: all 0.1s;
}
.chip:hover { background: var(--surface-alt); }
.chip.active {
  background: var(--primary); color: white; border-color: var(--primary);
}

/* ---------- Contact detail ---------- */
.contact-detail-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.contact-detail-header::before {
  content: ''; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong);
}
.contact-detail-close {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.contact-detail-name { font-size: 22px; font-weight: 700; padding-right: 44px; }
.contact-detail-sub { color: var(--text-muted); font-size: 14px; margin-top: 2px; }
.contact-detail-precinct { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.contact-call-actions {
  display: flex; gap: 8px; padding: 16px 20px;
  background: var(--primary-tint);
}
.call-btn {
  flex: 1; background: var(--primary); color: white;
  padding: 14px 16px; border-radius: var(--radius);
  font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
  min-height: 48px;
}
.call-btn:active { background: var(--primary-hover); }
.call-btn-secondary {
  flex: 0 0 auto; padding: 14px;
  background: white; color: var(--primary);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}

.detail-section {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.detail-section:last-child { border-bottom: none; }
.detail-section-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 10px;
}

.status-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.status-chip {
  padding: 12px 8px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; text-align: center;
  min-height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.status-chip.active { color: white; border-color: transparent; }
.status-chip.active[data-status="no_answer"] { background: #DA7101; }
.status-chip.active[data-status="left_voicemail"] { background: #964219; }
.status-chip.active[data-status="spoke_to"] { background: var(--success); }
.status-chip.active[data-status="wrong_number"] { background: var(--text-muted); }
.status-chip.active[data-status="do_not_call"] { background: var(--error); }
.status-chip.active[data-status="callback"] { background: var(--accent); }
.status-chip.active[data-status="deceased_moved"] { background: #1B474D; }

.tag-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  padding: 8px 14px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; font-weight: 500;
  min-height: 40px; display: inline-flex; align-items: center;
}
.tag-chip.active { background: var(--primary); color: white; border-color: var(--primary); }

textarea.notes-input {
  width: 100%; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 15px;
  resize: vertical; min-height: 80px;
}
textarea.notes-input:focus { outline: none; border-color: var(--primary); background: var(--surface-elevated); }

.callback-picker { display: flex; flex-direction: column; gap: 8px; }
.callback-quick-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.callback-quick-buttons button {
  padding: 8px 14px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; font-weight: 500; min-height: 40px;
}
.callback-quick-buttons button.active { background: var(--accent); color: white; border-color: var(--accent); }
.callback-datetime {
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; width: 100%;
}

.voter-context {
  padding: 12px 14px; background: var(--surface); border-radius: var(--radius);
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
}
.voter-context .label { color: var(--text); font-weight: 600; margin-right: 6px; }
.voter-context .warn { color: var(--accent); font-weight: 600; }
.voter-context .success { color: var(--success); font-weight: 600; }

/* ---------- Script ---------- */
.script-body {
  font-size: 15px; line-height: 1.6;
}
.script-body h3 {
  font-size: 15px; font-weight: 700; margin-top: 24px; margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--primary);
}
.script-body h3:first-child { margin-top: 0; }
.script-body p { margin-bottom: 12px; }
.script-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 8px 14px; margin: 8px 0;
  background: var(--primary-tint);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: normal;
  color: var(--text);
}
.script-body ul { padding-left: 20px; margin-bottom: 12px; }
.script-body li { margin-bottom: 6px; }
.script-body strong { font-weight: 700; }
.script-body .callout {
  padding: 12px 14px; background: var(--accent-tint);
  border-radius: var(--radius); border-left: 3px solid var(--accent);
  margin: 12px 0;
}

/* ---------- Export ---------- */
.export-preview {
  padding: 16px; background: var(--surface); border-radius: var(--radius);
  font-size: 14px; color: var(--text-muted); text-align: center; margin-top: 16px;
}
.export-preview strong { display: block; color: var(--text); font-size: 24px; font-weight: 700; margin-bottom: 4px; }

.muted { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface);
  padding: 12px 20px; border-radius: 100px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 5000;
  animation: toast-in 0.2s;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

/* ---------- Animations ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; }
}

/* ============================================================
   Script Panel - floating / docked / drawer
   ============================================================ */

/* Base script-panel z-index sits ABOVE .sheet (z-index 2000) so the floating
   window stays on top when a voter card is opened. Per-layout overrides below. */
.script-panel {
  position: fixed;
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 2200;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.35, 1),
              opacity 0.15s ease-out,
              border-radius 0.15s ease-out;
}

.script-panel[hidden] { display: none !important; }

.script-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-elevated);
  flex-shrink: 0;
  min-height: 44px;
}

.script-panel-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.script-layout-picker {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.layout-choice {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.layout-choice:hover { color: var(--text); }

.layout-choice[aria-pressed="true"] {
  background: var(--surface-elevated);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.script-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
}

.script-panel-resize {
  position: absolute;
  z-index: 2;
  background: transparent;
  transition: background 0.12s;
}

.script-panel-resize:hover { background: rgba(0,0,0,0.05); }

/* ---------- Layout: docked to right side ---------- */
.script-panel[data-layout="dock-right"] {
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--script-panel-width, 380px);
  min-width: 300px;
  max-width: 55vw;
  border-radius: 0;
  border-top: none;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid var(--border);
  animation: slide-in-right 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
}

.script-panel[data-layout="dock-right"] .script-panel-resize {
  top: 0;
  left: -3px;
  bottom: 0;
  width: 6px;
  cursor: ew-resize;
}

.script-panel[data-layout="dock-right"] #script-panel-drag-handle {
  cursor: default;
}

/* When docked, push app content and modals over so the script stays visible */
body[data-script-docked="true"] #app {
  padding-right: var(--script-panel-width, 380px);
  transition: padding-right 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
}
body[data-script-docked="true"] .sheet {
  right: var(--script-panel-width, 380px);
  transition: right 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
}
body[data-script-docked="true"] .toast {
  transform: translateX(calc(-50% - (var(--script-panel-width, 380px) / 2)));
}
/* Docked script must sit above other sheets so it's never covered */
.script-panel[data-layout="dock-right"] { z-index: 2200; }

/* ---------- Layout: floating window ---------- */
.script-panel[data-layout="float"] {
  top: var(--script-panel-top, 80px);
  left: var(--script-panel-left, calc(100vw - 420px));
  width: var(--script-panel-width, 380px);
  height: var(--script-panel-height, 500px);
  min-width: 280px;
  min-height: 240px;
  max-width: 95vw;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  animation: fade-in 0.15s;
}

.script-panel[data-layout="float"] #script-panel-drag-handle {
  cursor: move;
  user-select: none;
  touch-action: none;
}

.script-panel[data-layout="float"] .script-panel-resize {
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: transparent;
}

.script-panel[data-layout="float"] .script-panel-resize::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  opacity: 0.7;
}

/* ---------- Layout: bottom drawer ---------- */
.script-panel[data-layout="drawer"] {
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--script-panel-drawer-height, 45vh);
  min-height: 200px;
  max-height: 85vh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--border);
  border-left: none;
  border-right: none;
  border-bottom: none;
  animation: slide-up 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
  z-index: 2200; /* above voter/filter sheets so it stays visible */
}
/* When drawer is showing, other sheets stop above it */
body[data-script-drawer="true"] .sheet {
  bottom: var(--script-panel-drawer-height, 45vh);
  transition: bottom 0.22s cubic-bezier(0.2, 0.9, 0.35, 1);
}
body[data-script-drawer="true"] .sheet .sheet-inner {
  max-height: calc(92vh - var(--script-panel-drawer-height, 45vh));
}

.script-panel[data-layout="drawer"] #script-panel-drag-handle {
  cursor: ns-resize;
  user-select: none;
  touch-action: none;
}

.script-panel[data-layout="drawer"] .script-panel-resize {
  top: -3px;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
}

/* ---------- Minimized state (all layouts): panel is hidden, tab is shown ---------- */
.script-panel[data-state="minimized"] { display: none !important; }

.script-tab {
  position: fixed;
  left: 16px;
  bottom: calc(var(--safe-bottom) + 16px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 1400;
  animation: fade-in 0.15s;
  transition: transform 0.12s, background 0.12s;
}

.script-tab:hover {
  background: var(--primary-hover, var(--primary));
  transform: translateY(-1px);
}

.script-tab[hidden] { display: none !important; }

/* ---------- Mobile: force drawer layout ---------- */
@media (max-width: 720px) {
  .script-panel[data-layout="dock-right"] {
    width: 100vw;
    max-width: 100vw;
    border-left: none;
  }
  body[data-script-docked="true"] #app {
    padding-right: 0;
  }
  body[data-script-docked="true"] .sheet {
    right: 0;
  }
  .script-panel[data-layout="float"] {
    top: 60px !important;
    left: 8px !important;
    width: calc(100vw - 16px) !important;
    height: calc(100vh - 120px) !important;
  }
  /* Only show drawer choice on mobile (docked and float aren't practical on small screens) */
  .script-layout-picker { display: none; }
}

@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* ============================================================
   Twilio in-call overlay
   Sits above sheets (2000) and script panel (2200). Never blocked
   by any other UI. Positioned top-right on desktop, bottom on mobile.
   ============================================================ */
.twilio-call-overlay {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 3500;
  min-width: 300px;
  max-width: 360px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: twilio-call-in 0.2s cubic-bezier(0.2, 0.9, 0.35, 1);
}
@keyframes twilio-call-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.twilio-call-inner {
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.twilio-call-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.twilio-call-number {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.twilio-call-state {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  color: var(--primary);
  margin-top: 4px;
}
.twilio-call-state[data-state="ringing"],
.twilio-call-state[data-state="dialing"] {
  color: var(--warning, #964219);
}
.twilio-call-state[data-state="in-progress"] {
  color: var(--success, #437A22);
}
.twilio-call-state[data-state="completed"],
.twilio-call-state[data-state="failed"] {
  color: var(--text-muted);
}
.twilio-call-timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin: 2px 0 6px;
  letter-spacing: 0.5px;
}
.twilio-call-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.twilio-call-btn {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.twilio-call-btn:hover {
  background: var(--surface-alt);
}
.twilio-call-btn[aria-pressed="true"] {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.twilio-hangup {
  background: #A13544;
  color: white;
  border-color: #A13544;
}
.twilio-hangup:hover {
  background: #8B2C39;
  border-color: #8B2C39;
}

/* Mobile: dock overlay to bottom of screen */
@media (max-width: 720px) {
  .twilio-call-overlay {
    top: auto;
    bottom: 20px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
}

/* Call-state chip in the topbar (visible when device is registered) */
.twilio-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.twilio-status-chip[data-ready="true"] {
  background: color-mix(in oklab, var(--success, #437A22) 15%, transparent);
  color: var(--success, #437A22);
}
.twilio-status-chip::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
