/* ═══════════════════════════════════════════════════════════════
   SMART SLIDES — Design System
   Palette: deep navy bg · slate panels · electric indigo accent
   Type: Inter (system) + mono for code
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Core palette */
  --bg:          #0d1117;
  --bg-panel:    #161b22;
  --bg-panel2:   #1c2330;
  --border:      #30363d;
  --border-soft: #21262d;

  /* Accent — electric indigo */
  --accent:      #6e57ff;
  --accent-dim:  #4a3bbf;
  --accent-glow: rgba(110, 87, 255, 0.25);
  --accent-text: #a89fff;

  /* Semantic */
  --success:     #3fb950;
  --warning:     #d29922;
  --danger:      #f85149;
  --tts:         #58a6ff;

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  /* Spacing */
  --gap:    12px;
  --radius: 8px;
  --radius-lg: 14px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Utilities ── */
.hidden { display: none !important; }
code {
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 0.78rem;
  background: var(--bg-panel2);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--accent-text);
}

/* ═══════════════════════════
   HEADER
   ═══════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-icon {
  color: var(--accent);
  font-size: 1.4rem;
  line-height: 1;
}
.brand-name { color: var(--text-secondary); }
.brand-name strong { color: var(--text-primary); }

/* ═══════════════════════════
   LAYOUT
   ═══════════════════════════ */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.viewer-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ═══════════════════════════
   PANELS
   ═══════════════════════════ */
.panel {
  padding: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-compact { padding: 12px 16px; }
.panel-thumbnails { flex: 1; min-height: 0; }

.panel-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

/* ═══════════════════════════
   BUTTONS
   ═══════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  white-space: nowrap;
  background: none;
  color: var(--text-primary);
  line-height: 1;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }

.btn-ghost {
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-glow);
}

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg { padding: 10px 20px; font-size: 0.95rem; }

.btn-nav {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1rem;
}
.btn-nav:hover:not(:disabled) {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--text-primary);
}
.btn-large { width: 52px; height: 52px; font-size: 1.2rem; }

.btn-ai {
  width: 100%;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  justify-content: flex-start;
  margin-bottom: 6px;
  font-size: 0.82rem;
}
.btn-ai:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-glow);
}

.btn-tts {
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  color: var(--tts);
  font-size: 0.82rem;
}
.btn-tts:hover:not(:disabled) { background: rgba(88, 166, 255, 0.1); }
.btn-tts-sm {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.btn-tts-sm:hover:not(:disabled) {
  border-color: var(--tts);
  color: var(--tts);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--text-primary); }

/* ═══════════════════════════
   DROP ZONE
   ═══════════════════════════ */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  transition: all 0.2s var(--ease);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.drop-icon {
  font-size: 2rem;
  color: var(--accent);
  line-height: 1;
}
.drop-zone p { font-size: 0.85rem; color: var(--text-secondary); }
.drop-sub { font-size: 0.75rem; color: var(--text-muted); }
.drop-hint { font-size: 0.72rem; color: var(--text-muted); }

/* ── Progress ── */
.upload-progress {
  margin-top: 10px;
}
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s var(--ease);
}
#progressLabel {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ═══════════════════════════
   SLIDE COUNTER
   ═══════════════════════════ */
.slide-counter {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
#currentSlideNum {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-text);
  line-height: 1;
}
.counter-divider {
  font-size: 1.2rem;
  color: var(--text-muted);
}
#totalSlideNum {
  font-size: 1.2rem;
  color: var(--text-secondary);
}
.counter-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ═══════════════════════════
   NAV BUTTONS
   ═══════════════════════════ */
.nav-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}
.fullscreen-row {
  display: flex;
  gap: 6px;
}
.fullscreen-row .btn { flex: 1; font-size: 0.78rem; }

/* ═══════════════════════════
   AI PANEL
   ═══════════════════════════ */
.hf-token-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.token-input {
  flex: 1;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 0.78rem;
}
.token-input::placeholder { color: var(--text-muted); }
.token-input:focus { outline: none; border-color: var(--accent); }

.ai-buttons { display: flex; flex-direction: column; }

.ai-question-box {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.question-input {
  flex: 1;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 0.82rem;
}
.question-input::placeholder { color: var(--text-muted); }
.question-input:focus { outline: none; border-color: var(--accent); }

.ai-result {
  margin-top: 10px;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ai-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.ai-result-label {
  font-size: 0.72rem;
  color: var(--accent-text);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ai-result-text {
  padding: 10px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-height: 180px;
  overflow-y: auto;
}

.ai-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
}
.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 0.9s infinite ease-in-out;
}
.loading-dot:nth-child(2) { animation-delay: 0.15s; }
.loading-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ═══════════════════════════
   TTS BUTTONS
   ═══════════════════════════ */
.tts-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.btn-tts { flex: 1; }

/* ═══════════════════════════
   VIEWER
   ═══════════════════════════ */
.viewer-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #060a0f;
  overflow: hidden;
}

