/**
 * Voice Layer Styles
 *
 * Styles for:
 * - Voice Command Bar (global footer)
 * - Diff Preview Panel (slide-up)
 * - Status indicators and animations
 */

/* ============================================
   Dark Roast Beachhead — Voice Layer
   ============================================
   ARCHITECTURE: Self-contained token block. Works without global dark-roast-tokens.css.
   WHY: Organic migration — voice bar adopts warm coffee palette independently.
   TRADEOFF: ~25 local declarations vs. requiring global stylesheet load order.
*/
:root {
  /* DR base tokens (local copies — no dependency on dark-roast-tokens.css) */
  --dr-void:           #120C06;
  --dr-obsidian:       #160E08;
  --dr-grain:          #2A1C13;
  --dr-grain-hover:    #382818;
  --dr-crema:          #FFF7EE;
  --dr-mocha:          #8B7355;
  --dr-bone:           #EBE1D7;
  --dr-crater:         #5A453A;  /* v2-hardened (dark-roast-tokens.css:740); #3C2A21 here nullified every crater border app-wide */
  --dr-crater-lt:      #4D3B31;
  --dr-rustic:         #480404;
  --dr-amber:          #E69A4C;
  --dr-scarlet:        #C44C4C;
  --dr-teal:           #4CC4B4;

  /* DR opacity variants */
  --dr-teal-dim:       rgba(76, 196, 180, 0.40);
  --dr-teal-subtle:    rgba(76, 196, 180, 0.10);
  --dr-scarlet-dim:    rgba(196, 76, 76, 0.40);
  --dr-scarlet-subtle: rgba(196, 76, 76, 0.10);
  --dr-amber-subtle:   rgba(230, 154, 76, 0.10);

  /* DR glow effects (box-shadows, not colors) */
  --dr-glow-teal:
      0 0 2px rgba(255, 255, 255, 0.4),
      0 0 8px rgba(76, 196, 180, 0.35),
      0 0 24px rgba(76, 196, 180, 0.12);
  --dr-glow-teal-ghost:
      0 0 4px rgba(76, 196, 180, 0.08),
      0 0 12px rgba(76, 196, 180, 0.03);
  --dr-glow-scarlet:
      0 0 2px rgba(255, 255, 255, 0.3),
      0 0 8px rgba(196, 76, 76, 0.40),
      0 0 16px rgba(196, 76, 76, 0.15);

  /* Voice aliases → Dark Roast tokens */
  --voice-primary: var(--dr-teal);
  --voice-primary-hover: #3AA89A;
  --voice-success: var(--dr-teal);
  --voice-danger: var(--dr-scarlet);
  --voice-warning: var(--dr-amber);
  --voice-bg: var(--dr-grain);
  --voice-bg-light: var(--dr-crater);
  --voice-text: var(--dr-crema);
  --voice-text-muted: var(--dr-mocha);
  --voice-border: var(--dr-crater-lt);
  --voice-recording: var(--dr-scarlet);
  --voice-shadow: var(--dr-glow-teal-ghost);
  --voice-bar-height: 64px;
  --voice-panel-height: 300px;
  --voice-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Voice Command Bar (Floating Pill - Click-Through)
   ============================================
   ARCHITECTURE: Compact floating bar with pointer-events passthrough
   WHY: Bar must never block underlying action buttons (generate, cancel, prior notes)
   TRADEOFF: Click-through means only interactive elements capture clicks
   NOTE: Container has pointer-events:none, children re-enable as needed
*/
/* FIX (2026-02-26): Raised from bottom:12px → bottom:64px.
   BUG: Bar clipped by browser chrome / OS taskbar, invisible when rail open.
   FIX: 64px clears bottom edge, stays visible alongside rail.
   FIX (2026-03-09): Shifted left when rail is expanded.
   BUG: Bar centered on full viewport overlapped the 900px note rail.
   FIX: Use CSS calc to center on the content area (viewport minus rail width).
   --rail-width-expanded is 920px but rendered at 900px on >=1600px screens.
   Using right offset approach: right: auto + left: calc(50% - 450px) when rail open. */
.voice-command-bar {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  height: var(--voice-bar-height);
  max-width: 640px;
  width: calc(100% - 48px);
  background: var(--voice-bg);
  border: 1px solid var(--voice-border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 4px 16px;
  z-index: 9999;
  box-shadow: var(--voice-shadow);
  transition: all var(--voice-transition);
  backdrop-filter: blur(8px);
  background: rgba(42, 28, 19, 0.92);
  pointer-events: none; /* Container passes clicks through */
}

/* FIX (2026-03-09): Shift voice bar left when note rail is expanded
   WHY: Bar centered on full viewport overlaps the 900px rail on the right
   FIX: Center on the content area instead (viewport minus rail width) */
body.rail-open .voice-command-bar {
  left: calc(50% - var(--rail-width-expanded, 920px) / 2);
}

/* FIX (2026-08-23): the iPhone panel had no matching rail-open rule, so when
   the rail opened the bar shifted left and the panel stayed centered — the
   two surfaces visibly detached. Keep them anchored together. */
body.rail-open .voice-iphone-panel {
  left: calc(50% - var(--rail-width-expanded, 920px) / 2);
}

/* Re-enable pointer events ONLY on actual interactive elements */
.voice-command-bar button,
.voice-command-bar select,
.voice-command-bar input,
.voice-command-bar [role="button"],
.voice-command-bar a {
  pointer-events: auto;
}

/* Section containers remain click-through */
.voice-bar-left,
.voice-bar-center,
.voice-bar-right {
  pointer-events: none;
}

.voice-command-bar.recording {
  background: linear-gradient(135deg, rgba(42, 28, 19, 0.95) 0%, rgba(72, 4, 4, 0.95) 100%);
  border-color: var(--voice-recording);
  box-shadow: 0 4px 24px rgba(196, 76, 76, 0.3);
}

/* Left section: Mic button + Status (compact) */
.voice-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.voice-bar-mic {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--voice-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--voice-transition);
  box-shadow: var(--dr-glow-teal);
  flex-shrink: 0;
}

.voice-bar-mic:hover {
  background: var(--voice-primary-hover);
  transform: scale(1.08);
}

.voice-bar-mic.recording {
  background: var(--voice-recording);
  animation: dr-pulse-recording 1.5s infinite;
  box-shadow: 0 0 0 0 rgba(196, 76, 76, 0.7);
}

@keyframes dr-pulse-recording {
  0% { box-shadow: 0 0 0 0 rgba(196, 76, 76, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(196, 76, 76, 0); }
  100% { box-shadow: 0 0 0 0 rgba(196, 76, 76, 0); }
}

.voice-bar-mic svg {
  width: 20px;
  height: 20px;
  color: white;
}

.voice-bar-status {
  font-size: 13px;
  color: var(--dr-bone);
  min-width: 60px;
  display: flex;
  align-items: center;
}

.voice-bar-status.listening .status-text {
  color: var(--voice-recording);
}

/* Show status text during automation runs for UI tests. */
.voice-command-bar[data-automation-mode="true"] .voice-bar-status {
  display: flex;
  align-items: center;
}

.voice-bar-status.processing .status-text {
  color: var(--voice-warning);
}

.voice-bar-status.proposal .status-text {
  color: var(--voice-success);
}

.voice-bar-status.error .status-text {
  color: var(--voice-danger);
}

/* Center section: Transcript (wider, multi-line) */
.voice-bar-center {
  flex: 1;
  max-width: 400px;
  overflow: hidden;
  min-width: 0; /* Allow flex shrinking */
}

.voice-bar-transcript {
  font-size: 15px;
  color: var(--voice-text);
  /* FIX (2026-08-23): was a 2-line -webkit-line-clamp with overflow hidden
     and no scroll — long dictation was unreadable and unverifiable. Scroll
     instead of clip, and let the doctor select/copy the text. */
  max-height: 4.2em;
  overflow-y: auto;
  overscroll-behavior: contain;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

.transcript-placeholder {
  color: var(--voice-text-muted);
  font-style: italic;
}

.transcript-listening {
  color: var(--voice-warning);
}

.transcript-partial {
  color: var(--voice-text-muted);
}

.transcript-final {
  color: var(--voice-text);
}

.transcript-corrections {
  color: var(--voice-success);
  font-size: 12px;
}

/* Streaming NLP Correction Highlight
 * ARCHITECTURE: Visual feedback for real-time corrections
 * WHY: Shows user "hyper tension" -> "hypertension" while speaking
 * NOTE: Replaced rgba(var()) hack with direct DR token references
 */
.streaming-correction {
  color: var(--voice-success);
  background: var(--dr-teal-subtle);
  border-radius: 3px;
  padding: 0 2px;
  animation: correction-flash 0.6s ease-out;
}

@keyframes correction-flash {
  0% {
    background: var(--dr-teal-dim);
    color: var(--voice-success);
  }
  100% {
    background: var(--dr-teal-subtle);
    color: var(--voice-success);
  }
}

.transcript-partial.corrected {
  color: var(--voice-text);
}

.transcript-error {
  color: var(--voice-danger);
}

/* Right section: Patient + Context + Mode */
.voice-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Hide patient indicator by default; show when active */
.voice-bar-patient {
  display: none;
}

.voice-bar-patient.active {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--dr-bone);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-bar-context {
  display: none;
}

/* Provider indicator - compact style */
.voice-bar-provider {
  font-size: 11px;
  padding: 4px 10px;
  background: var(--voice-bg-light);
  border-radius: 10px;
  color: var(--voice-text-muted);
}

.voice-bar-mode {
  background: var(--voice-bg-light);
  border: 1px solid var(--voice-border);
  color: var(--voice-text);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
}

.voice-bar-mode:focus {
  outline: none;
  border-color: var(--voice-primary);
}

/* ============================================
   Diff Preview Panel
   ============================================ */
.voice-diff-panel {
  position: fixed;
  bottom: calc(var(--voice-bar-height) + 24px); /* Above floating bar + margin */
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  max-width: 800px;
  width: calc(100% - 48px);
  height: var(--voice-panel-height);
  background: rgba(22, 14, 8, 0.98);
  border: 1px solid var(--voice-border);
  border-radius: 16px;
  transition: transform var(--voice-transition);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.voice-diff-panel.visible {
  transform: translateX(-50%) translateY(0);
}

/* Panel Header */
.voice-diff-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--voice-border);
  background: var(--voice-bg-light);
}

.voice-diff-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--voice-text);
}

