:root {
  --bg: #0b0d12;
  --panel: #11141b;
  --panel-2: #161a23;
  --border: #232836;
  --text: #e6e8ee;
  --muted: #8a93a6;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --thumb-w: 200px;
  --thumb-h: 113px; /* 16:9 of 200 */
  --thumb-render-w: 1280px;
  --thumb-render-h: 720px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  font-size: 14px;
}

.app {
  display: grid;
  grid-template-columns: var(--left-w, 240px) 4px 1fr 4px var(--right-w, 380px);
  height: 100vh;
  width: 100vw;
}

.resize-handle {
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
  user-select: none;
}
.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
  opacity: 0.4;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  padding: 6px 9px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  display: block;
}

.btn svg, .pres-btn svg, .pres-ctrl svg {
  display: block;
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* Split button: main action + small chevron toggle for a dropdown menu. */
.btn-split {
  display: inline-flex;
  align-items: stretch;
  position: relative;
}

.btn-split .btn-split-main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right-width: 0;
}

.btn-split .btn-split-chevron {
  padding: 0 7px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
}

.btn-split .btn-split-chevron[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.06);
  border-color: #2f3447;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  min-width: 0;
  max-width: 180px;
}

.brand-link svg {
  color: rgba(226, 232, 240, 0.7);
  flex: 0 0 auto;
}

.brand-link:hover svg {
  color: #fff;
}

.brand-link .brand-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text.editable {
  cursor: text;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 6px;
  outline: none;
  transition: background 0.12s ease;
  max-width: 220px;
}

.brand-text.editable:hover,
.brand-text.editable:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.brand-text.editable[contenteditable="true"],
.brand-text.editable[contenteditable="plaintext-only"] {
  background: rgba(99, 102, 241, 0.12);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.55);
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-text-fill-color: #e2e8f0;
  color: #e2e8f0;
  cursor: text;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.slide-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  counter-reset: slide;
}

.slide-item {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.06s ease;
  counter-increment: slide;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.slide-skeleton {
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.slide-skeleton-thumb {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    100deg,
    rgba(255,255,255,0.02) 30%,
    rgba(255,255,255,0.06) 50%,
    rgba(255,255,255,0.02) 70%
  );
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s ease-in-out infinite;
}

.slide-item::before {
  content: counter(slide);
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 2;
  font-size: 10px;
  color: white;
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 6px;
  border-radius: 999px;
  pointer-events: none;
}

.slide-item:hover {
  border-color: #2f3447;
}

.slide-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.35) inset;
}

.slide-item.dragging {
  opacity: 0.45;
}

.slide-item.drag-over-top {
  box-shadow: 0 -2px 0 0 var(--accent);
}

.slide-item.drag-over-bottom {
  box-shadow: 0 2px 0 0 var(--accent);
}

/* Multi-select */
.slide-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.45) inset;
  background: rgba(99, 102, 241, 0.08);
}

.slide-item .slide-check {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--accent);
  border: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.slide-item.selected .slide-check {
  display: flex;
}

