/* ============================================================================
   SmartSlides — style.css
   A dark, control-room UI: the slide is the hero, the two side rails hold
   input/output controls. Indigo/violet accent per the Space's own palette.
   ========================================================================== */

:root {
  --bg: #0e0d17;
  --panel: #171526;
  --panel-alt: #1d1a30;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e7e5f2;
  --text-dim: #9c98b8;
  --text-faint: #6b6786;

  --accent: #7c6ef2;
  --accent-strong: #9b8bff;
  --accent-soft: rgba(124, 110, 242, 0.18);
  --violet: #b06ef2;

  --ok: #59d68c;
  --warn: #f2b84e;
  --danger: #f2607c;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f2fa;
    --panel: #ffffff;
    --panel-alt: #f6f5fc;
    --border: rgba(20, 15, 50, 0.09);
    --border-strong: rgba(20, 15, 50, 0.16);
    --text: #1c1a2b;
    --text-dim: #5c5878;
    --text-faint: #8a86a6;
    --accent-soft: rgba(124, 110, 242, 0.12);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--accent-strong);
}

/* ------------------------------------------------------------------ header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
}
.brand-icon { color: var(--accent-strong); font-size: 20px; }
.brand-name strong { color: var(--accent-strong); font-weight: 700; }

/* -------------------------------------------------------------------- btn */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

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

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-ai { background: linear-gradient(135deg, var(--accent-soft), transparent); border-color: var(--accent); color: var(--accent-strong); justify-content: flex-start; width: 100%; margin-bottom: 6px; }
.btn-ai:hover { background: var(--accent-soft); }

.btn-tts { width: 100%; margin-bottom: 8px; justify-content: center; }
.btn-tts-sm { padding: 6px 10px; font-size: 13px; }

.btn-nav { font-size: 16px; padding: 8px 12px; }
.btn-large { flex: 1; font-size: 20px; }

.btn-icon {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 16px; line-height: 1; padding: 4px;
}
.btn-icon:hover { color: var(--text); }

/* ------------------------------------------------------------------ layout */

.app-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 53px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 2px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.panel-compact { padding: 10px 14px; }

.panel-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ upload */

.drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.drop-zone.drag-active,
.drop-zone:hover { border-color: var(--accent); background: var(--accent-soft); }

.drop-icon { font-size: 26px; color: var(--accent-strong); margin-bottom: 6px; }
.drop-zone p { margin: 4px 0; color: var(--text-dim); }
.drop-sub { display: block; font-size: 11px; color: var(--text-faint); margin: 4px 0; }
.drop-hint { font-size: 11px; color: var(--text-faint); margin-top: 8px !important; }

.upload-progress { margin-top: 12px; }
.progress-bar {
  height: 5px; border-radius: 3px; background: var(--panel-alt);
  overflow: hidden; margin-bottom: 6px;
}
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width 200ms ease; }
#progressLabel { font-size: 11px; color: var(--text-faint); }

/* ------------------------------------------------------------------ counter */

.slide-counter {
  display: flex; align-items: baseline; justify-content: center; gap: 4px;
  font-size: 20px; font-weight: 600;
}
.counter-divider { color: var(--text-faint); }
.counter-label { font-size: 11px; color: var(--text-faint); margin-left: 6px; font-weight: 400; }

/* ------------------------------------------------------------------- nav */

.nav-buttons { display: flex; gap: 6px; margin-bottom: 8px; }
.fullscreen-row { display: flex; gap: 6px; }
.fullscreen-row .btn { flex: 1; justify-content: center; }

/* -------------------------------------------------------------------- AI */

.hf-token-row { display: flex; gap: 6px; margin-bottom: 10px; }
.token-input, .question-input {
  flex: 1; min-width: 0;
  background: var(--panel-alt); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text); padding: 7px 9px; font-size: 12px;
}
.token-input:focus, .question-input:focus { outline: none; border-color: var(--accent); }

.ai-question-box { display: flex; gap: 6px; margin-top: 4px; }

.ai-result {
  margin-top: 10px; background: var(--panel-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px;
}
.ai-result-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.ai-result-label { font-size: 11px; font-weight: 600; color: var(--accent-strong); }
.ai-result-text { font-size: 13px; color: var(--text); white-space: pre-wrap; }

.ai-loading { display: flex; gap: 4px; padding: 4px 0; }
.loading-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: gp-pulse 1.1s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.15s; }
.loading-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes gp-pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* -------------------------------------------------------------------- TTS */

.tts-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.tts-buttons .btn-tts { flex-basis: 100%; }

