/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Upload screen ─────────────────────────────────────────────── */
#upload-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
}
#app-layout { display: none; flex-direction: column; height: 100vh; }

/* ── Loading screen ─────────────────────────────────────────────── */
#loading-screen {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  flex-direction: column;
  gap: var(--space-5);
}
.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border-medium);
  border-top-color: var(--teal-bright);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title {
  font-size: 18px; font-weight: 600; color: var(--text-primary);
}
.loading-sub {
  font-size: 13px; color: var(--text-muted);
}

body.deck-loading #upload-screen  { display: none; }
body.deck-loading #loading-screen { display: flex; }
body.deck-loading #app-layout     { display: none; }

.has-deck #upload-screen  { display: none; }
.has-deck #loading-screen { display: none; }
.has-deck #app-layout     { display: flex; }

/* ── Header ────────────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

#header-progress-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: var(--teal-bright);
  transition: width 0.3s ease;
  width: 0%;
}

#header-left  { display: flex; align-items: center; gap: var(--space-3); min-width: 0; flex: 0 0 auto; }
#header-center { flex: 1; display: flex; justify-content: center; }
#header-right { display: flex; align-items: center; gap: var(--space-3); flex: 0 0 auto; }

/* ── Mode tabs ─────────────────────────────────────────────────── */
#mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-base);
  border-radius: var(--radius-md);
  padding: 3px;
}
.mode-tab {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.mode-tab:hover { color: var(--text-primary); background: var(--bg-elevated); }
.mode-tab.active {
  background: var(--bg-elevated);
  color: var(--teal-bright);
}

/* ── Body below header ─────────────────────────────────────────── */
#app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
#app-sidebar {
  flex: 0 0 15%;
  min-width: 180px;
  max-width: 280px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
}

#sidebar-filter-bar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

#sidebar-slide-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

/* ── Main area ─────────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#main-panes {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Left pane ─────────────────────────────────────────────────── */
#left-pane {
  flex: 0 0 70%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: var(--space-4);
  gap: var(--space-4);
}

/* ── Drag handle ───────────────────────────────────────────────── */
#pane-drag-handle {
  width: 5px;
  background: var(--border-subtle);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}
#pane-drag-handle:hover,
#pane-drag-handle.dragging { background: var(--teal-bright); }

/* ── Right pane ────────────────────────────────────────────────── */
#right-pane {
  flex: 1;
  min-width: 240px;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ── Bottom bar ────────────────────────────────────────────────── */
#bottom-bar {
  height: var(--bottom-bar-h);
  min-height: var(--bottom-bar-h);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  flex-shrink: 0;
}

.bottom-controls { display: none; width: 100%; align-items: center; gap: var(--space-3); }
.mode-coach        .bottom-controls[data-mode="coach"]        { display: flex; }
.mode-teleprompter .bottom-controls[data-mode="teleprompter"] { display: flex; }
.mode-brief        .bottom-controls[data-mode="brief"]        { display: flex; }
.mode-setlist      .bottom-controls[data-mode="setlist"]      { display: flex; }

/* ── Mode layout overrides ─────────────────────────────────────── */

/* Teleprompter: collapse sidebar, both panes, drag handle — show tp-content */
.mode-teleprompter #app-sidebar      { display: none; }
.mode-teleprompter #left-pane        { display: none; }
.mode-teleprompter #pane-drag-handle { display: none; }
.mode-teleprompter #right-pane       { display: none; }
.mode-teleprompter #tp-content       { display: flex; }


/* Presenter Brief: full-width, no sidebar, no panes */
.mode-brief #app-sidebar      { display: none; }
.mode-brief #left-pane        { display: none; }
.mode-brief #pane-drag-handle { display: none; }
.mode-brief #right-pane       { display: none; }
.mode-brief #brief-view       { display: flex; }
.mode-brief .bottom-controls[data-mode="brief"] { display: flex; }

/* Set List: full-width, no sidebar, no panes */
.mode-setlist #app-sidebar      { display: none; }
.mode-setlist #left-pane        { display: none; }
.mode-setlist #pane-drag-handle { display: none; }
.mode-setlist #right-pane       { display: none; }
.mode-setlist #setlist-view     { display: flex; }

#setlist-view {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Alternate views (flashcard / teleprompter) ────────────────── */
#flashcard-view { display: none; flex: 1; overflow-y: auto; }

#tp-content {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Left: sticky slide panel */
#tp-slide-panel {
  flex: 0 0 320px;
  min-width: 200px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  padding: var(--space-5);
  gap: var(--space-4);
  overflow: hidden;
}

/* Resize handle between side panel and scroll area */
#tp-panel-resize {
  width: 5px;
  background: var(--border-subtle);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}
#tp-panel-resize:hover,
#tp-panel-resize.dragging { background: var(--teal-bright); }

.tp-resume-btn {
  width: 100%;
  justify-content: center;
}

