/* Mahi call page. Visual language borrowed from the Pipecat playground:
   near-black background, zinc cards with hairline borders, mono uppercase
   labels, a green Connect that turns red, status pills. */

@font-face {
  font-family: "Geist";
  src: url("/static/fonts/geist-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/geist-mono-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #09090b;
  --card: #18181b;
  --raised: #27272a;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --fg: #fafafa;
  --muted: #a1a1aa;
  --subtle: #71717a;
  --active: #00bc7d;
  --active-fg: #022c1e;
  --inactive: #f8646a;
  --agent: #6366f1;
  --agent-soft: #a5b4fc;
  --client: #2563eb;
  --warn: #fbbf24;
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(70% 38% at 50% -8%, rgba(99, 102, 241, 0.16), transparent 70%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.app {
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: max(20px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- header ---------- */
.head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 2px 2px;
}
.avatar {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #7c7ff5, var(--agent));
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.35);
}
h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.sub {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- mic picker ---------- */
.mic {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 10px;
  height: 44px;
  border-radius: 10px;
  background: var(--raised);
  border: 1px solid transparent;
  color: var(--muted);
}
.mic:focus-within { border-color: var(--border-strong); }
.mic > .ico { position: absolute; left: 14px; pointer-events: none; }
.mic > .chev { position: absolute; right: 12px; pointer-events: none; }
.mic select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 100%;
  padding: 0 40px 0 42px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  text-overflow: ellipsis;
  cursor: pointer;
  outline: none;
}
.mic select option { background: var(--card); color: var(--fg); }
.mic select:disabled { cursor: default; color: var(--muted); }

.meter {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
  margin: 12px 2px 0;
}
.meter i {
  flex: 1;
  border-radius: 2px;
  background: var(--raised);
  transition: background-color 0.08s linear;
}
.meter i.on { background: var(--active); }

/* ---------- connect + status ---------- */
.controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 18px;
}
.cta {
  flex: none;
  width: 96px;
  height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 22px;
  background: var(--active);
  color: var(--active-fg);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 8px 28px rgba(0, 188, 125, 0.22);
}
.cta .ico { width: 28px; height: 28px; stroke-width: 2.2; }
.cta:hover:not(:disabled) { filter: brightness(1.08); }
.cta:active:not(:disabled) { transform: scale(0.96); }
.cta:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.cta[data-mode="disconnect"] {
  background: var(--inactive);
  color: #3b0509;
  box-shadow: 0 8px 28px rgba(248, 100, 106, 0.22);
}
.cta[data-mode="connecting"] {
  background: var(--raised);
  color: var(--muted);
  box-shadow: none;
  cursor: default;
}
.cta[data-mode="connecting"] .ico { animation: spin 0.9s linear infinite; }

.side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 13px 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--subtle);
}
.pill[data-state="connecting"] { color: var(--warn); border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.08); }
.pill[data-state="connecting"] .dot { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.pill[data-state="connected"] { color: #34d399; border-color: rgba(0, 188, 125, 0.35); background: rgba(0, 188, 125, 0.1); }
.pill[data-state="connected"] .dot { background: var(--active); }
.pill[data-state="speaking"] { color: var(--agent-soft); border-color: rgba(99, 102, 241, 0.45); background: rgba(99, 102, 241, 0.14); }
.pill[data-state="speaking"] .dot { background: var(--agent); animation: pulse 0.7s ease-in-out infinite; }
.pill[data-state="ended"] .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--subtle); }

