/**
 * Live Customer Support Co-Pilot - CSS Design System
 * Based on UI UX Pro Max recommendations:
 * - Style: Dark Mode (OLED)
 * - Typography: Fira Code / Fira Sans
 * - Colors: Blue primary (#1E40AF), Amber CTA (#F59E0B)
 */

/* ====== FONTS ====== */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

/* ====== CSS VARIABLES ====== */
:root {
  /* Dark Mode Colors (Default) */
  --color-background: #0a0a0f;
  --color-surface: #12121a;
  --color-surface-elevated: #1a1a24;
  --color-surface-hover: #22222e;
  
  --color-primary: #1E40AF;
  --color-primary-light: #3B82F6;
  --color-primary-glow: rgba(30, 64, 175, 0.3);
  
  --color-secondary: #3B82F6;
  --color-cta: #F59E0B;
  --color-cta-hover: #D97706;
  
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-danger: #EF4444;
  --color-info: #3B82F6;
  
  --color-text-primary: #F8FAFC;
  --color-text-secondary: #94A3B8;
  --color-text-muted: #64748B;
  
  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-hover: rgba(255, 255, 255, 0.15);
  
  /* Typography */
  --font-sans: 'Fira Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Fira Code', 'SF Mono', Consolas, monospace;
  
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px var(--color-primary-glow);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  
  /* Z-Index */
  --z-dropdown: 100;
  --z-modal: 200;
  --z-tooltip: 300;
  --z-toast: 400;
}

/* ====== RESET & BASE ====== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-background);
  height: 100%;
  overflow: hidden; /* Prevent body scroll */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ====== MAIN LAYOUT (CSS GRID) ====== */
.app-container {
  display: grid;
  /* 280px Sidebar | 1fr Main Content | 380px Detail Panel */
  grid-template-columns: 280px 1fr 380px;
  /* 73px Header | Remaining Height Content */
  grid-template-rows: 73px 1fr;
  grid-template-areas:
    "header header header"
    "sidebar main detail";
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--color-background);
}

/* Header - Spans full width */
.header {
  grid-area: header;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  /* Glassmorphism attempt - optional */
  /* backdrop-filter: blur(10px); */
  /* background-color: rgba(18, 18, 26, 0.95); */
}

/* Sidebar - Left Panel */
.sidebar {
  grid-area: sidebar;
  background-color: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Internal scrolling handled by children */
  height: 100%;
}

/* Main Content - Center Panel */
.main-content {
  grid-area: main;
  background-color: var(--color-background);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  min-width: 0; /* Prevent flex/grid blowout */
}

/* Detail Panel - Right Panel */
.detail-panel {
  grid-area: detail;
  background-color: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

/* ====== HEADER COMPONENTS ====== */
.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo svg {
  width: 24px;
  height: 24px;
  color: white;
}

.header-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text-primary);
}

.header-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.header-stats {
  display: flex;
  gap: var(--space-6);
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
}

.stat-value.active { color: var(--color-success); }
.stat-value.waiting { color: var(--color-warning); }
.stat-value.human { color: var(--color-info); }

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

/* ====== SIDEBAR COMPONENTS ====== */
.sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

/* Custom scrollbar for sessions list */
.sessions-list::-webkit-scrollbar {
  width: 6px;
}
.sessions-list::-webkit-scrollbar-track {
  background: transparent;
}
.sessions-list::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
.sessions-list::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

.session-card {
  background-color: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: all var(--transition-base);
}

.session-card:hover {
  background-color: var(--color-surface-hover);
  border-color: var(--color-border-hover);
}

.session-card.selected {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
  background-color: rgba(30, 64, 175, 0.1);
}

.session-card.human-takeover {
  border-left: 3px solid var(--color-warning);
}

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-2);
}

.session-id {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.session-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
}

.session-status.ai {
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--color-info);
}

.session-status.human {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
}

.session-status.waiting {
  background-color: rgba(100, 116, 139, 0.15);
  color: var(--color-text-muted);
}

.session-preview {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ====== MAIN CONTENT COMPONENTS ====== */
.conversation-header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0; /* Prevent shrinking */
}