.voice-diff-icon {
  font-size: 18px;
}

.voice-diff-panel-actions {
  display: flex;
  gap: 8px;
}

.voice-diff-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.voice-diff-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.voice-diff-btn-accept {
  background: var(--voice-success);
  color: white;
}

.voice-diff-btn-accept:hover:not(:disabled) {
  background: #3AA89A;
}

.voice-diff-btn-reject {
  background: var(--voice-danger);
  color: white;
}

.voice-diff-btn-reject:hover:not(:disabled) {
  background: #A33A3A;
}

.voice-diff-btn-undo,
.voice-diff-btn-redo {
  background: var(--voice-bg);
  color: var(--voice-text);
  border: 1px solid var(--voice-border);
  padding: 8px 12px;
}

.voice-diff-btn-undo:hover:not(:disabled),
.voice-diff-btn-redo:hover:not(:disabled) {
  background: var(--voice-bg-light);
}

/* Panel Body */
.voice-diff-panel-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.voice-diff-transcript {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--voice-text-muted);
  border-bottom: 1px solid var(--voice-border);
  display: none;
}

.voice-transcript-label {
  color: var(--voice-primary);
  font-weight: 500;
}

.voice-diff-columns {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.voice-diff-main {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.voice-diff-sidebar {
  width: 280px;
  border-left: 1px solid var(--voice-border);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.voice-diff-content {
  min-height: 100%;
}

.voice-diff-placeholder {
  color: var(--voice-text-muted);
  font-style: italic;
  padding: 20px;
  text-align: center;
}

.voice-diff-processing {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--voice-text-muted);
}

.voice-diff-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--voice-border);
  border-top-color: var(--voice-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.voice-diff-error {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  color: var(--voice-danger);
}

.voice-diff-error-icon {
  font-size: 24px;
}

/* NLP Section */
.voice-diff-nlp,
.voice-diff-metrics {
  padding: 12px 16px;
  font-size: 13px;
  display: none;
}

.voice-nlp-section {
  margin-bottom: 12px;
}

.voice-nlp-section strong {
  color: var(--voice-text);
  display: block;
  margin-bottom: 4px;
}

.voice-nlp-section ul {
  margin: 0;
  padding-left: 16px;
  color: var(--voice-text-muted);
}

.voice-nlp-section li {
  margin: 4px 0;
}

.voice-nlp-section del {
  color: var(--voice-danger);
  text-decoration: line-through;
}

.voice-nlp-section ins {
  color: var(--voice-success);
  text-decoration: none;
}

/* ============================================
   Diff Table Styles (from semantic_diff_service)
   ============================================ */
.voice-diff-content table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
}

.voice-diff-content th {
  background: var(--voice-bg-light);
  color: var(--voice-text);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--voice-border);
}