.slide-item .slide-check::after {
  content: "";
  width: 4px;
  height: 7px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Selection action bar */
.slide-selection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(99, 102, 241, 0.12);
  border-top: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.slide-selection-bar .sel-count {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

.slide-selection-bar .btn-sel-clear {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.slide-selection-bar .btn-sel-clear:hover { color: var(--text); }

/* Group header row */
.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 2px 6px;
  margin-top: 4px;
  border-left: 3px solid var(--gc, rgba(99,102,241,0.4));
}

.group-header-label {
  flex: 1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gc, var(--muted));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: color 0.12s, background 0.12s;
}
.group-header-label:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.group-header-btn {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.group-header:hover .group-header-btn { opacity: 1; }
.group-header-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.group-header-btn.danger:hover { background: rgba(239,68,68,0.15); color: #f87171; }

/* Group coloring: each group gets --gc (border color) and --gc-rgb (for tints) set inline by JS */
.slide-item.in-group {
  border-left: 3px solid var(--gc, rgba(99,102,241,0.5));
  background: rgba(var(--gc-rgb, 99,102,241), 0.05);
}
.slide-item.in-group:hover {
  background: rgba(var(--gc-rgb, 99,102,241), 0.09);
}
.slide-item.in-group.active {
  border-left-color: var(--gc, var(--accent));
  box-shadow: 0 0 0 1px rgba(var(--gc-rgb, 99,102,241), 0.3) inset;
}

/* Group name pill at the bottom of each grouped slide */
.slide-group-pill {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gc, #818cf8);
  background: rgba(var(--gc-rgb, 99,102,241), 0.12);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  align-self: flex-start;
}

.thumb {
  position: relative;
  width: 100%;
  /* No max-width: let the sidebar drag-resize handle the size. The source
     WebP is 960px wide so it stays crisp up to a fairly wide sidebar. */
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  container-type: inline-size;
}

.thumb iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--thumb-render-w);
  height: var(--thumb-render-h);
  border: 0;
  transform-origin: top left;
  transform: scale(calc(100cqi / var(--thumb-render-w)));
  pointer-events: none;
  background: #000;
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.thumb .thumb-cover {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.thumb .thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  transition: opacity 160ms ease;
}

.thumb .thumb-img.opacity-0 { opacity: 0; }

.thumb .thumb-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    rgba(255,255,255,0.02) 30%,
    rgba(255,255,255,0.07) 50%,
    rgba(255,255,255,0.02) 70%
  );
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s linear infinite;
}

@keyframes thumb-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.thumb .loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  background: linear-gradient(135deg, #0f172a, #1e293b);
}

.slide-item.is-generating .thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.72);
  backdrop-filter: blur(1px);
  z-index: 4;
  border-radius: inherit;
}

.slide-item.is-generating .thumb::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: rgba(255,255,255,0.75);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  pointer-events: none;
}


/* ---------------- Stage ---------------- */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: radial-gradient(1200px 600px at 50% -20%, rgba(99, 102, 241, 0.08), transparent 60%), var(--bg);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.slide-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-actions {
  display: flex;
  gap: 8px;
}

.iframe-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 0;
  min-width: 0;
  transition: box-shadow 0.2s;
}

/* Text-edit mode: subtle inset glow so the user knows edits are live */
.iframe-wrap.text-edit-active {
  box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.35);
}
.iframe-wrap.text-edit-active::after {
  content: "Text editing";
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(99, 102, 241, 0.8);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 99px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  pointer-events: none;
}

/* Regenerate slide popover (anchored to the regen button in stage toolbar) */
.regen-wrap {
  position: relative;
  display: inline-flex;
}
.regen-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: 320px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.2);
  animation: regen-pop-in 0.12s ease-out;
}
@keyframes regen-pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.regen-popover-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}
.regen-popover-hint {
  font-size: 11.5px;
  color: rgba(226, 232, 240, 0.55);
  margin: 0 0 10px;
  line-height: 1.4;
}
.regen-popover-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  outline: none;
  box-sizing: border-box;
}
.regen-popover-input:focus {
  border-color: rgba(99, 102, 241, 0.55);
  background: rgba(99, 102, 241, 0.06);
}
.regen-popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 10px;
}
.regen-popover-actions .btn.small {
  padding: 5px 12px;
  font-size: 12px;
}
.chrome-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text);
  margin: 8px 0;
  cursor: pointer;
  user-select: none;
}
.chrome-row input[type="checkbox"] {
  accent-color: #6366f1;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

/* Pinned font-size toolbar shown while in text-edit mode. */
.te-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.2);
  font-size: 12px;
  color: var(--text);
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
}
.te-toolbar:not([hidden]) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.te-toolbar .te-tb-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.te-tb-done {
  background: transparent;
  color: rgba(226, 232, 240, 0.3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  gap: 4px;
  transition: background 0.15s, color 0.15s;
}
.te-tb-done.te-done-has-changes {
  background: rgba(99, 102, 241, 0.2);
  color: #c7d2fe;
}
.te-tb-done.te-done-has-changes:hover {
  background: rgba(99, 102, 241, 0.35) !important;
  color: #fff !important;
}
.te-tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
  height: 24px;
}
.te-tb-btn:hover {
  background: rgba(99, 102, 241, 0.18);
  color: #c7d2fe;
}
.te-tb-btn.te-tb-text {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.te-tb-size {
  display: inline-block;
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: rgba(226, 232, 240, 0.7);
}
.te-tb-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0 2px;
}

