/* Phone-style simulator. Looks/feels like a smartphone "call" screen so the
   user can test their flow the way a real caller would experience it.
   Used by:
     - the admin editor's Simulate button (mounted as a floating panel)
     - the public per-flow test URL (full-screen)
*/

/* Editor float wrapper: anchors the phone bottom-right with a close button. */
.sim-phone-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 250;
}
.sim-phone-wrap[hidden] { display: none; }
.sim-phone-wrap__close {
  position: absolute;
  top: -10px;
  right: -10px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #0c1014;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  font-size: 13px;
}
.sim-phone-wrap__close:hover { background: #fff; }

.sim-phone {
  /* Derived from the user-chosen --accent for text use against the dark
     phone screen — a 55/45 mix with white gives a noticeably softer, more
     readable tint than the full-saturation accent. Used for the header
     title and the "calls remaining" line; the Call button, waveform, key
     flash, etc. keep using --accent at full strength for visual punch. */
  --accent-soft: color-mix(in srgb, var(--accent, #18FFB8) 55%, white);

  background: linear-gradient(180deg, #1a2128 0%, #0c1014 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 36px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.6),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  width: 340px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  color: #e9f2ee;
  /* iPhone-style notch hint */
  position: relative;
}
.sim-phone::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 22px;
  background: #000;
  border-radius: 12px;
  z-index: 1;
}

.sim-phone__header {
  padding: 44px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sim-phone__header-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sim-phone__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--accent-soft);
}
.sim-phone__timer {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  font-variant-numeric: tabular-nums;
}
/* Single button that swaps to-call (uses --accent) ↔ red Hangup.
   Real iPhones always green for Call — but the user wants their brand color
   applied throughout, so we use --accent for the Call state. */
.sim-phone__call-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #18FFB8);
  color: #00170f;
  font-size: 17px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 4px 18px color-mix(in srgb, var(--accent, #18FFB8) 55%, transparent);
}
.sim-phone__call-btn:active { transform: scale(0.92); }
.sim-phone__call-btn:disabled {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.35);
  cursor: not-allowed;
  box-shadow: none;
}
/* Hangup is always red regardless of accent — universal phone affordance. */
.sim-phone--in-call .sim-phone__call-btn,
.sim-phone--dialing .sim-phone__call-btn {
  background: #ff3b30;
  color: #fff;
  box-shadow: 0 4px 18px rgba(255, 59, 48, 0.55);
}

/* ─── Idle "Tap to call" screen ─────────────────────────────────── */
.sim-phone__status--idle {
  align-items: center;
  justify-content: center;
  padding: 32px 0 24px;
  color: rgba(255,255,255,0.65);
}
.sim-phone__big-icon {
  font-size: 56px;
  color: var(--accent, #18FFB8);
  margin-bottom: 8px;
  opacity: 0.85;
}
/* User-uploaded logo replaces the big phone icon. Always fits inside this
   box: scaled down if too large, scaled up if smaller. Object-fit: contain
   preserves aspect ratio either way. */
.sim-phone__logo {
  display: block;
  width: 200px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 8px;
}
.sim-phone__big-label {
  font-size: 15px;
  color: rgba(255,255,255,0.75);
}
.sim-phone__throttle {
  margin-top: auto;
  padding: 14px 16px 4px;
  text-align: center;
  width: 100%;
  border-top: 1px dashed rgba(255,255,255,0.1);
}
.sim-phone__throttle-main {
  font-size: 13px;
  color: var(--accent-soft);
  font-weight: 600;
}
.sim-phone__throttle-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-top: 4px;
}

.sim-phone__screen {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 18px;
  margin: 0 12px;
  padding: 18px 16px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  overflow: hidden;
}

.sim-phone__node-label {
  font-size: 14px;
  color: #e9f2ee;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.sim-phone__status {
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
}
.sim-phone__status--dialing::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent, #18FFB8);
  animation: sim-pulse 1s ease-in-out infinite;
}
.sim-phone__status--ended { color: rgba(255, 255, 255, 0.55); font-size: 14px; }
.sim-phone__status--ended i { font-size: 28px; color: #ff3b30; }
.sim-phone__status-detail { font-size: 11px; opacity: 0.7; }

.sim-phone__hint {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  margin-top: -4px;
}
.sim-phone__hint--warn { color: #ffc857; }

/* ─── Waveform animation (audio-playing indicator) ───────────────────── */
.sim-phone__wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 48px;
  opacity: 0.4;
  transition: opacity 200ms ease;
}
.sim-phone__wave.is-playing { opacity: 1; }
.sim-phone__wave-bar {
  width: 4px;
  height: 6px;
  background: var(--accent, #18FFB8);
  border-radius: 2px;
}
.sim-phone__wave.is-playing .sim-phone__wave-bar {
  animation: sim-wave 0.85s ease-in-out infinite;
}
@keyframes sim-wave {
  0%, 100% { height: 6px; opacity: 0.4; }
  50%      { height: 36px; opacity: 1; }
}
@keyframes sim-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.8); }
}