.voice-diff-content td {
  padding: 8px 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--voice-border);
}

.voice-diff-content tr.added td {
  background: var(--dr-teal-subtle);
}

.voice-diff-content tr.removed td {
  background: var(--dr-scarlet-subtle);
}

.voice-diff-content tr.changed td {
  background: var(--dr-amber-subtle);
}

.voice-diff-content ins {
  background: rgba(76, 196, 180, 0.3);
  color: var(--voice-success);
  text-decoration: none;
  padding: 1px 3px;
  border-radius: 2px;
}

.voice-diff-content del {
  background: rgba(196, 76, 76, 0.3);
  color: var(--voice-danger);
  text-decoration: line-through;
  padding: 1px 3px;
  border-radius: 2px;
}

/* ============================================
   Body adjustment when panel is open
   ============================================
   NOTE: Voice bar is now click-through, so no body padding needed
   for the bar itself. Only diff panel needs adjustment.
*/
body.voice-diff-panel-open {
  padding-bottom: calc(var(--voice-bar-height) + var(--voice-panel-height) + 24px);
}

/* ============================================
   Rationale Tooltips for Diff Explainability
   ============================================ */

/* Elements with rationale show tooltip on hover */
[data-rationale] {
  position: relative;
  cursor: help;
}

[data-rationale]::after {
  content: attr(data-rationale);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--dr-void);
  color: var(--voice-text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  max-width: 300px;
  white-space: normal;
  text-align: left;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--voice-border);
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}