/* "Edit text" toolbar button states */
.stage-actions .btn#textEditBtn.active {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.35);
}
.stage-actions .btn#textEditBtn.te-unsaved {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.slide-frame-fit {
  position: relative;
  margin: auto;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: none;
}

.slide-frame-fit.visible {
  display: block;
}

/* Both A/B frames live on top of the backdrop. The "active" one is fully
   opaque; the "inactive" one is fully transparent. We swap the class on
   load to cross-fade — keeps the previous slide visible until the new one
   has actually painted, so there's no white flash on switch/regeneration.
   Uses class selectors only (no #ids) so .slide-frame-active actually wins
   the specificity battle when toggled. */
.slide-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--stage-render-w, 1280px);
  height: var(--stage-render-h, 720px);
  border: 0;
  background: transparent;
  transform-origin: top left;
  transform: scale(var(--stage-scale, 1));
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 2;
}

.slide-frame.slide-frame-active {
  opacity: 1;
  pointer-events: auto;
}

/* Thumbnail backdrop sits behind both iframes. We set its src to the slide's
   WebP thumbnail the instant the user clicks a slide, so the visual swap is
   "instant" even before the iframe network request completes. The active
   iframe fades in over the top once it's actually rendered. */
.slide-frame-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--stage-render-w, 1280px);
  height: var(--stage-render-h, 720px);
  border: 0;
  display: block;
  object-fit: cover;
  transform-origin: top left;
  transform: scale(var(--stage-scale, 1));
  background: #000;
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
  z-index: 1;
}

.slide-frame-backdrop.visible {
  opacity: 1;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px;
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
}

.empty-state.hidden {
  display: none;
}

/* ---------------- Chat ---------------- */

.chat {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.chat-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 0;
  max-height: 240px;
  overflow-y: auto;
}

.chat-progress:empty {
  padding: 0;
  display: none;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-title {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Model / thinking selector bar — sits below the send button inside the form */
.model-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border);
}

.model-select {
  flex: 1 1 auto;
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 4px 24px 4px 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.12s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  min-width: 0;
}

.model-select.thinking-select {
  flex: 0 0 auto;
  min-width: 110px;
}