.conversation-info h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.conversation-mode {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.mode-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.mode-indicator.ai { background-color: var(--color-success); }
.mode-indicator.human { background-color: var(--color-warning); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.conversation-actions {
  display: flex;
  gap: var(--space-2);
}

#conversation-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.transcript-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* CRITICAL for flex nesting */
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scroll-behavior: smooth;
}

/* Custom scrollbar for transcript */
.transcript-container::-webkit-scrollbar {
  width: 8px;
}
.transcript-container::-webkit-scrollbar-track {
  background: var(--color-surface);
}
.transcript-container::-webkit-scrollbar-thumb {
  background: var(--color-border-hover);
  border-radius: var(--radius-full);
}
.transcript-container::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

.message {
  display: flex;
  gap: var(--space-3);
  max-width: 85%;
}

.message.customer {
  align-self: flex-start;
}

.message.ai,
.message.supervisor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message.customer .message-avatar {
  background-color: var(--color-surface-elevated);
  color: var(--color-text-secondary);
}

.message.ai .message-avatar {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: white;
}

.message.supervisor .message-avatar {
  background-color: var(--color-warning);
  color: var(--color-background);
}

.message-content {
  background-color: var(--color-surface-elevated);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.message.ai .message-content {
  background: linear-gradient(135deg, rgba(30, 64, 175, 0.1), rgba(59, 130, 246, 0.05));
  border-color: rgba(59, 130, 246, 0.2);
}

.message.supervisor .message-content {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.05));
  border-color: rgba(245, 158, 11, 0.2);
}

.message-text {
  font-size: var(--text-sm);
  line-height: 1.5;
}

.message-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* Audio Controls */
.audio-controls {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  background-color: var(--color-surface);
  display: flex;
  gap: var(--space-4);
  align-items: center;
  flex-shrink: 0; /* Prevent shrinking */
}

.audio-visualizer {
  flex: 1;
  height: 48px;
  background-color: var(--color-surface-elevated);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 var(--space-4);
}

.audio-bar {
  width: 3px;
  height: 20px;
  background-color: var(--color-primary-light);
  border-radius: var(--radius-full);
  transition: height var(--transition-fast);
}

.audio-bar.active {
  animation: audioWave 0.5s ease-in-out infinite;
}

@keyframes audioWave {
  0%, 100% { height: 8px; }
  50% { height: 32px; }
}

/* ====== DETAIL PANEL COMPONENTS ====== */
.detail-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.detail-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Detail Content Container - Needs to scroll independently */
#detail-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom scrollbar for details */
#detail-content::-webkit-scrollbar {
  width: 6px;
}
#detail-content::-webkit-scrollbar-track {
  background: transparent;
}
#detail-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.detail-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.detail-section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-3);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.detail-label {
  color: var(--color-text-muted);
}

.detail-value {
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Context Injection */
.context-input {
  padding: var(--space-4);
}

.context-textarea {
  width: 100%;
  min-height: 120px;
  background-color: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  resize: vertical;
  transition: border-color var(--transition-base);
}

.context-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.context-textarea::placeholder {
  color: var(--color-text-muted);
}

/* ====== BUTTONS ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

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

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-light);
}

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

.btn-cta:hover:not(:disabled) {
  background-color: var(--color-cta-hover);
}

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

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

.btn-ghost {
  background-color: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--color-surface-hover);
  border-color: var(--color-border-hover);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

/* Premium Glass Button (for Call Summaries) */
.btn-glass-premium {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  text-decoration: none !important; /* Force remove underline */
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.btn-glass-premium:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--color-primary-light);
  box-shadow: 0 0 15px var(--color-primary-glow);
  transform: translateY(-1px);
  color: white;
}

.btn-glass-premium::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: translateX(-100%);
  transition: 0.5s;
}

.btn-glass-premium:hover::before {
  transform: translateX(100%);
}

/* ====== EMPTY STATE ====== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--color-surface-elevated), var(--color-surface-hover));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-6);
}

.empty-state-icon svg {
  width: 40px;
  height: 40px;
  color: var(--color-text-muted);
}

.empty-state-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 300px;
}

/* ====== TOAST NOTIFICATIONS ====== */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast {
  background-color: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 300px;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--color-success); }
.toast.warning .toast-icon { color: var(--color-warning); }
.toast.error .toast-icon { color: var(--color-danger); }
.toast.info .toast-icon { color: var(--color-info); }

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}

.toast-message {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ====== LOADING STATES ====== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-elevated) 25%,
    var(--color-surface-hover) 50%,
    var(--color-surface-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ====== RESPONSIVE (Basic adjustments) ====== */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: 73px auto 1fr;
    grid-template-areas:
      "header"
      "sidebar"
      "main";
  }
  
  .detail-panel {
    display: none; /* Hide details on small screens for now */
  }
  
  .sidebar {
    height: 150px; /* Small height for mobile sidebar */
    resize: vertical;
  }
}