[data-rationale]::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--dr-void);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}

[data-rationale]:hover::after,
[data-rationale]:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Styling for diff elements with rationale */
.voice-diff-content [data-rationale] {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

/* Hunk-based diff display */
.voice-diff-hunks {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
}

.voice-diff-hunk {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid var(--voice-border);
}

.voice-diff-hunk.insert {
  background: var(--dr-teal-subtle);
  border-left-color: var(--voice-success);
}

.voice-diff-hunk.delete {
  background: var(--dr-scarlet-subtle);
  border-left-color: var(--voice-danger);
}

.voice-diff-hunk.replace {
  background: var(--dr-amber-subtle);
  border-left-color: var(--voice-warning);
}

.voice-diff-hunk-header {
  font-size: 11px;
  color: var(--voice-text-muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.voice-diff-hunk-op {
  text-transform: uppercase;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
}

.voice-diff-hunk.insert .voice-diff-hunk-op {
  background: var(--voice-success);
  color: white;
}

.voice-diff-hunk.delete .voice-diff-hunk-op {
  background: var(--voice-danger);
  color: white;
}

.voice-diff-hunk.replace .voice-diff-hunk-op {
  background: var(--voice-warning);
  color: var(--dr-void);
}

.voice-diff-hunk-rationale {
  font-style: italic;
  color: var(--voice-text-muted);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-diff-hunk-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voice-diff-old-text,
.voice-diff-new-text {
  padding: 4px 8px;
  border-radius: 3px;
}

.voice-diff-old-text {
  background: rgba(196, 76, 76, 0.2);
  color: var(--voice-danger);
  text-decoration: line-through;
}

.voice-diff-new-text {
  background: rgba(76, 196, 180, 0.2);
  color: var(--voice-success);
}

/* ============================================
   Responsive adjustments
   ============================================ */
@media (max-width: 768px) {
  .voice-bar-patient {
    display: none;
  }

  .voice-bar-context .context-icon {
    display: none;
  }

  .voice-diff-sidebar {
    width: 200px;
  }
}

/* ============================================
   Guest Hero Context - Hide voice bar
   ============================================
   WHY: Voice bar is not useful on guest/welcome screen (no patient selected)
   TRADEOFF: Users must sign in before using voice features
*/
.sol-guest-hero:not(.hidden) ~ .voice-command-bar,
body:has(.sol-guest-hero:not(.hidden)) .voice-command-bar {
  display: none;
}

/* Keep voice bar visible under automation runs for UI tests. */
body:has(.sol-guest-hero:not(.hidden)) .voice-command-bar[data-automation-mode="true"] {
  display: flex !important;
}

@media (max-width: 480px) {
  .voice-bar-context {
    display: none;
  }
}

@media (max-width: 640px) {
  .voice-diff-columns {
    flex-direction: column;
  }

  .voice-diff-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--voice-border);
  }

  .voice-diff-btn span:not(:first-child) {
    display: none;
  }
}

/* ============================================
   Conflict Resolution Modal
   ============================================ */
.voice-conflict-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-conflict-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.voice-conflict-content {
  position: relative;
  background: var(--voice-bg);
  border: 1px solid var(--voice-border);
  border-radius: 12px;
  padding: 24px 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: conflictSlideIn 0.2s ease-out;
}

@keyframes conflictSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.voice-conflict-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.voice-conflict-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--voice-text);
  margin-bottom: 8px;
}

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