.model-select:hover { border-color: #2f3447; }
.model-select:focus { border-color: var(--accent); }
.model-select option { background: #1a1d2e; color: var(--text); }

.chat-status {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px 0;
}

.chat-status:empty {
  display: none;
  padding: 0;
}

.chat-status.thinking {
  color: var(--accent);
}

.chat-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.progress-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: rgba(99, 102, 241, 0.05);
  border: 1px dashed rgba(99, 102, 241, 0.28);
  border-radius: 10px;
  align-self: stretch;
  transition: opacity 600ms ease, transform 600ms ease, max-height 600ms ease, padding 600ms ease, margin 600ms ease;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.progress-group.fade-out {
  opacity: 0;
  transform: translateY(-4px);
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-color: transparent;
  margin-top: -10px;
  overflow: hidden;
}

.progress-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.progress-item .pi-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.progress-item.done .pi-icon {
  border: none;
  background: var(--ok);
  animation: none;
  position: relative;
}

.progress-item.done .pi-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.progress-item.error .pi-icon {
  border: none;
  background: var(--danger);
  animation: none;
}

.progress-item .pi-text {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-item .pi-op {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 6px;
  border-radius: 999px;
}

.progress-item.is-tool {
  margin-left: 18px;
  background: transparent;
  border: 1px dashed var(--border);
  font-style: italic;
  color: var(--muted);
}

.progress-item.is-tool .pi-text {
  font-style: italic;
}

.progress-item.is-tool .pi-icon {
  border-color: var(--accent, #6ea8ff);
  border-top-color: transparent;
}

.progress-item.is-tool.done {
  font-style: normal;
  color: var(--text);
}

.progress-item.is-queued {
  opacity: 0.55;
  border-style: dotted;
}

.progress-item.is-queued .pi-icon {
  animation: none;
  border-color: var(--muted);
  border-top-color: transparent;
  opacity: 0.5;
}

/* Live "thinking" notes — orchestrator plan reply and per-slide commentary
   the model produces between tool calls. Rendered as a muted italic line
   threaded into the progress group. */
.progress-thought {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  margin: 1px 0;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(226, 232, 240, 0.55);
  font-style: italic;
}

.progress-thought.action-thought {
  margin-left: 18px;
  border-left: 2px solid rgba(255, 255, 255, 0.06);
  padding-left: 8px;
}

.progress-thought .pt-icon {
  flex: 0 0 auto;
  margin-top: 2px;
  color: rgba(226, 232, 240, 0.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress-thought .pt-text {
  flex: 1 1 auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.progress-thought.is-thinking-pulse .pt-text {
  opacity: 0.5;
  animation: thinking-pulse 1.4s ease-in-out infinite;
}
@keyframes thinking-pulse {
  0%, 100% { opacity: 0.35; }
  50%       { opacity: 0.7; }
}

/* Plan list — structured summary of the orchestrator's planned actions. */
.plan-list {
  margin: 6px 0 8px 0;
  padding: 8px 10px 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
}

.plan-list-head {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.55);
  margin: 0 0 6px 2px;
}

.plan-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 2px;
  line-height: 1.4;
  color: rgba(226, 232, 240, 0.78);
}

.plan-row .plan-op {
  flex: 0 0 auto;
  display: inline-block;
  min-width: 50px;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(226, 232, 240, 0.7);
}

.plan-row.plan-op-create .plan-op { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.plan-row.plan-op-edit   .plan-op { background: rgba(110, 168, 255, 0.18); color: #93c5fd; }
.plan-row.plan-op-delete .plan-op { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.plan-row.plan-op-reorder .plan-op { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }

.plan-row .plan-label {
  flex: 1 1 auto;
  word-break: break-word;
}

/* Per-slide brief — collapsible disclosure showing the prompt the
   orchestrator handed to the slide-gen sub-agent. */
.progress-brief {
  margin: 1px 0 1px 18px;
  padding: 0;
  border-left: 2px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: rgba(226, 232, 240, 0.6);
}

.progress-brief .pb-summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  color: rgba(226, 232, 240, 0.55);
  border-radius: 4px;
  transition: background 0.1s ease, color 0.1s ease;
}

.progress-brief .pb-summary::-webkit-details-marker { display: none; }

.progress-brief .pb-summary:hover {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(226, 232, 240, 0.85);
}

.progress-brief[open] .pb-summary svg {
  transform: rotate(90deg);
}

.progress-brief .pb-summary svg {
  transition: transform 0.12s ease;
  flex: 0 0 auto;
}

.progress-brief .pb-body {
  margin: 4px 8px 6px 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(226, 232, 240, 0.7);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

.msg.user {
  background: rgba(99, 102, 241, 0.10);
  border-color: rgba(99, 102, 241, 0.35);
  align-self: flex-end;
  max-width: 90%;
  position: relative;
}

.msg.user .msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg .msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.msg .msg-attachments img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.msg.user .msg-edit-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
  padding: 0;
}

.msg.user:hover .msg-edit-btn,
.msg.user:focus-within .msg-edit-btn {
  opacity: 1;
}

.chat-log[data-sending="true"] .msg-edit-btn {
  display: none !important;
}

.msg.user .msg-edit-btn:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.25);
}

.msg.user.editing {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  width: 100%;
  max-width: 100%;
}

.msg.user.editing .msg-edit-textarea {
  width: 100%;
  min-height: 64px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  resize: vertical;
}

.msg.user.editing .msg-edit-textarea:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.65);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.msg.user.editing .msg-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.msg.user.editing .btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.msg.assistant {
  background: var(--panel-2);
  align-self: flex-start;
  max-width: 95%;
}

.msg.system {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  align-self: center;
}

.msg.error {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.chat-form {
  margin: 0;
  padding: 0;
  border: none;
}

.chat-input-wrap {
  position: relative;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--border);
  transition: border-color 0.15s ease, background 0.15s ease;
  width: 100%;
}

.chat-input-wrap:focus-within {
  background: rgba(255,255,255,0.06);
  border-top-color: rgba(99,102,241,0.5);
}

.chat-input-wrap textarea {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  resize: none;
  padding: 12px 52px 12px 48px;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
}

.chat-input-wrap textarea::placeholder {
  color: rgba(148,163,184,0.5);
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 8px 0 8px;
}

.chat-attachments:empty {
  display: none;
}

.chat-attach-chip {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.5);
  flex: 0 0 auto;
}

.chat-attach-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-attach-chip.uploading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  border-radius: inherit;
}

.chat-attach-chip .chip-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.chat-attach-chip .chip-spinner::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.chat-attach-chip.error {
  border-color: rgba(239, 68, 68, 0.65);
  background: rgba(239, 68, 68, 0.18);
}

.chat-attach-chip .chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.chat-attach-chip:hover .chip-remove,
.chat-attach-chip:focus-within .chip-remove {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chat-input-tools {
  position: absolute;
  bottom: 6px;
  left: 6px;
  display: flex;
  gap: 4px;
}

.chat-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s ease, color 0.12s ease;
}

.chat-tool-btn:hover {
  background: rgba(99, 102, 241, 0.16);
  color: var(--text);
}

.assets-popover {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  z-index: 60;
  width: 300px;
  max-height: 340px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.2);
  overflow: hidden;
  animation: regen-pop-in 0.12s ease-out;
}
.assets-popover-header {
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.assets-popover-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  display: block;
}
.assets-popover-hint {
  font-size: 11px;
  color: rgba(226,232,240,0.45);
  display: block;
  margin-top: 2px;
}
.assets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px;
  overflow-y: auto;
}
.assets-grid:empty::after {
  content: "No images uploaded yet";
  grid-column: 1 / -1;
  font-size: 12px;
  color: rgba(226,232,240,0.35);
  text-align: center;
  padding: 16px 0;
}
.asset-thumb {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  position: relative;
  background: rgba(255,255,255,0.04);
  transition: border-color 0.12s;
}
.asset-thumb:hover {
  border-color: rgba(99,102,241,0.6);
}
.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.asset-thumb-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 4px;
  font-size: 9px;
  color: #fff;
  background: rgba(0,0,0,0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.chat-drop-overlay {
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  background: rgba(99, 102, 241, 0.16);
  border: 2px dashed rgba(99, 102, 241, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  pointer-events: none;
  z-index: 20;
  backdrop-filter: blur(2px);
}

.chat-drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.chat-send-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.12s ease, transform 0.06s ease, background 0.18s ease, opacity 0.12s ease;
  font-family: inherit;
  box-shadow: 0 1px 4px rgba(99,102,241,0.35);
}

.chat-send-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.chat-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send-btn .icon-send,
.chat-send-btn .icon-stop {
  display: block;
}

.chat-send-btn .icon-stop {
  display: none;
}

.chat-send-btn.stop {
  background: var(--danger);
  animation: stopPulse 1.3s ease-in-out infinite;
}

.chat-send-btn.stop .icon-send {
  display: none;
}

.chat-send-btn.stop .icon-stop {
  display: block;
}

@keyframes stopPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ---------------- Buttons ---------------- */

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}