.sim-phone__tap-start {
  background: var(--accent, #18FFB8);
  color: #00170f;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

/* ─── DTMF display ──────────────────────────────────────────────────── */
.sim-phone__dtmf-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 28px;
  letter-spacing: 0.18em;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid color-mix(in srgb, var(--accent, #18FFB8) 35%, transparent);
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 56px;
  min-width: 160px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ─── Speech input (voice password node) ───────────────────────────── */
.sim-phone__speech {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
  margin-top: auto;
}
.sim-phone__text-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.sim-phone__text-input:focus { border-color: var(--accent, #18FFB8); }
.sim-phone__submit {
  background: var(--accent, #18FFB8);
  color: #00170f;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

/* ─── Voicemail recording UI ──────────────────────────────────────── */
.sim-phone__recording { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.sim-phone__rec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}
.sim-phone__rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff3b30;
  animation: sim-pulse 1s ease-in-out infinite;
}
.sim-phone__rec-time { font-variant-numeric: tabular-nums; opacity: 0.6; }
.sim-phone__rec-meter {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 60px;
  width: 100%;
  justify-content: space-between;
}
.sim-phone__rec-meter-bar {
  flex: 1;
  background: var(--accent, #18FFB8);
  border-radius: 2px;
  min-height: 2px;
  height: 2px;
  transition: height 80ms ease-out;
}
.sim-phone__rec-actions { display: flex; gap: 8px; justify-content: center; }
.sim-phone__stop-rec {
  background: #ff3b30;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
}
.sim-phone__skip-rec {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

/* ─── Keypad ──────────────────────────────────────────────────────── */
/* Explicit key size + `justify-content: center` on the grid: this keeps the
   keypad visually centered inside the phone body regardless of how the
   surrounding layout (floating wrapper vs full-page) sizes things around it.
   The previous `repeat(3, 1fr)` + `aspect-ratio` combination produced
   subtle alignment drift inside the editor's floating wrapper where the phone
   could be slightly wider than expected. */
.sim-phone__keypad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-auto-rows: 76px;
  gap: 14px;
  justify-content: center;
  align-content: center;
  padding: 18px 0 26px;
  width: 100%;
  box-sizing: border-box;
  transition: opacity 200ms ease;
}
.sim-phone__keypad--disabled { opacity: 0.3; pointer-events: none; }
.sim-key {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 50%;
  width: 76px;
  height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: inherit;
  transition: background 80ms ease, transform 80ms ease;
  padding: 0;
  user-select: none;
}
.sim-key:hover { background: rgba(255, 255, 255, 0.14); }
.sim-key__num { font-size: 22px; font-weight: 500; line-height: 1; }
.sim-key__sub {
  font-size: 9px;
  letter-spacing: 0.18em;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.5);
}
.sim-key--pressed {
  background: var(--accent, #18FFB8) !important;
  color: #00170f !important;
  transform: scale(0.94);
}
.sim-key--pressed .sim-key__sub { color: rgba(0, 23, 15, 0.5); }
