/* ============================================
   CollabAI - Main Stylesheet
   Modular, maintainable styles for the collaborative canvas
   ============================================ */

  /* CSS Variables - Theme System */
  :root {
    --surface: #f7f4ee;
    --surface-alt: #ffffff;
    --surface-contrast: #0e3a2b;
    --text-primary: #0f172a;
    --text-muted: rgba(15, 23, 42, 0.65);
    --grid-dot-color: rgba(15, 23, 42, 0.18);
    --grid-major-color: rgba(15, 23, 42, 0.35);
    --border-color: rgba(17, 24, 39, 0.08);
    --canvas-bg: #f7f3eb;
    --canvas-overlay: rgba(15, 23, 42, 0.08);
  }

/* Light Theme */
body[data-theme="light"] {
  --surface: #f7f4ee;
  --surface-alt: #ffffff;
  --surface-contrast: #0e3a2b;
  --text-primary: #0f172a;
  --text-muted: rgba(15, 23, 42, 0.65);
  --grid-dot-color: rgba(17, 24, 39, 0.12);
  --grid-major-color: rgba(17, 24, 39, 0.26);
  --border-color: rgba(17, 24, 39, 0.08);
  --canvas-bg: #f8f5ee;
  --canvas-overlay: rgba(15, 23, 42, 0.1);
}

/* Dark Theme */
body[data-theme="dark"] {
  --surface: #05080e;
  --surface-alt: #0d141d;
  --surface-contrast: #38bdf8;
  --text-primary: #f8fafc;
  --text-muted: rgba(226, 232, 240, 0.8);
  --grid-dot-color: rgba(94, 234, 212, 0.3);
  --grid-major-color: rgba(94, 234, 212, 0.55);
  --border-color: rgba(148, 163, 184, 0.25);
  --canvas-bg: #0f1419;
  --canvas-overlay: rgba(94, 234, 212, 0.1);
}

/* Auto Dark Mode Detection */
@media (prefers-color-scheme: dark) {
  body[data-theme="dark"] {
    --surface: #05080e;
    --surface-alt: #0b1120;
    --surface-contrast: #5eead4;
    --text-primary: #f8fafc;
    --text-muted: rgba(248, 250, 252, 0.68);
    --grid-dot-color: rgba(94, 234, 212, 0.3);
    --grid-major-color: rgba(94, 234, 212, 0.55);
    --border-color: rgba(148, 163, 184, 0.2);
    --canvas-bg: #0f1419;
    --canvas-overlay: rgba(94, 234, 212, 0.1);
  }
}

/* Base Body Styles */
body {
  background: var(--surface);
  color: var(--text-primary);
  min-height: 100dvh;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body.modal-active {
  overflow: hidden;
}

/* ============================================
   Card & Surface Components
   ============================================ */
.card-backdrop {
  background: var(--surface-alt);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
}

/* ============================================
   Viewport & Canvas
   ============================================ */
#viewport {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  border-radius: 1.25rem;
  border: 1px solid var(--border-color);
  background-color: var(--canvas-bg);
  min-height: clamp(520px, 76vh, 960px);
  height: 100%;
  touch-action: none;
}

/* Screen-Space Grid Overlay - Dot Pattern */
#grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  /* Dot-based grid using radial gradients */
  background-image:
    radial-gradient(circle, var(--grid-major-color) 1.5px, transparent 1.5px),
    radial-gradient(circle, var(--grid-dot-color) 1px, transparent 1px);
  background-position: 0 0, 0 0;
  background-size: var(--coarse) var(--coarse), var(--fine) var(--fine);
  /* Default sizes (overridden by JS) */
  --fine: 32px;
  --coarse: 160px;
  opacity: 1;
}

#world {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  width: 100%;
  height: 100%;
  background-color: var(--canvas-overlay);
}

/* World Grid Axis Lines */
#world::before,
#world::after {
  content: "";
  position: absolute;
  background: var(--grid-major-color);
  opacity: 0.5;
  pointer-events: none;
}

#world::before {
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  transform: translateX(-50%);
}

#world::after {
  left: 0;
  top: 50%;
  height: 1px;
  width: 100%;
  transform: translateY(-50%);
}

.world-overlay {
  z-index: 3;
  pointer-events: none;
}

/* Drawing Layer */
#drawingLayer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ============================================
   Canvas Toolbar
   ============================================ */