.btn:hover:not(:disabled) {
  border-color: #2f3447;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: white;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.btn.danger {
  color: #fca5a5;
}

.btn.danger:hover:not(:disabled) {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.btn.ghost {
  background: transparent;
}

.btn.large {
  padding: 10px 16px;
  font-size: 14px;
  margin-top: 12px;
}

/* ---------------- Presenter overlay ---------------- */

.presenter-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: none;
}

.presenter-overlay[hidden] {
  display: none;
}

.presenter-overlay.show-cursor {
  cursor: default;
}

.presenter-frames {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: calc(100vh * 16 / 9);
  max-height: calc(100vw * 9 / 16);
  background: #000;
}

.pres-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  opacity: 0;
  transition: opacity 280ms ease, transform 280ms ease;
  pointer-events: none;
  transform: scale(1.005);
}

.pres-frame.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.presenter-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  z-index: 5;
}

.presenter-progress .bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 240ms ease;
}

.presenter-top {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 7;
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.presenter-overlay.show-cursor .presenter-top,
.presenter-top:hover {
  opacity: 1;
  pointer-events: auto;
}

.pres-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 18, 26, 0.78);
  backdrop-filter: blur(10px);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.pres-btn:hover {
  background: rgba(28, 33, 47, 0.9);
  border-color: rgba(255, 255, 255, 0.16);
}