.timer {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.time {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.time[data-tone="idle"] { color: var(--subtle); }
.time[data-tone="warn"] { color: var(--warn); }
.time[data-tone="danger"] { color: var(--inactive); animation: pulse 1s ease-in-out infinite; }
.timer .hint {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle);
}

/* ---------- inline error ---------- */
.error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(248, 100, 106, 0.35);
  background: rgba(248, 100, 106, 0.08);
  color: #fecaca;
  font-size: 13.5px;
}
.error > .ico { margin-top: 1px; color: var(--inactive); }
.err-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.err-body strong { color: #fff; font-weight: 600; }
.err-body span { color: #fca5a5; overflow-wrap: anywhere; }
.retry {
  flex: none;
  align-self: center;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid rgba(248, 100, 106, 0.5);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.retry:hover { background: rgba(248, 100, 106, 0.15); }
.retry:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- transcript ---------- */
.chat {
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.listening {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #93c5fd;
  font-size: 12.5px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.18s, transform 0.18s;
}
.listening.on { opacity: 1; transform: none; }
.eq { display: inline-flex; align-items: center; gap: 2px; height: 12px; }
.eq i { width: 3px; height: 4px; border-radius: 2px; background: currentColor; }
.listening.on .eq i { animation: eq 0.8s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: 0.15s; }
.eq i:nth-child(3) { animation-delay: 0.3s; }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  max-height: min(46dvh, 380px);
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.empty {
  margin: auto;
  max-width: 260px;
  text-align: center;
  color: var(--subtle);
  font-size: 13.5px;
}
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 86%; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.who {
  padding: 0 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--subtle);
}
.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15px;
  overflow-wrap: anywhere;
  animation: pop 0.18s ease-out;
}
.bot .bubble { background: var(--raised); border-bottom-left-radius: 6px; }
.user .bubble { background: var(--client); color: #fff; border-bottom-right-radius: 6px; }
.user.interim .bubble { opacity: 0.6; }
.typing .bubble { display: inline-flex; gap: 4px; padding: 13px 14px; }
.typing .bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1s ease-in-out infinite;
}
.typing .bubble i:nth-child(2) { animation-delay: 0.15s; }
.typing .bubble i:nth-child(3) { animation-delay: 0.3s; }
.note {
  align-self: center;
  padding: 2px 10px;
  color: var(--subtle);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- footer ---------- */
.foot {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 0 4px;
  color: var(--subtle);
  font-family: var(--mono);
  font-size: 11px;
}
.foot a { color: var(--subtle); text-decoration: underline; text-underline-offset: 2px; }
.foot a:hover { color: var(--muted); }

/* ---------- motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 12px; } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (min-width: 640px) {
  .app { padding-top: 40px; padding-bottom: 24px; gap: 16px; }
  .card { padding: 20px; }
  .chat { padding: 0; }
  .chat-head { padding: 0 20px; }
  .log { padding: 20px; }
}

/* shown only when the browser blocked autoplay of Mahi's audio */
.unmute { display: block; width: 100%; margin-top: 12px; padding: 12px; font-weight: 600; }


/* Post-call contact form: email is typed here, never spelled over the call. */
.contact {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.contact .hint { margin: 0; font-size: 13px; color: var(--muted, #a3a3a3); }
.contact input {
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font: inherit;
  font-size: 14px;
}
.contact input:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.contact-row { display: flex; align-items: center; gap: 10px; }
.cta.small { height: 36px; padding: 0 16px; font-size: 13px; }
.contact-msg { font-size: 13px; color: var(--muted, #a3a3a3); }
.contact-msg[data-tone="ok"] { color: #86efac; }
.contact-msg[data-tone="err"] { color: #fca5a5; }

/* ---------- what this is ---------- */
.intro { display: flex; flex-direction: column; gap: 12px; }
.lede { margin: 0; color: var(--muted); font-size: 14.5px; }
.lede strong { color: var(--fg); font-weight: 600; }
.steps {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.steps li { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); font-size: 14px; }
.steps b { color: var(--fg); font-weight: 600; }
.step-n {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--agent-soft);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

/* ---------- mic row (the picker only appears once permission is granted) ---------- */
.mic-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.mic-row .hint { font-size: 12.5px; color: var(--subtle); }

/* ---------- verdict + booking ---------- */
.verdict {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--raised);
  animation: pop 0.2s ease-out;
}
.verdict[data-tone="pass"] { border-color: rgba(0, 188, 125, 0.4); background: rgba(0, 188, 125, 0.08); }
.verdict[data-tone="fail"] { border-color: rgba(248, 100, 106, 0.35); background: rgba(248, 100, 106, 0.07); }
.verdict-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.verdict-body strong { color: #fff; font-weight: 600; }
.verdict-body span { color: var(--muted); }
.verdict .spin {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 999px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--agent-soft);
  animation: spin 0.8s linear infinite;
}
.verdict:not([data-tone="wait"]) .spin { display: none; }
.verdict .cta.small { flex: none; align-self: center; }

/* ---------- booking modal ---------- */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(2px); }
.modal-card {
  position: relative;
  width: min(100%, 940px);
  transition: width 0.15s ease;
  max-height: min(92dvh, 860px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: pop 0.18s ease-out;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head strong { display: block; font-size: 15px; font-weight: 600; }
.modal-head .hint { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--raised);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--fg); border-color: var(--border-strong); }
/* flex-basis 0 + min-height 0 so this can shrink below its content. With the old `min-height: 460px`
   a short phone could not fit head + embed + foot inside a 100dvh card, and because the card is
   overflow:hidden the bottom of the Cal iframe -- the name/email fields and the Confirm button --
   was simply cut off the screen with nothing to scroll. */
.cal-mount { flex: 1 1 0; min-height: min(460px, 55dvh); overflow: auto; -webkit-overflow-scrolling: touch; background: var(--bg); }
/* Belt and braces over the class rename: Cal.com's injected `!important` display rule ties with a
   bare [hidden] on specificity and wins on order, so the hide has to outrank it by an id. */
#calEmbed[hidden] { display: none !important; }
.cal-fallback { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px 20px; text-align: center; }
.cal-fallback .hint { margin: 0; color: var(--muted); font-size: 14px; max-width: 40ch; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.modal-foot .hint { font-size: 12.5px; color: var(--subtle); }
/* The escape hatch sits next to "rather leave my contact" and must not out-shout the booker. */
.foot-link {
  flex: none;
  margin-left: auto;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.foot-link:hover { color: var(--fg); }
@media (max-width: 640px) {
  .modal { padding: 0; }
  .modal-card { width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; }
  /* The card owns exactly the viewport, so every child has to be allowed to shrink inside it. */
  .modal-head { padding: 10px 12px; }
  .cal-mount { min-height: 0; }
  .modal-foot { padding: 10px 12px; gap: 8px; }
  /* The long explainer costs a whole row of a phone screen that the booking form needs more. */
  .modal-foot .hint { display: none; }
  .modal-foot .retry { flex: 1; }
}

/* ---------- result popup (the calendar's sibling) ---------- */
.modal-card[data-mode="wait"], .modal-card[data-mode="result"] { width: min(100%, 460px); }
.result-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 20px;
  text-align: center;
}
.result-panel > strong { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.result-panel > .hint { margin: 0; color: var(--muted); font-size: 14px; max-width: 42ch; }
.result-panel .contact { width: 100%; margin-top: 6px; text-align: left; }
.result-panel .contact-row { justify-content: flex-start; }
.badge {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  animation: pop 0.25s ease-out;
}
.badge .ico { width: 24px; height: 24px; stroke-width: 2.5; }
.badge[data-tone="pass"] { background: rgba(0, 188, 125, 0.14); border-color: rgba(0, 188, 125, 0.45); color: var(--active); }
.badge[data-tone="fail"] { background: rgba(248, 100, 106, 0.12); border-color: rgba(248, 100, 106, 0.4); color: var(--inactive); }
.big-spin {
  width: 30px;
  height: 30px;
  margin: 6px 0;
  border-radius: 999px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--agent-soft);
  animation: spin 0.8s linear infinite;
}

/* Dismissing the popup scrolls the inline strip into view; this is what makes it findable there. */
.verdict.flash { animation: flash 1.1s ease-out 1; }
@keyframes flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
  25% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.35); }
  60% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18); }
}
@media (max-width: 640px) {
  .modal-card[data-mode="wait"], .modal-card[data-mode="result"] {
    width: 100%;
    height: auto;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    align-self: end;
  }
  .modal { padding: 0; align-items: end; }
}
@media (prefers-reduced-motion: reduce) {
  .verdict.flash, .badge { animation: none; }
  .log { scroll-behavior: auto; }
}
