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

/* ============================================
   CSS Variables
   ============================================ */
:root {
  --voice-primary: #3b82f6;
  --voice-primary-hover: #2563eb;
  --voice-success: #10b981;
  --voice-danger: #ef4444;
  --voice-warning: #f59e0b;
  --voice-bg: #1e293b;
  --voice-bg-light: #334155;
  --voice-text: #f1f5f9;
  --voice-text-muted: #94a3b8;
  --voice-border: #475569;
  --voice-recording: #ef4444;
  --voice-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --voice-bar-height: 44px;
  --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
*/
.voice-command-bar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  height: var(--voice-bar-height);
  max-width: 480px;
  width: calc(100% - 48px);
  background: var(--voice-bg);
  border: 1px solid var(--voice-border);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 12px;
  z-index: 9999;
  box-shadow: var(--voice-shadow);
  transition: all var(--voice-transition);
  backdrop-filter: blur(8px);
  background: rgba(30, 41, 59, 0.9);
  pointer-events: none; /* Container passes clicks through */
}

/* 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(30, 41, 59, 0.95) 0%, rgba(63, 21, 21, 0.95) 100%);
  border-color: var(--voice-recording);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 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: 32px;
  height: 32px;
  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: 0 2px 6px rgba(59, 130, 246, 0.4);
  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: pulse-recording 1.5s infinite;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
}

@keyframes pulse-recording {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

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

.voice-bar-status {
  font-size: 11px;
  color: var(--voice-text-muted);
  min-width: 60px;
  display: none; /* Hide status text in compact mode */
}

.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 (compact, limited width) */
.voice-bar-center {
  flex: 1;
  max-width: 280px;
  overflow: hidden;
  min-width: 0; /* Allow flex shrinking */
}

.voice-bar-transcript {
  font-size: 13px;
  color: var(--voice-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.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
 */
.streaming-correction {
  color: var(--voice-success);
  background: rgba(var(--voice-success-rgb, 34, 197, 94), 0.15);
  border-radius: 3px;
  padding: 0 2px;
  animation: correction-flash 0.6s ease-out;
}

@keyframes correction-flash {
  0% {
    background: rgba(var(--voice-success-rgb, 34, 197, 94), 0.4);
    color: var(--voice-success);
  }
  100% {
    background: rgba(var(--voice-success-rgb, 34, 197, 94), 0.15);
    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 and context indicators in compact floating bar */
.voice-bar-patient {
  display: none;
}

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

/* Provider indicator - compact style */
.voice-bar-provider {
  font-size: 10px;
  padding: 2px 6px;
  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(30, 41, 59, 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: #059669;
}

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

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

.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: rgba(16, 185, 129, 0.15);
}

.voice-diff-content tr.removed td {
  background: rgba(239, 68, 68, 0.15);
}

.voice-diff-content tr.changed td {
  background: rgba(245, 158, 11, 0.15);
}

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

.voice-diff-content del {
  background: rgba(239, 68, 68, 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: #0f172a;
  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: #0f172a;
  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: rgba(16, 185, 129, 0.1);
  border-left-color: var(--voice-success);
}

.voice-diff-hunk.delete {
  background: rgba(239, 68, 68, 0.1);
  border-left-color: var(--voice-danger);
}

.voice-diff-hunk.replace {
  background: rgba(245, 158, 11, 0.1);
  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: #1e293b;
}

.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(239, 68, 68, 0.2);
  color: var(--voice-danger);
  text-decoration: line-through;
}

.voice-diff-new-text {
  background: rgba(16, 185, 129, 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: rgba(245, 158, 11, 0.1);
}