.pres-btn.ghost {
  padding: 8px 12px;
}

.pres-icon {
  font-size: 14px;
  line-height: 1;
}

.presenter-chrome {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: rgba(15, 18, 26, 0.78);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  z-index: 6;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.presenter-overlay.show-cursor .presenter-chrome,
.presenter-chrome:hover {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.pres-ctrl {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.12s ease;
}

.pres-ctrl:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.pres-ctrl:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pres-counter {
  font-size: 12px;
  color: #c1c6d4;
  padding: 0 10px;
  min-width: 56px;
  text-align: center;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

/* ---------------- Scrollbars (global) ---------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.22);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* ---------------- Version banner ---------------- */

.version-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(139, 92, 246, 0.14));
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 12px;
  margin: 0 16px 8px;
  color: var(--text);
  flex-wrap: wrap;
}

.version-banner[hidden] {
  display: none;
}

.version-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.version-banner-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.version-banner-summary {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}

.version-banner-actions {
  display: flex;
  gap: 8px;
}

/* ---------------- Version history panel ---------------- */

.history-panel {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  justify-content: flex-end;
  animation: modalFadeIn 140ms ease;
}

.history-panel[hidden] {
  display: none !important;
}

.history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.55);
  backdrop-filter: blur(4px);
}

.history-card {
  position: relative;
  width: 380px;
  max-width: 100%;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.55);
  animation: historySlideIn 180ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes historySlideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.history-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.history-subtitle {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.08s ease, background 0.12s ease;
}

.history-row:hover {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.06);
}

.history-row.is-current {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.06);
}

.history-row.is-viewing {
  border-color: rgba(99, 102, 241, 0.7);
  background: rgba(99, 102, 241, 0.12);
}

.history-row .v-num {
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
  min-width: 36px;
}

.history-row .v-body {
  min-width: 0;
}