/* Rehearsal Check-in Modal */
.tp-analyze-modal {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.tp-analyze-backdrop {
  position: absolute; inset: 0;
  background: var(--bg-overlay);
}
.tp-analyze-dialog {
  position: relative;
  width: min(680px, 92vw);
  max-height: min(600px, 85vh);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}
#tp-analyze-overlay {
  display: flex; flex-direction: column;
  flex: 1; overflow: hidden;
}
.tp-analyze-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.tp-analyze-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.tp-analyze-body {
  flex: 1; overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-5);
}
.tp-analyze-section { display: flex; flex-direction: column; gap: var(--space-3); }
.tp-analyze-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
}
.tp-analyze-content {
  font-size: 13px; line-height: 1.65; color: var(--text-primary);
}
.tp-analyze-loading {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: 13px; color: var(--text-muted); padding: var(--space-4) 0;
}
.tp-analyze-actions {
  display: flex; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}
#tp-slide-img-wrap {
  aspect-ratio: 16/9;
  background: var(--bg-base);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
}
#tp-slide-img-wrap img {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
#tp-slide-img-wrap .tp-slide-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 12px;
}
.tp-slide-meta {
  display: flex; flex-direction: column; gap: var(--space-2);
}
.tp-slide-meta-title {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  line-height: 1.4; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.tp-slide-meta-num {
  font-size: 11px; color: var(--text-muted);
}
.tp-time-block {
  display: flex; flex-direction: column; gap: var(--space-2);
}
.tp-time-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-muted);
}
.tp-time-value {
  font-family: var(--font-mono); font-weight: 600; color: var(--text-primary);
}
.tp-progress-bar-wrap {
  height: 4px; background: var(--bg-elevated); border-radius: 2px; overflow: hidden;
}
.tp-progress-bar-fill {
  height: 100%; background: var(--teal-bright);
  border-radius: 2px; transition: width 0.5s ease;
}

.tp-on-track {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 12px; text-align: center;
  min-height: 22px;
}
.tp-on-track.on-track-good {
  background: rgba(34,197,94,0.15); color: #22c55e;
}
.tp-on-track.on-track-warn {
  background: rgba(245,158,11,0.15); color: #f59e0b;
}
.tp-on-track.on-track-over {
  background: rgba(239,68,68,0.15); color: #ef4444;
}

/* Right: scrolling text */
#tp-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
  min-height: 0;
}

#tp-scroll-inner {
  max-width: var(--tp-content-width, 680px);
  margin: 0 auto;
  min-height: 100%;
}

/* ── Presenter Brief view ──────────────────────────────────────── */
#brief-view {
  display: none;
  flex: 1;
  flex-direction: row;
  overflow: hidden;
}

/* Left pane: audience definition */
#brief-audience-pane {
  flex: 0 0 var(--brief-audience-width, 300px);
  min-width: 200px;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  overflow: hidden;
}
.brief-pane-header {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.brief-pane-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.brief-audience-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  gap: var(--space-3);
  overflow-y: auto;
}
.brief-audience-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}
.brief-audience-textarea {
  flex: 1;
  min-height: 160px;
  resize: none;
  font-size: 13px;
  line-height: 1.6;
}

/* Drag handle between audience and map panes */
#brief-pane-resize {
  width: 5px;
  background: var(--border-subtle);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}
#brief-pane-resize:hover,
#brief-pane-resize.dragging { background: var(--teal-bright); }

/* Right pane: message map */
#brief-map-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#brief-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}
#brief-feedback-bar {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}
#brief-header-left  { display: flex; align-items: center; gap: var(--space-3); }
#brief-header-actions { display: flex; align-items: center; gap: var(--space-2); }

.brief-title {
  font-size: 15px; font-weight: 700; color: var(--text-primary);
}
.brief-save-status {
  font-size: 12px; color: var(--teal-bright); opacity: 0.8;
}

#brief-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.brief-empty-inner {
  text-align: center; max-width: 360px;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
}
.brief-empty-icon  { font-size: 40px; }
.brief-empty-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.brief-empty-sub   { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

#brief-preview {
  flex: 1; overflow-y: auto;
  padding: var(--space-6) var(--space-6);
}

#brief-editor {
  flex: 1;
  margin: var(--space-4) var(--space-6);
  resize: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  min-height: 0;
}

.brief-regen-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--teal-dim);
  border-bottom: 1px solid var(--teal-bright);
  font-size: 13px; flex-shrink: 0;
}
.brief-banner-msg { color: var(--text-secondary); }

/* ── Settings panel ────────────────────────────────────────────── */
#settings-panel {
  position: fixed;
  top: 0; right: -400px;
  width: 380px;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  z-index: 100;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
  padding: var(--space-6);
  gap: var(--space-5);
  overflow-y: auto;
}
#settings-panel.open { right: 0; }
#settings-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  z-index: 99;
}
#settings-overlay.open { display: block; }

/* ── Empty / no-deck state ─────────────────────────────────────── */
#no-slide-selected {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 13px;
}