.voice-conflict-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voice-conflict-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.voice-conflict-btn-refresh {
  background: var(--voice-primary);
  color: white;
  border-color: var(--voice-primary);
}

.voice-conflict-btn-refresh:hover {
  background: var(--voice-primary-hover);
}

.voice-conflict-btn-discard {
  background: transparent;
  color: var(--voice-text);
  border-color: var(--voice-border);
}

.voice-conflict-btn-discard:hover {
  background: var(--voice-bg-light);
}

.voice-conflict-btn-force {
  background: transparent;
  color: var(--voice-warning);
  border-color: var(--voice-warning);
}

.voice-conflict-btn-force:hover {
  background: var(--dr-amber-subtle);
}

/* ============================================
   iPhone Panel (Phase 3 — 2026-02-28)
   ARCHITECTURE: Slide-up panel above voice bar for iPhone pairing, transcript, sections.
   WHY: Unified voice bar owns iPhone mode — panel replaces IPhoneDictationZone's rail UI.
   ============================================ */

.voice-iphone-panel {
  position: fixed;
  bottom: calc(var(--voice-bar-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  max-height: 420px;
  overflow-y: auto;
  background: var(--voice-bg);
  border: 1px solid var(--voice-border);
  border-radius: 12px;
  box-shadow: var(--voice-shadow);
  z-index: 10001;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  color: var(--voice-text);
  animation: iphonePanelSlideUp 0.25s ease-out;
}

.voice-iphone-panel[hidden] {
  display: none;
}

@keyframes iphonePanelSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Header */
.iphone-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--voice-border);
}

.iphone-panel-title {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.iphone-panel-timer {
  font-size: 12px;
  color: var(--voice-text-muted);
  font-variant-numeric: tabular-nums;
}

.iphone-panel-close,
.iphone-panel-disconnect {
  background: transparent;
  border: 1px solid var(--voice-border);
  color: var(--voice-text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.15s;
}

.iphone-panel-close:hover,
.iphone-panel-disconnect:hover {
  color: var(--voice-text);
  border-color: var(--voice-text-muted);
}

/* Body */
.iphone-panel-body {
  padding: 12px 14px;
}

/* Pairing state */
.iphone-panel-pairing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.iphone-panel-qr {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.iphone-panel-url-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.iphone-panel-url {
  flex: 1;
  background: var(--voice-bg-light);
  border: 1px solid var(--voice-border);
  color: var(--voice-text-muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: inherit;
}

.iphone-panel-copy {
  background: var(--voice-bg-light);
  border: 1px solid var(--voice-border);
  color: var(--voice-text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.15s;
}

.iphone-panel-copy:hover {
  background: var(--voice-primary);
  border-color: var(--voice-primary);
}

.iphone-panel-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--voice-text-muted);
}

/* Status dots */
.iphone-panel-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.iphone-panel-dot.waiting {
  background: var(--voice-warning);
  animation: iphoneDotPulse 1.5s ease-in-out infinite;
}

.iphone-panel-dot.recording {
  background: var(--voice-recording);
  animation: iphoneDotPulse 1s ease-in-out infinite;
}

@keyframes iphoneDotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* DOCKED PANEL (2026-08-23): as a child of the bar the panel rides every bar
   position rule (rail shift included) instead of duplicating them, and stacks
   in the bar's context — below the conflict modal, not above it. */
.voice-iphone-panel--docked {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: auto;
  pointer-events: auto;
}

.iphone-panel-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--voice-text-dim, rgba(255, 255, 255, 0.6));
}

.iphone-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.iphone-panel-actions button {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--voice-border, rgba(255, 255, 255, 0.2));
  background: transparent;
  color: var(--voice-text);
  cursor: pointer;
}

.iphone-panel-actions button:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Transcript */
.iphone-panel-transcript {
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  padding: 8px;
  background: var(--voice-bg-light);
  border-radius: 6px;
  line-height: 1.5;
  font-size: 13px;
}

.iphone-panel-placeholder {
  color: var(--voice-text-muted);
  font-style: italic;
}