.history-row .v-summary {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-row .v-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.history-row .v-source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  color: #c7d2fe;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.history-row .v-source.ai { background: rgba(139, 92, 246, 0.18); color: #ddd6fe; }
.history-row .v-source.restore { background: rgba(245, 158, 11, 0.18); color: #fde68a; }
.history-row .v-source.create { background: rgba(34, 197, 94, 0.18); color: #bbf7d0; }
.history-row .v-source.manual { background: rgba(255, 255, 255, 0.08); color: var(--muted); }

.history-row .v-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.history-row:hover .v-actions,
.history-row.is-viewing .v-actions {
  opacity: 1;
}

.btn.icon-only {
  padding: 8px;
  min-width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 600px) {
  .history-card {
    width: 100%;
  }
  .history-subtitle {
    max-width: 200px;
  }
}

/* ---------------- Slide context menu ---------------- */

.context-menu {
  position: fixed;
  z-index: 9000;
  min-width: 200px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: ctx-pop 0.08s ease-out;
}

.context-menu[hidden] {
  display: none !important;
}

@keyframes ctx-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.context-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: none;
  color: var(--text);
  border: 0;
  padding: 8px 12px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: background 0.1s ease;
}

.context-menu button:hover,
.context-menu button:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.context-menu button svg {
  flex: 0 0 14px;
  color: var(--muted);
}

.context-menu button:hover svg {
  color: var(--text);
}

.context-menu button.danger {
  color: #fca5a5;
}

.context-menu button.danger:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.context-menu button.danger svg {
  color: #fca5a5;
}

.context-menu .ctx-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

.slide-item.context-active {
  outline: 1px solid rgba(99, 102, 241, 0.55);
  outline-offset: -1px;
}

/* ---------------- Modal dialog ---------------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalFadeIn 140ms ease;
}

.modal-root[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.62);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  animation: modalPopIn 160ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.modal-root.danger .modal-card {
  border-color: rgba(239, 68, 68, 0.35);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.modal-message {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.modal-input-wrap {
  margin-bottom: 16px;
}

.modal-input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.modal-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* -------- Share modal redesign -------- */

.share-card {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04) inset;
  animation: modalPopIn 160ms cubic-bezier(0.2,0.9,0.3,1.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.share-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 20px 0;
}

.share-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.25);
  color: #818cf8;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.share-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.share-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}

.share-close-btn {
  margin-left: auto;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.share-close-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }

.share-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  margin-top: 16px;
}

.share-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.share-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.share-status-off  { background: rgba(255,255,255,0.2); }
.share-status-on   { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,0.2); }

.share-toggle-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.12s ease, background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.share-toggle-off {
  background: var(--accent);
  color: white;
}
.share-toggle-off:hover { filter: brightness(1.12); }
.share-toggle-on {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: var(--muted);
}
.share-toggle-on:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.25); color: #fca5a5; }

.share-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px 20px;
  transition: opacity 0.2s ease;
}

.share-link-row.share-link-inactive {
  opacity: 0.35;
  pointer-events: none;
}

.share-link-icon {
  color: var(--muted);
  flex-shrink: 0;
}

.share-link-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  color: var(--text);
  outline: none;
  min-width: 0;
  transition: border-color 0.12s ease;
}
.share-link-input:focus { border-color: var(--accent); }

.share-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.share-copy-btn:hover:not(:disabled) { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.18); }
.share-copy-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.share-copy-btn.copied { background: rgba(52,211,153,0.12); border-color: rgba(52,211,153,0.3); color: #34d399; }

.modal-actions .btn.danger {
  background: var(--danger);
  border-color: transparent;
  color: white;
}

.modal-actions .btn.danger:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: transparent;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalPopIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ---------------- Mobile tabs (bottom nav) ---------------- */

.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9000;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  gap: 4px;
}

.mobile-tabs .mtab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.mobile-tabs .mtab svg {
  display: block;
}

.mobile-tabs .mtab.active {
  color: var(--text);
  background: rgba(99, 102, 241, 0.14);
}

.mobile-tabs .mtab:active {
  background: rgba(255, 255, 255, 0.05);
}