.canvas-toolbar {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.5rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.02);
  pointer-events: auto;
  min-width: 56px;
  max-width: 240px;
}

body[data-theme="dark"] .canvas-toolbar {
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(148, 163, 184, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.canvas-toolbar.collapsed #toolbarContent {
  display: none;
}

.toolbar-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.25rem;
}

.toolbar-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.25rem;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toolbar-toggle:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-primary);
}

.toolbar-toggle svg {
  transition: transform 0.2s ease;
}

.canvas-toolbar.collapsed .toolbar-toggle svg {
  transform: rotate(-90deg);
}

body[data-theme="dark"] .toolbar-toggle:hover {
  background: rgba(148, 163, 184, 0.15);
}

/* Tool Sections */
.tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.25rem;
}

.tool-section-compact {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  gap: 0.15rem;
  padding: 0.25rem;
}

.toolbar-divider {
  height: 1px;
  background: rgba(15, 23, 42, 0.1);
  margin: 0.25rem 0;
}

.toolbar-divider-thin {
  height: 1px;
  background: rgba(15, 23, 42, 0.06);
  margin: 0.35rem 0.25rem;
}

body[data-theme="dark"] .toolbar-divider {
  background: rgba(148, 163, 184, 0.2);
}

body[data-theme="dark"] .toolbar-divider-thin {
  background: rgba(148, 163, 184, 0.1);
}

/* Icon Tool Buttons */
.tool-icon-button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  pointer-events: auto;
}

.tool-icon-button:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-primary);
}

.tool-icon-button.active {
  background: rgba(37, 99, 235, 0.15);
  color: #2563eb;
}

.tool-icon-button.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: #2563eb;
  border-radius: 0 2px 2px 0;
}

body[data-theme="dark"] .tool-icon-button:hover {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-primary);
}

body[data-theme="dark"] .tool-icon-button.active {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

body[data-theme="dark"] .tool-icon-button.active::after {
  background: #60a5fa;
}

.canvas-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Tool Buttons */
.tool-button {
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(255, 255, 255, 0.78);
  color: var(--text-primary);
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
  pointer-events: auto;
}

.tool-button.active {
  background: var(--surface-contrast);
  color: #0f172a;
}

body[data-theme="dark"] .tool-button {
  background: rgba(15, 23, 42, 0.6);
  border-color: rgba(148, 163, 184, 0.3);
  color: var(--text-muted);
}

body[data-theme="dark"] .tool-button.active {
  color: #0b1120;
}

/* Toolbar Section Labels */
.toolbar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.25rem;
}

/* Color Swatches */
.color-swatches-compact {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  padding: 0.25rem;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 0.375rem;
  border: 2px solid rgba(15, 23, 42, 0.1);
  background: var(--swatch-color);
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto;
  position: relative;
}

.color-swatch:hover {
  transform: scale(1.05);
  border-color: rgba(15, 23, 42, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.color-swatch.active {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.color-swatch.active::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 2px solid #2563eb;
  border-radius: 0.375rem;
  pointer-events: none;
}

body[data-theme="dark"] .color-swatch {
  border-color: rgba(148, 163, 184, 0.2);
}

body[data-theme="dark"] .color-swatch.active {
  border-color: rgba(15, 23, 42, 0.9);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.6);
}

/* Sliders */
.pen-size-slider,
.text-size-slider,
.shape-size-slider {
  appearance: none;
  width: 120px;
  height: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.15);
  outline: none;
}

.pen-size-slider::-webkit-slider-thumb,
.text-size-slider::-webkit-slider-thumb,
.shape-size-slider::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-contrast);
  cursor: pointer;
}

.pen-size-slider::-moz-range-thumb,
.text-size-slider::-moz-range-thumb,
.shape-size-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-contrast);
  cursor: pointer;
}

/* Toolbar Labels & Values */
/* Slider Controls */
.slider-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
}

.slider-control-compact {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
}

.slider-control label,
.slider-control-compact label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 35px;
}

.slider-control span,
.slider-control-compact span {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

.compact-slider {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(15, 23, 42, 0.1);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.compact-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  cursor: pointer;
  transition: all 0.15s ease;
}

.compact-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.compact-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.compact-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

body[data-theme="dark"] .compact-slider {
  background: rgba(148, 163, 184, 0.2);
}

body[data-theme="dark"] .compact-slider::-webkit-slider-thumb {
  background: #60a5fa;
}

body[data-theme="dark"] .compact-slider::-moz-range-thumb {
  background: #60a5fa;
}

/* Action Buttons */
.action-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto;
  width: 100%;
  justify-content: flex-start;
}

