/* ============================================================================
   RESET & BASE STYLES
   ============================================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-user1-bg: #fff3cd;
  --color-user1-border: #ffc107;
  --color-user2-bg: #e7d6ff;
  --color-user2-border: #9c27b0;
  --color-primary: #007bff;
  --color-success: #28a745;
  --color-danger: #dc3545;
  --color-secondary: #6c757d;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;
  --color-bg-light: #f8f9fa;
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background-color: #f0f0f0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.app-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: var(--spacing-md);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
}

.header-info {
  display: flex;
  gap: var(--spacing-md);
  align-items: center;
}

.token-display {
  background: rgba(255, 255, 255, 0.2);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
}

.session-timer {
  background: rgba(255, 255, 255, 0.2);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  min-width: 80px;
  text-align: center;
}

/* ============================================================================
   TOKEN SECTION
   ============================================================================ */

.token-section {
  background: white;
  padding: var(--spacing-md);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.token-input-group {
  display: flex;
  gap: var(--spacing-sm);
  max-width: 600px;
  margin: 0 auto;
}

.token-input {
  flex: 1;
  padding: var(--spacing-sm);
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
}

.token-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.status-message {
  text-align: center;
  margin-top: var(--spacing-sm);
  font-size: 0.9rem;
  min-height: 24px;
}

.status-message.success {
  color: var(--color-success);
}

.status-message.error {
  color: var(--color-danger);
}

/* ============================================================================
   DUAL PANEL CONTAINER
   ============================================================================ */

.dual-panel-container {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

/* ============================================================================
   USER PANELS
   ============================================================================ */

.user-panel {
  display: flex;
  flex-direction: column;
  padding: var(--spacing-md);
  overflow-y: auto;
  border-right: 2px solid white;
  transition: all 0.4s ease; /* Smooth transition for turn-taking */
}

.user-panel:last-child {
  border-right: none;
}

.user1-bg {
  background-color: var(--color-user1-bg);
  border-top: 4px solid var(--color-user1-border);
}

.user2-bg {
  background-color: var(--color-user2-bg);
  border-top: 4px solid var(--color-user2-border);
}

.panel-header {
  margin-bottom: var(--spacing-md);
}

.panel-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ============================================================================
   CONTROLS SECTION
   ============================================================================ */

.controls-section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.control-group label {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--color-text);
}

.language-select,
.device-select {
  padding: var(--spacing-sm);
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}

.language-select:focus,
.device-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* ============================================================================
   STATUS SECTION
   ============================================================================ */

.status-section {
  margin-bottom: var(--spacing-md);
}

.user-status {
  padding: var(--spacing-sm);
  text-align: center;
  font-weight: 600;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid var(--color-border);
}

.user-status.ready {
  background: #d4edda;
  border-color: var(--color-success);
  color: var(--color-success);
}

.user-status.recording {
  background: #fff3cd;
  border-color: #ffc107;
  color: #856404;
}

.user-status.processing {
  background: #cce5ff;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.user-status.warning {
  background: #fff3cd;
  border-color: #ff9800;
  color: #e65100;
  font-weight: 500;
}

.user-status.error {
  background: #f8d7da;
  border-color: #dc3545;
  color: #721c24;
  font-weight: 500;
}

/* Turn-Taking Status Classes */
.user-status.speaking-green {
  background: #d4edda;
  border-color: #28a745;
  color: #155724;
  font-weight: 600;
  animation: pulse-green 2s infinite;
}

.user-status.ready-green {
  background: #e8f5e8;
  border-color: #28a745;
  color: #155724;
  font-weight: 500;
}

.user-status.wait-red {
  background: #f8d7da;
  border-color: #dc3545;
  color: #721c24;
  font-weight: 600;
  animation: pulse-red 2s infinite;
}

.user-status.conflict-orange {
  background: #fff3cd;
  border-color: #ff6b35;
  color: #dc3545;
  font-weight: 700;
  animation: flash-orange 1s infinite;
}

/* Turn-Taking Animations */
@keyframes pulse-green {
  0% { box-shadow: 0 0 5px rgba(40, 167, 69, 0.5); }
  50% { box-shadow: 0 0 15px rgba(40, 167, 69, 0.8); }
  100% { box-shadow: 0 0 5px rgba(40, 167, 69, 0.5); }
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 5px rgba(220, 53, 69, 0.5); }
  50% { box-shadow: 0 0 15px rgba(220, 53, 69, 0.8); }
  100% { box-shadow: 0 0 5px rgba(220, 53, 69, 0.5); }
}