.viewer-empty {
  text-align: center;
  color: var(--text-muted);
}
.viewer-empty .empty-icon {
  font-size: 4rem;
  color: var(--border);
  margin-bottom: 16px;
}
.viewer-empty h3 { font-size: 1.1rem; font-weight: 500; margin-bottom: 6px; }
.viewer-empty p { font-size: 0.85rem; }

.slide-canvas,
.slide-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.swipe-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.gesture-anim {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  color: var(--accent);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.gesture-anim.show {
  display: block !important;
  opacity: 1;
  animation: gestureFlash 0.6s var(--ease) forwards;
}
@keyframes gestureFlash {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

/* ── Status Bar ── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 2s infinite;
}
.status-dot.listening {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse 1s infinite;
}
.status-dot.speaking {
  background: var(--tts);
  box-shadow: 0 0 6px var(--tts);
  animation: pulse 0.6s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.last-command {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--accent-text);
  font-style: italic;
}

/* ═══════════════════════════
   WEBCAM
   ═══════════════════════════ */
.webcam-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}
.webcam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.gesture-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}
.camera-off-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.camera-buttons {
  display: flex;
  gap: 6px;
}
.camera-buttons .btn { flex: 1; }

.error-msg {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--danger);
}

/* ═══════════════════════════
   VOICE
   ═══════════════════════════ */
.voice-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.voice-toggle .btn { flex: 1; }

.voice-log {
  max-height: 120px;
  overflow-y: auto;
  background: var(--bg-panel2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.voice-log-empty { color: var(--text-muted); font-style: italic; }
.voice-log-entry {
  padding: 2px 0;
  border-bottom: 1px solid var(--border-soft);
}
.voice-log-entry:last-child { border-bottom: none; }
.voice-log-cmd  { color: var(--success); font-weight: 600; }
.voice-log-raw  { color: var(--text-muted); font-size: 0.72rem; }
.voice-log-miss { color: var(--warning); font-size: 0.78rem; }

.voice-commands-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.8;
}
.voice-commands-hint strong {
  display: block;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.voice-commands-hint code { margin: 2px; display: inline-block; }

/* ═══════════════════════════
   THUMBNAILS
   ═══════════════════════════ */
.thumbnail-strip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}
.thumb-empty { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.thumb-item {
  position: relative;
  border: 2px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
  aspect-ratio: 16/9;
  background: #000;
}
.thumb-item:hover { border-color: var(--accent-dim); }
.thumb-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.thumb-item canvas,
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.thumb-num {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.5);
  border-radius: 3px;
  padding: 1px 4px;
}

/* ═══════════════════════════
   MODAL
   ═══════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-body { overflow-y: auto; padding: 20px; }

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.help-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-text);
  margin-bottom: 10px;
}
.help-section ul {
  list-style: none;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.help-section li strong { color: var(--text-primary); }

/* ═══════════════════════════
   FULLSCREEN PRESENTATION
   ═══════════════════════════ */
.presentation-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fs-canvas,
.fs-img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}
.fs-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50px;
  padding: 8px 16px;
  opacity: 0;
  transition: opacity 0.3s;
}
.presentation-overlay:hover .fs-controls { opacity: 1; }
.fs-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}
.fs-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.fs-btn-exit { color: var(--danger); }
.fs-counter {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  min-width: 60px;
  text-align: center;
}

/* ═══════════════════════════
   SCROLLBARS
   ═══════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ═══════════════════════════
   RESPONSIVE
   ═══════════════════════════ */
@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 240px 1fr 240px; }
}
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    overflow-y: auto;
  }
  .sidebar, .sidebar-right {
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }
  .viewer-column { min-height: 60vw; }
  .help-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .app-header { padding: 0 12px; }
  .panel { padding: 12px; }
  .status-bar { gap: 8px; flex-wrap: wrap; }
}

/* ═══════════════════════════
   ANIMATIONS
   ═══════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ═══════════════════════════
   GESTURE LEGEND
   ═══════════════════════════ */
.gesture-legend {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.gesture-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.gesture-icon {
  font-size: 1rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

/* ═══════════════════════════
   UPLOAD ERROR
   ═══════════════════════════ */
.upload-error-msg {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--danger);
}

/* ═══════════════════════════
   HELP KEYBOARD SECTION
   ═══════════════════════════ */
.help-keyboard {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.help-keyboard h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-text);
  margin-bottom: 12px;
}
.key-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 8px 16px;
  align-items: center;
}
kbd {
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: monospace;
  color: var(--accent-text);
  white-space: nowrap;
}
.key-grid span {
  font-size: 0.78rem;
  color: var(--text-secondary);
}