.action-button:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-primary);
}

body[data-theme="dark"] .action-button:hover {
  background: rgba(148, 163, 184, 0.15);
}

/* Compact Action Buttons */
.action-buttons-compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem;
  padding: 0.25rem;
}

.action-button-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto;
}

.action-button-icon:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-primary);
}

body[data-theme="dark"] .action-button-icon:hover {
  background: rgba(148, 163, 184, 0.15);
}

/* Hide helper */
.hidden {
  display: none !important;
}

/* Live Text Editor on Canvas */
.canvas-text-editor-live {
  font-family: 'Inter', sans-serif;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  cursor: text;
  /* Note: border, color, and other styles are set inline in canvas.js */
}

.canvas-text-editor-live:focus {
  outline: none;
}

/* Hide any old text editor elements that might exist */
textarea.canvas-text-editor,
div.canvas-text-editor:not(.canvas-text-editor-live) {
  display: none !important;
}

/* Old text editor styles - no longer used (using .canvas-text-editor-live instead) */

/* ============================================
   Zoom Controls
   ============================================ */
#zoomControls {
  position: fixed;
  right: 1.5rem;
  bottom: clamp(5.75rem, 16vh, 9rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 30;
}

@media (max-width: 768px) {
  #zoomControls {
    right: 1rem;
    bottom: clamp(6rem, 22vh, 8.5rem);
  }
}

.zoom-button {
  background: var(--surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  font-size: 1.375rem;
  color: var(--text-primary);
  transition: transform 0.15s ease;
}

.zoom-button:hover {
  transform: translateY(-2px);
}

.zoom-button:active {
  transform: translateY(1px) scale(0.98);
}

/* ============================================
   Attendee Tray
   ============================================ */
#attendeeTray {
  position: absolute;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  width: min(94%, 960px);
  padding: 1.1rem 1.4rem;
  border-radius: 1.5rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: linear-gradient(135deg, rgba(247, 243, 235, 0.96), rgba(252, 249, 242, 0.96));
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  pointer-events: auto;
}

#attendeeTray .tray-heading,
#attendeeTray .tray-copy {
  color: rgba(15, 23, 42, 0.72);
}

@media (prefers-color-scheme: dark) {
  #attendeeTray {
    border-color: rgba(148, 163, 184, 0.25);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.82), rgba(17, 24, 39, 0.78));
    box-shadow: 0 18px 36px rgba(2, 6, 23, 0.45);
  }

  #attendeeTray .tray-heading,
  #attendeeTray .tray-copy {
    color: var(--text-muted);
  }
}

/* Attendee List */
#attendeeList {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

#attendeeList li {
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 0.35rem 0.9rem;
  background: rgba(15, 23, 42, 0.02);
  color: var(--text-primary);
  font-size: 0.85rem;
}

@media (prefers-color-scheme: dark) {
  #attendeeList li {
    background: rgba(148, 163, 184, 0.08);
  }
}

/* ============================================
   Identity Modal
   ============================================ */
#identityModal {
  display: none;
}

#identityModal.active {
  display: block;
}

#identityModal .modal-card {
  border-radius: 1.5rem;
  max-width: 480px;
  width: 100%;
}

/* ============================================
   AI Transcription Marquee
   ============================================ */
#ai-transcription-marquee {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 0.875rem;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#ai-transcription-marquee.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.transcription-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
  animation: pulse 2s ease-in-out infinite;
}

.status-indicator.status-active .pulse-dot {
  background: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

.status-indicator.status-disconnected {
  background: rgba(239, 68, 68, 0.3);
}

.status-indicator.status-disconnected .pulse-dot {
  background: #ef4444;
  animation: none;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

.transcription-text {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  line-height: 1.4;
  animation: slideIn 0.5s ease;
}

.transcription-text.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Adjust body padding when marquee is visible */
body:has(#ai-transcription-marquee:not(.hidden)) {
  padding-top: 3rem;
}

/* Dark theme adjustments */
@media (prefers-color-scheme: dark) {
  #ai-transcription-marquee {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
  }
}
