:root {
  --green:       #34c759;   /* iOS system green */
  --green-glow:  rgba(52, 199, 89, 0.55);
  --red:         #ff3b30;   /* iOS system red */
  --red-glow:    rgba(255, 59, 48, 0.55);
  --white:       #ffffff;
  --grey-1:      rgba(255, 255, 255, 0.95);
  --grey-2:      rgba(255, 255, 255, 0.70);
  --grey-3:      rgba(255, 255, 255, 0.50);
  --grey-4:      rgba(255, 255, 255, 0.20);
  --bg-top:      #1c1c1e;
  --bg-bot:      #000000;

  /* iMessage bubble colours (item 3.1) */
  --bubble-user:   #1d6bf5;   /* iOS Messages blue — user (right) */
  --bubble-agent:  #3a3a3c;   /* iOS dark grey — agent (left) */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; min-height: 100%; min-height: 100dvh; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  color: var(--white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(env(safe-area-inset-top), 24px)
           24px
           max(env(safe-area-inset-bottom), 32px);
}

/* ─── PASSWORD GATE ─────────────────────────────────────── */
.gate {
  align-items: center;
  justify-content: center;
}
.gate-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}
.gate-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  color: var(--grey-1);
  letter-spacing: -0.02em;
}
.gate-sub {
  margin: 0 0 32px;
  font-size: 14px;
  color: var(--grey-3);
}
#gateForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#gateInput {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--white);
  font-size: 16px;
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
#gateInput::placeholder { color: var(--grey-3); }
#gateInput:focus {
  border-color: var(--green);
  background: rgba(255, 255, 255, 0.12);
}
#gateSubmit {
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
#gateSubmit:hover  { background: #2db84d; }
#gateSubmit:active { transform: scale(0.98); }
#gateSubmit:disabled {
  background: rgba(255,255,255,0.1);
  color: var(--grey-3);
  cursor: not-allowed;
}
.gate-msg {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--grey-2);
  min-height: 18px;
}
.gate-msg.error { color: var(--red); }
.gate-msg.lock  { color: var(--red); font-weight: 500; }

/* ─── CALL SCREEN (iPhone style) ────────────────────────── */
.call-screen {
  justify-content: space-between;
  align-items: center;
}

.call-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 12vh;
  width: 100%;
  /* Reserve vertical space so transcript can grow without pushing the
     bottom bar off screen. flex + min-height keeps things stable. */
  min-height: 0;
  flex: 1;
}

/* Default (idle/connecting) avatar — full size */
.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3a3a3c 0%, #1c1c1e 100%);
  border: 2px solid rgba(255,255,255,0.08);
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transition: width 0.3s ease, height 0.3s ease, margin-bottom 0.3s ease;
  flex-shrink: 0;
}
.avatar-initial {
  font-size: 56px;
  font-weight: 300;
  color: var(--grey-1);
  letter-spacing: -0.02em;
  transition: font-size 0.3s ease;
}

/* Compact avatar during active call — shrinks to make room for transcript */
.call-screen.in-call .call-top {
  padding-top: 6vh;
}
.call-screen.in-call .avatar {
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
}
.call-screen.in-call .avatar-initial {
  font-size: 28px;
}

.contact-name {
  margin: 0;
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--white);
}
.contact-sub {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--grey-3);
}
.status {
  margin: 20px 0 0;
  font-size: 17px;
  font-weight: 400;
  color: var(--grey-2);
  min-height: 22px;
  letter-spacing: -0.01em;
}
.status.error { color: var(--red); }

/* ─── "Paulo está a pensar…" animated dots (item 1.2) ─────
   The indicator is shown inside .status via JS — no extra element
   needed. The dots class is applied to .status in-place. */
.status.thinking::after {
  content: "";
  display: inline-block;
  animation: thinking-dots 1.2s steps(3, end) infinite;
  width: 1.5em;
  text-align: left;
}
@keyframes thinking-dots {
  0%   { content: "."; }
  33%  { content: ".."; }
  66%  { content: "..."; }
  100% { content: ""; }
}

/* ─── Live transcript (item 3.1) ─────────────────────────── */
.transcript {
  width: 100%;
  max-width: 400px;
  max-height: 34vh;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 14px;
  padding: 0 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* Thin custom scrollbar on webkit */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.transcript::-webkit-scrollbar { width: 3px; }
.transcript::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 99px; }

/* Individual message bubbles */
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  animation: bubble-in 0.18s ease-out both;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* User bubbles — right-aligned, iOS blue */
.bubble-user {
  background: var(--bubble-user);
  color: var(--white);
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}

/* Agent bubbles — left-aligned, dark grey */
.bubble-agent {
  background: var(--bubble-agent);
  color: var(--grey-1);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}

/* Thinking placeholder bubble (item 1.2 in transcript) */
.bubble-thinking {
  background: var(--bubble-agent);
  color: var(--grey-3);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  font-style: italic;
}
.bubble-thinking::after {
  content: "";
  display: inline-block;
  animation: thinking-dots 1.2s steps(3, end) infinite;
  width: 1.5em;
  text-align: left;
}

/* ─── Bottom (call button + hint) ───────────────────────── */
.call-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding-bottom: 8px;
  flex-shrink: 0;
}

.call-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, box-shadow 0.3s ease;
  position: relative;
}
.call-btn svg { width: 36px; height: 36px; color: var(--white); }
.call-btn:active { transform: scale(0.94); }
.call-btn:disabled { opacity: 0.5; cursor: progress; }
.call-btn:focus-visible { outline: 3px solid rgba(255,255,255,0.4); outline-offset: 4px; }

/* Idle = green call button */
.call-btn-start {
  background: var(--green);
  box-shadow: 0 8px 28px rgba(52, 199, 89, 0.35);
}
.call-btn-start:hover { background: #2db84d; }

/* Connecting = green pulsing */
.call-btn.connecting {
  background: var(--green);
  box-shadow: 0 8px 28px rgba(52, 199, 89, 0.35);
  animation: pulse-green 1.2s ease-out infinite;
}

/* In-call = red end-call (rotated icon) */
.call-btn.in-call {
  background: var(--red);
  box-shadow: 0 8px 28px rgba(255, 59, 48, 0.35);
  animation: pulse-red 1.8s ease-out infinite;
}
.call-btn.in-call:hover { background: #e62e24; }
.call-btn.in-call svg { transform: rotate(135deg); }

@keyframes pulse-green {
  0%   { box-shadow: 0 8px 28px rgba(52,199,89,0.35), 0 0 0 0   var(--green-glow); }
  100% { box-shadow: 0 8px 28px rgba(52,199,89,0.35), 0 0 0 28px rgba(52,199,89,0); }
}
@keyframes pulse-red {
  0%   { box-shadow: 0 8px 28px rgba(255,59,48,0.35), 0 0 0 0   var(--red-glow); }
  100% { box-shadow: 0 8px 28px rgba(255,59,48,0.35), 0 0 0 32px rgba(255,59,48,0); }
}

.hint {
  margin: 28px 0 0;
  font-size: 13px;
  color: var(--grey-3);
  max-width: 320px;
  text-align: center;
  line-height: 1.5;
}
.hint em { font-style: normal; color: var(--grey-2); }
.hint.hidden { visibility: hidden; }

.disclaimer {
  margin: 16px 0 0;
  font-size: 11px;
  color: var(--grey-4);
  max-width: 320px;
  text-align: center;
  line-height: 1.5;
}