/* Sections */
.iphone-panel-sections {
  margin-top: 10px;
}

.iphone-panel-sections-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.iphone-panel-sections-count {
  font-size: 12px;
  color: var(--voice-text-muted);
}

.iphone-panel-use-all {
  background: var(--voice-primary);
  border: none;
  color: #fff;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s;
}

.iphone-panel-use-all:hover:not(:disabled) {
  background: var(--voice-primary-hover);
}

.iphone-panel-use-all:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Section cards grid */
.iphone-panel-section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.iphone-section-card {
  background: var(--voice-bg-light);
  border: 1px solid var(--voice-border);
  border-radius: 8px;
  padding: 8px 10px;
  overflow: hidden;
}

.iphone-card-header {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
}

.iphone-card-icon {
  font-size: 14px;
  color: var(--dr-amber);
}

.iphone-card-title {
  font-weight: 600;
  font-size: 12px;
  flex: 1;
}

.iphone-confidence-badge {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}

.iphone-confidence-badge.high {
  color: var(--voice-success);
  background: var(--dr-teal-subtle);
}

.iphone-confidence-badge.medium {
  color: var(--voice-warning);
  background: var(--dr-amber-subtle);
}

.iphone-confidence-badge.low {
  color: var(--voice-danger);
  background: var(--dr-scarlet-subtle);
}

.iphone-confidence-badge.uncertain {
  color: var(--voice-text-muted);
  background: rgba(139, 115, 85, 0.15);
}

.iphone-card-body {
  font-size: 12px;
  line-height: 1.4;
  color: var(--voice-text);
  max-height: 60px;
  overflow-y: auto;
  word-break: break-word;
}

.iphone-card-source {
  font-size: 10px;
  color: var(--voice-text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================
   Dual-Stream Badges (Phase 4 — 2026-02-28)
   ============================================
   ARCHITECTURE: Visual indicators for Flux (fast/draft) vs Nova-3 (final) STT streams.
   WHY: Users need to see which transcript source is active and when crossfade occurs.
*/

.ds-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--term-font-mono, 'JetBrains Mono', monospace);
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 6px;
  letter-spacing: 0.5px;
  vertical-align: middle;
  line-height: 1;
  flex-shrink: 0;
}

.ds-flux {
  background: var(--dr-teal-subtle);
  color: var(--dr-teal);
  border: 1px solid var(--dr-teal-dim);
}

.ds-nova3 {
  background: rgba(230, 154, 76, 0.2);
  color: var(--dr-amber);
  border: 1px solid rgba(230, 154, 76, 0.4);
}

.ds-flux.ds-promoted {
  background: rgba(76, 196, 180, 0.15);
  border-style: dashed;
}

/* Flux text: slightly dimmer to indicate "draft" quality */
.ds-flux-text {
  opacity: 0.8;
}

/* Nova-3 text: crossfade in to replace Flux */
.ds-nova3-text {
  animation: dsFadeIn 0.2s ease-out;
}

@keyframes dsFadeIn {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

/* Waiting spinner for Flux preview */
.ds-waiting {
  font-size: 10px;
  margin-left: 4px;
  animation: dsPulse 1.2s ease-in-out infinite;
}

@keyframes dsPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Flux-promoted transcript — amber warning when Nova-3 timed out and Flux was promoted as final.
   Medical terms may be inaccurate; physician must verify before accepting. */
.flux-promoted-transcript {
  border-left: 3px solid var(--dr-warning, #f59e0b);
  padding-left: 8px;
  opacity: 0.85;
}

.ds-flux-promoted-warn {
  color: var(--dr-warning, #f59e0b);
  font-size: 11px;
  font-style: italic;
  margin-left: 4px;
}

/* Correction indicator — brief flash when Nova-3 replaces Flux */
.ds-correction-indicator {
  color: var(--dr-teal);
  font-size: 11px;
  margin-left: 4px;
  animation: dsFadeIn 0.3s ease-out;
}

/* Preview text (Flux end-of-turn, waiting for Nova-3) */
.ds-preview-text {
  border-bottom: 1px dashed rgba(76, 196, 180, 0.3);
}

/* Final text — querySelector hook + crossfade animation */
.ds-final-text {
  animation: dsFadeIn 0.25s ease-out;
}

/* Bar-level dual-stream indicator — subtle left border accent */
.voice-command-bar.dual-stream {
  border-left: 2px solid var(--dr-teal-dim);
}