/* ---------------- Responsive: tablet/mobile ---------------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100vh;
    height: 100dvh;
  }

  .resize-handle { display: none; }

  .sidebar,
  .stage,
  .chat {
    grid-row: 1;
    grid-column: 1;
    height: 100vh;
    height: 100dvh;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar { border-right: 0; }
  .chat    { border-left: 0; }

  body[data-view="slides"] .stage,
  body[data-view="slides"] .chat   { display: none; }
  body[data-view="stage"]  .sidebar,
  body[data-view="stage"]  .chat   { display: none; }
  body[data-view="chat"]   .sidebar,
  body[data-view="chat"]   .stage  { display: none; }

  .mobile-tabs { display: flex; }

  .stage-toolbar {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .slide-title {
    flex: 1 0 100%;
    order: -1;
    font-size: 15px;
  }

  .stage-actions {
    flex-wrap: wrap;
  }

  .iframe-wrap {
    padding: 12px;
  }

  .slide-list {
    padding: 14px;
    align-items: center;
    --thumb-w: min(360px, 88vw);
    --thumb-h: calc(var(--thumb-w) * 9 / 16);
  }

  .slide-item {
    width: 100%;
    max-width: 380px;
  }

  .chat {
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  }

  .chat-input-wrap textarea,
  .modal-input {
    font-size: 16px; /* prevent iOS zoom */
  }

  /* Presenter overlay: full-bleed on mobile */
  .presenter-frames {
    max-width: 100vw;
    max-height: 100vh;
  }

  .presenter-overlay { cursor: default; }
  .presenter-top, .presenter-chrome { opacity: 1; pointer-events: auto; }

  .presenter-chrome {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .pres-ctrl { width: 44px; height: 44px; }
}

@media (max-width: 480px) {
  .stage-actions .btn { padding: 6px 10px; font-size: 13px; }
  .modal-card { padding: 18px; border-radius: 12px; }
}

/* ---------------- Command palette (Cmd/Ctrl-K) ---------------- */

.cmdk-modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
}

.cmdk-modal[hidden] { display: none; }

.cmdk-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.62);
  backdrop-filter: blur(4px);
}

.cmdk-card {
  position: relative;
  width: 100%;
  max-width: 580px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  overflow: hidden;
  animation: modalPopIn 160ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.cmdk-search-icon { color: rgba(226, 232, 240, 0.55); flex-shrink: 0; }

.cmdk-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 0;
}

.cmdk-input::placeholder { color: rgba(226, 232, 240, 0.4); }

.cmdk-esc-hint {
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.5);
  padding: 2px 7px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.cmdk-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
}

.cmdk-results::-webkit-scrollbar { width: 8px; }
.cmdk-results::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 8px; }

.cmdk-section-label {
  padding: 10px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.45);
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.cmdk-item.is-active {
  background: rgba(99, 102, 241, 0.16);
  outline: 1px solid rgba(99, 102, 241, 0.32);
}

.cmdk-item:hover { background: rgba(255, 255, 255, 0.05); }
.cmdk-item.is-active:hover { background: rgba(99, 102, 241, 0.18); }

.cmdk-item-thumb {
  width: 56px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 5px;
  background: #0e1017;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: rgba(226, 232, 240, 0.4);
}

.cmdk-item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cmdk-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cmdk-item-title {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdk-item-sub {
  font-size: 11px;
  color: rgba(226, 232, 240, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdk-item-kbd {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: rgba(226, 232, 240, 0.4);
  flex-shrink: 0;
}

.cmdk-item-kbd kbd {
  padding: 1px 5px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  font-family: inherit;
  font-size: 10px;
  margin-left: 2px;
}

.cmdk-empty {
  padding: 24px;
  text-align: center;
  color: rgba(226, 232, 240, 0.45);
  font-size: 13px;
}

.cmdk-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: rgba(226, 232, 240, 0.5);
  background: rgba(0, 0, 0, 0.18);
}

.cmdk-footer kbd {
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  font-family: inherit;
  font-size: 10px;
  color: rgba(226, 232, 240, 0.7);
}

@media (max-width: 480px) {
  .cmdk-modal { padding: 8vh 8px 8px; }
  .cmdk-card { max-height: 80vh; }
  .cmdk-input { font-size: 16px; }
  .cmdk-footer { display: none; }
}
