/*
 * device-test.css — "Test speaker & microphone" wizard (device-test.js).
 * Load after style.css / devices.css:
 *   <link rel="stylesheet" href="/device-test.css?v=1">
 *
 * The dialog is mounted on <body>, outside #screen-call; the call-screen
 * tokens (--call-menu, --call-text, …) come from theme.css :root, so the
 * dialog follows the light / dark theme. `color-scheme: var(--color-scheme)`
 * keeps native <select> popups and scrollbars in step with it.
 */

/* ---- Entry points ------------------------------------------------------ */
.dt-entry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  align-self: center;
  max-width: 100%;
  min-height: 40px;
  padding: 8px 18px 8px 14px;
  border: 1px solid var(--border-color, rgba(55, 65, 81, 0.5));
  border-radius: 999px;
  background: var(--fg-a04);
  color: var(--call-accent-text, #ffb38a);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms var(--call-ease, ease-out), border-color 150ms var(--call-ease, ease-out);
}

.dt-entry svg {
  flex-shrink: 0;
}

.dt-entry:hover {
  background: var(--call-accent-soft, rgba(255, 107, 31, 0.16));
  border-color: var(--call-accent, #FF6B1F);
}

.dt-entry:focus-visible {
  outline: 2px solid var(--call-focus, #ff7f3d);
  outline-offset: 2px;
}

/* ⋮ menu item: phones only (desktop reaches it from the mic chevron). */
.more-menu-item.dt-menu-item {
  display: none;
}

@media (max-width: 599px) and (pointer: coarse) {
  .more-menu-item.dt-menu-item {
    display: flex;
  }
}

/* ---- Dialog shell ------------------------------------------------------ */
.dt-root {
  --dt-surface: var(--call-menu, #28292a);
  --dt-raised: rgba(255, 255, 255, 0.05);
  --dt-raised-hover: var(--call-menu-hover, #353739);
  --dt-border: var(--call-border, #3c4043);
  --dt-text: var(--call-text, #e3e3e3);
  --dt-text-2: var(--call-text-muted, #a8abaf);
  --dt-ease: var(--call-ease, cubic-bezier(0.2, 0, 0, 1));
  position: fixed;
  inset: 0;
  z-index: 1060; /* above the sign-in modal (1000), below idle-guard (1100) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim-a60);
  color-scheme: var(--color-scheme);
  opacity: 0;
  transition: opacity 200ms var(--dt-ease);
}

.dt-root.dt-in {
  opacity: 1;
}

.dt-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 460px;
  max-width: 100%;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 20px 24px 24px;
  border: 1px solid var(--dt-border);
  border-radius: 24px;
  background: var(--dt-surface);
  box-shadow: 0 24px 64px var(--shadow-a55);
  color: var(--dt-text);
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  transform: translateY(8px) scale(0.98);
  transition: transform 240ms var(--dt-ease);
}

.dt-root.dt-in .dt-dialog {
  transform: none;
}

.dt-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.dt-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--dt-text);
}

.dt-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin-right: -8px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--dt-text-2);
  cursor: pointer;
  transition: background-color 150ms var(--dt-ease), color 150ms var(--dt-ease);
}

.dt-close:hover {
  background: var(--dt-raised-hover);
  color: var(--dt-text);
}

/* Progress: Speaker · Microphone */
.dt-steps {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.dt-steps[hidden] {
  display: none;
}

.dt-step {
  flex: 1 1 0;
  padding-top: 8px;
  border-top: 3px solid var(--dt-border);
  font-size: 12px;
  font-weight: 500;
  color: var(--dt-text-2);
  transition: border-color 200ms var(--dt-ease), color 200ms var(--dt-ease);
}

.dt-step-on {
  border-top-color: var(--call-accent, #FF6B1F);
  color: var(--dt-text);
}

.dt-step-done {
  border-top-color: var(--call-accent-pressed, #e85a10);
  color: var(--dt-text-2);
}

/* "You're muted while testing" */
.dt-chip {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  margin: 0 0 16px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: var(--call-accent-soft, rgba(255, 107, 31, 0.16));
  color: var(--call-accent-text, #ffb38a);
  font-size: 13px;
  font-weight: 500;
}

.dt-chip[hidden] {
  display: none;
}

/* ---- Step body --------------------------------------------------------- */
.dt-body {
  display: flex;
  flex-direction: column;
}

.dt-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 0 14px;
  border-radius: 50%;
  background: var(--dt-raised);
  color: var(--call-accent-text, #ffb38a);
}

.dt-hero-live {
  background: var(--call-accent-soft, rgba(255, 107, 31, 0.16));
}

.dt-hero-live .dt-wave {
  animation: dt-wave 1.2s var(--dt-ease) infinite;
}

.dt-hero-live .dt-wave-2 {
  animation-delay: 0.2s;
}

@keyframes dt-wave {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.dt-hero-rec {
  background: var(--danger-a18);
  color: var(--danger-text);
  animation: dt-pulse 1.4s ease-in-out infinite;
}

@keyframes dt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--pulse-danger-a35); }
  50% { box-shadow: 0 0 0 10px var(--pulse-danger-a00); }
}

.dt-hero-ok {
  background: var(--green-a16);
  color: var(--color-success, #34C759);
}

.dt-q {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--dt-text);
  overflow-wrap: anywhere;
}

/* Focused programmatically on a step change (tabindex=-1) so screen readers
   start there; it is not a control, so no focus ring. */
.dt-q:focus {
  outline: none;
}

.dt-sub {
  min-height: 1.45em;
  margin: 6px 0 16px;
  color: var(--dt-text-2);
}

.dt-sub-warn {
  color: var(--warning-text);
}

.dt-hint {
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--dt-raised);
  font-size: 13px;
  color: var(--dt-text-2);
}

/* ---- Device picker (native <select>, pill-styled) ---------------------- */
.dt-label {
  display: block;
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--dt-text-2);
}

.dt-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.dt-select-ico,
.dt-select-caret {
  position: absolute;
  top: 50%;
  display: inline-flex;
  transform: translateY(-50%);
  pointer-events: none;
}

.dt-select-ico {
  left: 14px;
  color: var(--call-accent-text, #ffb38a);
}

.dt-select-caret {
  right: 14px;
  color: var(--dt-text-2);
}

.dt-select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 40px 0 44px;
  border: 1px solid var(--dt-border);
  border-radius: 999px;
  background: var(--dt-raised);
  color: var(--dt-text);
  font: inherit;
  font-size: 14px;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color 150ms var(--dt-ease), border-color 150ms var(--dt-ease);
}

.dt-select:hover:not(:disabled) {
  background: var(--dt-raised-hover);
}

.dt-select:disabled {
  cursor: default;
  opacity: 0.65;
}

.dt-select option {
  background: var(--dt-surface);
  color: var(--dt-text);
}

/* ---- Meter -------------------------------------------------------------- */
.dt-meter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  color: var(--dt-text-2);
}

.dt-meter-row > svg {
  flex-shrink: 0;
}

.dt-meter {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 3px;
  height: 18px;
  min-width: 0;
}

/* Segmented input-level bar (Zoom-style). */
.dt-seg {
  flex: 1 1 0;
  height: 8px;
  border-radius: 2px;
  background: var(--surface-tonal-hover);
  transition: background-color 80ms linear;
}

.dt-seg:first-child {
  border-radius: 999px 2px 2px 999px;
}

.dt-seg:last-child {
  border-radius: 2px 999px 999px 2px;
}

.dt-seg.on {
  background: var(--call-accent, #FF6B1F);
}

.dt-count {
  min-width: 2.5em;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--dt-text);
}

.dt-meter-live .dt-count::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--call-danger, #ea4335);
  vertical-align: 1px;
}

/* ---- Actions ----------------------------------------------------------- */
.dt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
}

.dt-spacer {
  flex: 1 1 auto;
}

.dt-more {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.dt-more:empty {
  display: none;
}

.dt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 88px;
  height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms var(--dt-ease), border-color 150ms var(--dt-ease), color 150ms var(--dt-ease), transform 120ms var(--dt-ease);
}

.dt-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.dt-btn:focus-visible,
.dt-select:focus-visible,
.dt-close:focus-visible {
  outline: 2px solid var(--call-focus, #ff7f3d);
  outline-offset: 2px;
}

.dt-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

.dt-btn-primary {
  background: var(--call-accent, #FF6B1F);
  color: var(--on-fill, #fff);
}

.dt-btn-primary:hover:not(:disabled) {
  background: var(--call-accent-hover, #ff7f3d);
}

.dt-btn-secondary {
  border-color: var(--dt-border);
  background: var(--dt-raised);
  color: var(--dt-text);
}

.dt-btn-secondary:hover:not(:disabled) {
  background: var(--dt-raised-hover);
}

.dt-btn-stop svg {
  color: var(--danger-text);
}

.dt-btn-ghost {
  min-width: 0;
  padding: 0 14px 0 12px;
  background: transparent;
  color: var(--call-accent-text, #ffb38a);
}

.dt-btn-ghost:hover:not(:disabled) {
  background: var(--call-accent-soft, rgba(255, 107, 31, 0.16));
}

.dt-btn-link {
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  background: transparent;
  color: var(--call-accent-text, #ffb38a);
  font-size: 14px;
  font-weight: 500;
}

.dt-btn-link:hover:not(:disabled) {
  background: var(--call-accent-soft, rgba(255, 107, 31, 0.16));
}

.dt-hint .dt-btn-link {
  height: 32px;
  margin: 2px 0 -6px -12px;
  vertical-align: baseline;
}

/* ---- Done --------------------------------------------------------------- */
.dt-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
}

.dt-summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--dt-raised);
}

.dt-summary-row dt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: var(--dt-text-2);
}

.dt-summary-row dt svg {
  color: var(--call-accent-text, #ffb38a);
}

.dt-summary-row dd {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--dt-text);
  font-weight: 500;
}


/* Screen-reader-only live region */
.dt-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Phones: bottom sheet ----------------------------------------------- */
@media (max-width: 599px) {
  .dt-root {
    align-items: flex-end;
    padding: 0;
  }

  .dt-dialog {
    width: 100%;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform 280ms var(--dt-ease);
  }

  .dt-dialog::before {
    content: '';
    display: block;
    flex-shrink: 0;
    width: 36px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 999px;
    background: var(--dt-border);
  }

  .dt-hero {
    width: 52px;
    height: 52px;
    margin-bottom: 10px;
  }

  .dt-q {
    font-size: 18px;
  }

  /* Yes / No share the row; secondary actions wrap above them. */
  .dt-actions .dt-btn-primary,
  .dt-actions .dt-btn-secondary {
    flex: 1 1 0;
    min-width: 0;
  }

  /* A spacer after a ghost action breaks the row; a leading one is unused. */
  .dt-actions .dt-btn + .dt-spacer {
    flex-basis: 100%;
    height: 0;
  }

  .dt-actions .dt-spacer:first-child {
    display: none;
  }

  .dt-actions .dt-btn-ghost:first-child {
    margin-left: -12px;
  }
}

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .dt-root,
  .dt-dialog,
  .dt-step,
  .dt-seg,
  .dt-btn,
  .dt-entry {
    transition: none;
  }

  .dt-dialog,
  .dt-root.dt-in .dt-dialog {
    transform: none;
  }

  .dt-hero-live .dt-wave,
  .dt-hero-rec {
    animation: none;
  }

  .dt-btn:active:not(:disabled) {
    transform: none;
  }
}