@keyframes flash-orange {
  0% { 
    background: #fff3cd;
    box-shadow: 0 0 10px rgba(255, 107, 53, 0.6);
  }
  50% { 
    background: #ffe0b3;
    box-shadow: 0 0 20px rgba(255, 107, 53, 1);
  }
  100% { 
    background: #fff3cd;
    box-shadow: 0 0 10px rgba(255, 107, 53, 0.6);
  }
}

/* ============================================================================
   TRANSCRIPT SECTION
   ============================================================================ */

.transcript-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  overflow-y: auto;
}

.transcript-box,
.translation-box {
  background: white;
  border-radius: 8px;
  padding: var(--spacing-md);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.transcript-box h3,
.translation-box h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--color-text-muted);
}

.transcript-content,
.translation-content {
  flex: 1;
  padding: var(--spacing-sm);
  background: var(--color-bg-light);
  border-radius: 4px;
  font-size: 1.1rem;
  line-height: 1.6;
  overflow-y: auto;
  min-height: 100px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.transcript-content:empty::before {
  content: 'Waiting for speech...';
  color: var(--color-text-muted);
  font-style: italic;
}

.translation-content:empty::before {
  content: 'Translation will appear here...';
  color: var(--color-text-muted);
  font-style: italic;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

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

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: #0056b3;
}

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

.btn-success:hover:not(:disabled) {
  background-color: #218838;
}

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

.btn-danger:hover:not(:disabled) {
  background-color: #c82333;
}

.btn-secondary {
  background-color: var(--color-secondary);
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #5a6268;
}

.btn-large {
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: 1.2rem;
  min-width: 200px;
}

/* ============================================================================
   FOOTER
   ============================================================================ */

.app-footer {
  background: white;
  padding: var(--spacing-md);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.session-controls {
  display: flex;
  justify-content: center;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
}

.footer-status {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  min-height: 24px;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 1024px) {
  .dual-panel-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .user-panel {
    border-right: none;
    border-bottom: 2px solid white;
  }

  .user-panel:last-child {
    border-bottom: none;
  }
}

@media (max-width: 768px) {
  .app-header h1 {
    font-size: 1.25rem;
  }

  .header-info {
    flex-direction: column;
    gap: var(--spacing-xs);
    align-items: flex-end;
  }

  .token-input-group {
    flex-direction: column;
  }

  .session-controls {
    flex-direction: column;
  }

  .btn-large {
    min-width: auto;
    width: 100%;
  }
}

/* ============================================================================
   COLLAPSIBLE SECTIONS
   ============================================================================ */

.collapsed {
  display: none !important;
}

.collapsible-toggle {
  font-size: 0.9rem;
  color: var(--color-primary);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--color-primary);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: auto;
}

.collapsible-toggle:hover {
  background: white;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-md);
}

/* ============================================================================
   VISUAL TURN-TAKING CUES
   ============================================================================ */

/* Active Turn (Speaking) */
.user-panel.active-turn {
  opacity: 1;
  box-shadow: inset 0 0 20px rgba(40, 167, 69, 0.3), 0 0 15px rgba(40, 167, 69, 0.2);
  border-top-width: 8px; /* Thicker top border */
  border-top-color: #28a745;
  background-color: rgba(212, 237, 218, 0.3); /* Subtle green tint */
}

/* Inactive Turn (Waiting) */
.user-panel.inactive-turn {
  opacity: 0.6;
  filter: grayscale(0.8);
  background-color: #f8f9fa;
  border-top-color: #dee2e6;
}

/* Ensure panel header and status remain readable when dimmed */
.user-panel.inactive-turn .panel-header h2,
.user-panel.inactive-turn .user-status {
  filter: grayscale(0); /* Keep text somewhat legible */
}