/* ---------------------------------------------------------------- viewer */

.viewer-column { display: flex; flex-direction: column; min-width: 0; gap: 10px; }

.viewer-container {
  position: relative;
  flex: 1;
  background: #05040a;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.viewer-empty { text-align: center; color: var(--text-faint); }
.empty-icon { font-size: 40px; color: var(--accent); opacity: 0.5; margin-bottom: 8px; }
.viewer-empty h3 { margin: 0 0 4px; color: var(--text-dim); font-weight: 600; }
.viewer-empty p { margin: 0; font-size: 12px; }

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

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

.gesture-anim {
  position: absolute; inset: 0;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 60%);
  animation: gp-flash 400ms ease-out;
  pointer-events: none;
}
@keyframes gp-flash { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------------------------ status */

.status-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-dim);
}
.status-item { display: flex; align-items: center; gap: 6px; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}
.status-dot[data-state="on"],
.status-dot[data-state="idle"],
.status-dot[data-state="tracking"],
.status-dot[data-state="reading"] { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status-dot[data-state="paused"] { background: var(--warn); }
.status-dot[data-state="off"] { background: var(--text-faint); }

.last-command { margin-left: auto; color: var(--accent-strong); font-weight: 500; }

/* ------------------------------------------------------------------ camera */

.webcam-wrapper {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #05040a;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 10px;
}
.webcam-video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* mirrored preview */
}
.gesture-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.camera-off-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 12px;
  background: #05040a;
}

.camera-buttons { display: flex; gap: 6px; }
.camera-buttons .btn { flex: 1; justify-content: center; }

.error-msg {
  margin-top: 8px; font-size: 11px; color: var(--danger);
  background: rgba(242, 96, 124, 0.1); border: 1px solid rgba(242, 96, 124, 0.3);
  border-radius: var(--radius-sm); padding: 6px 8px;
}

/* ------------------------------------------------------------------- voice */

.voice-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.voice-toggle .btn { flex: 1; justify-content: center; }

.voice-log {
  height: 90px; overflow-y: auto;
  background: var(--panel-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px; margin-bottom: 8px;
  font-size: 12px;
}
.voice-log-empty, .voice-log-line { margin: 0 0 4px; color: var(--text-dim); }
.voice-log-line { color: var(--text); }

.voice-commands-hint { font-size: 11px; color: var(--text-faint); line-height: 1.9; }
.voice-commands-hint strong { display: block; color: var(--text-dim); margin-bottom: 4px; }

/* -------------------------------------------------------------- thumbnails */

.panel-thumbnails { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thumbnail-strip {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.thumb-empty { grid-column: 1 / -1; color: var(--text-faint); font-size: 12px; text-align: center; }

.thumbnail {
  position: relative; padding: 0; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; background: #05040a;
  aspect-ratio: 4 / 3;
}
.thumbnail canvas, .thumbnail img { width: 100%; height: 100%; object-fit: contain; }
.thumbnail.active { border-color: var(--accent-strong); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumbnail-num {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 10px; color: var(--text-dim);
  background: rgba(0, 0, 0, 0.6); border-radius: 3px; padding: 0 4px;
}

/* -------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 4, 10, 0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); width: min(760px, 100%); max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }

.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.help-section h3 { margin: 0 0 8px; font-size: 13px; }
.help-section ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-dim); line-height: 1.8; }
.help-section li strong { color: var(--text); }

/* ------------------------------------------------------------- fullscreen */

.presentation-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.fs-canvas, .fs-img { max-width: 100%; max-height: 100%; object-fit: contain; }

.fs-controls {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: rgba(20, 18, 34, 0.85); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 8px 14px;
  opacity: 0; transition: opacity 200ms ease;
}
.presentation-overlay:hover .fs-controls,
.presentation-overlay:focus-within .fs-controls { opacity: 1; }

.fs-btn {
  border: none; background: transparent; color: var(--text);
  font-size: 16px; padding: 6px 10px; border-radius: var(--radius-sm);
}
.fs-btn:hover { background: var(--accent-soft); }
.fs-btn-exit { color: var(--danger); }
.fs-counter { font-size: 13px; color: var(--text-dim); min-width: 60px; text-align: center; }

/* ----------------------------------------------------------------- mobile */

@media (max-width: 960px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
    min-height: calc(100vh - 53px);
  }
  .sidebar { flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .sidebar .panel { flex: 1 1 220px; }
  .viewer-column { order: -1; min-height: 50vh; }
  .help-grid { grid-template-columns: 1fr; }
}
