/* ──────────────────────────────────────────────────────────────────
 * Studio Plus — editor shell styling.
 *
 * Tokens, typography, and card vibe are aligned with almegle.com's
 * shell.css so the two surfaces read as the same product. Layout is
 * a dense editor grid (top bar / workbench / timeline) rather than
 * almegle's content-page 3-panel shell, with tighter radii and gaps
 * since this is a tool, not a feed.
 *
 * Theme: light by default to match almegle.com. The bootstrapping
 * script in index.html reads the cross-subdomain `cs` cookie so a
 * user with dark mode on almegle.com sees Studio Plus in dark too.
 * ────────────────────────────────────────────────────────────────── */

/* ── Theme tokens (copied verbatim from almegle.com/library/css/shell.css
 *    so the two surfaces stay token-compatible — any future updates on
 *    almegle.com should be mirrored here in lockstep) ───────────────── */
:root {
  --bg: #e8e6df;
  --fg: #000000;
  --card-bg: #ffffff;
  --chat-bg: #f8f7f3;
  --card-border: rgba(0, 0, 0, 0.18);
  --muted: rgba(0, 0, 0, 0.52);
  --surface: rgba(0, 0, 0, 0.04);
  --surface-strong: rgba(0, 0, 0, 0.07);
  --border: rgba(0, 0, 0, 0.14);
  --accent: #000000;
  --accent-fg: #ffffff;
  --shadow:      0 24px 60px rgba(0, 0, 0, 0.08);
  --shadow-soft: 0 8px 24px  rgba(0, 0, 0, 0.05);
  /* Editor-only tokens layered on top of almegle's. Density is tighter
   * than almegle's content pages so the timeline + preview get every
   * available pixel. */
  --panel-radius:   14px;
  --shell-gap:      6px;
  --shell-pad:      6px;
  --topbar-h:       54px;
  --tl-tools-h:     34px;
  --ruler-h:        28px;
  --track-h:        56px;
  /* Clip palette (kept across themes — colour is information here). */
  --clip-video:  #2d6cdf;
  --clip-audio:  #36a572;
  --clip-image:  #a063d9;
  --danger:      #e05a2b;
  color-scheme: light;
}
html.dark {
  --bg: #0e1226;
  --fg: #f0ede8;
  --card-bg: #171a30;
  --chat-bg: #171a30;
  --card-border: rgba(240, 237, 232, 0.18);
  --muted: rgba(240, 237, 232, 0.48);
  --surface: rgba(255, 255, 255, 0.05);
  --surface-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #f0ede8;
  --accent-fg: #0a0a0a;
  --shadow:      0 24px 60px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 8px 24px  rgba(0, 0, 0, 0.20);
  color-scheme: dark;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Montserrat', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.55;
}
body {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr 320px;
  gap: var(--shell-gap);
  padding: var(--shell-gap);
  overflow: hidden;
  user-select: none;
  position: relative;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 500px at 10% 10%, rgba(0,0,0,.04), transparent 60%),
    radial-gradient(700px 400px at 90% 90%, rgba(0,0,0,.04), transparent 60%);
}
html.dark body::before {
  background:
    radial-gradient(900px 500px at 10% 10%, rgba(255,255,255,.05), transparent 60%),
    radial-gradient(700px 400px at 90% 90%, rgba(255,255,255,.04), transparent 60%);
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.serif { font-family: 'Fraunces', 'Times New Roman', serif; font-weight: 300; }

/* Shared card chrome — mirrors .glass-card on almegle.com, tightened for
 * the editor (smaller radius, no backdrop-filter so the dense panels
 * stay snappy on lower-end laptops). */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow-soft);
  position: relative;
  z-index: 1;
  min-width: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow-soft);
  position: relative;
  z-index: 1;
}
.topbar-brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: 'Fraunces', 'Times New Roman', serif;
  font-weight: 300; font-size: 18px; letter-spacing: .01em;
}
.topbar-brand i { color: var(--fg); opacity: .9; font-size: 14px; }

.topbar-tools {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px;
}
.tool-btn {
  appearance: none; border: none; background: transparent;
  width: 30px; height: 30px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); transition: background .15s, color .15s, transform .15s;
  font-size: 12px;
}
.tool-btn:hover { color: var(--fg); background: var(--surface); transform: translateY(-1px); }
.tool-btn.is-active { background: var(--fg); color: var(--bg); }
.tool-btn[disabled] { opacity: .35; cursor: not-allowed; }
.tool-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

.topbar-actions {
  display: inline-flex; align-items: center; gap: 10px; justify-self: end;
}
.project-tc {
  font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted);
  letter-spacing: .04em;
}
.topbar-btn {
  appearance: none; border: 1px solid var(--card-border); background: transparent;
  color: var(--fg); padding: 7px 16px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  letter-spacing: .02em; transition: background .15s, border-color .15s;
}
.topbar-btn:hover:not([disabled]) { background: var(--surface); border-color: var(--fg); }
.topbar-btn[disabled] { opacity: .4; cursor: not-allowed; }
.topbar-btn-accent { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.topbar-btn-accent:hover:not([disabled]) { background: var(--fg); opacity: .9; }

/* Theme toggle in the top bar */
.theme-toggle {
  appearance: none; border: 1px solid var(--card-border); background: transparent;
  color: var(--fg); width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 11px; transition: background .15s, transform .15s;
}
.theme-toggle:hover { background: var(--surface); transform: translateY(-1px); }

/* ── Workbench (3-column row) ────────────────────────────────────── */
.workbench {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: var(--shell-gap);
  min-height: 0;
}
.panel {
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  position: relative; z-index: 1;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.panel-head h2 {
  margin: 0;
  font-size: 8px; font-weight: 700; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--muted); flex: 1;
}
.panel-head-btn {
  appearance: none; border: 1px solid var(--card-border); background: transparent;
  color: var(--fg); width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 10px; transition: background .15s, transform .15s;
}
.panel-head-btn:hover { background: var(--surface); transform: translateY(-1px); }

/* ── Library ─────────────────────────────────────────────────────── */
.lib-drop {
  flex: 1; min-height: 0; position: relative;
  overflow-y: auto;
  padding: 10px;
}
.lib-drop.is-drag {
  background: var(--surface);
  outline: 2px dashed var(--fg); outline-offset: -8px;
}
.lib-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); text-align: center; padding: 24px;
  pointer-events: none;
}
.lib-empty i { font-size: 28px; color: var(--card-border); }
.lib-empty-sub { font-size: 11px; }
.lib-list { display: flex; flex-direction: column; gap: 6px; }
.lib-item {
  display: grid; grid-template-columns: 56px 1fr auto;
  align-items: center; gap: 10px;
  padding: 6px; border-radius: 10px;
  background: var(--surface); border: 1px solid transparent;
  cursor: grab; transition: border-color .15s, background .15s, transform .15s;
}
.lib-item:hover { border-color: var(--card-border); background: var(--card-bg); transform: translateY(-1px); }
.lib-item:active { cursor: grabbing; }
.lib-thumb {
  width: 56px; height: 36px; border-radius: 6px; overflow: hidden;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  position: relative; flex: 0 0 56px;
}
.lib-thumb img, .lib-thumb video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  pointer-events: none;
}
.lib-thumb i { font-size: 16px; color: var(--muted); }
.lib-thumb-kind {
  position: absolute; bottom: 2px; right: 2px;
  background: rgba(0,0,0,.65); color: #fff; font-size: 8px;
  width: 14px; height: 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.lib-meta { min-width: 0; }
.lib-name {
  font-size: 12px; color: var(--fg); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-info { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lib-rm {
  appearance: none; border: none; background: transparent; color: var(--muted);
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 11px;
  transition: color .15s, background .15s;
}
.lib-rm:hover { color: var(--danger); background: var(--surface); }

/* ── Preview ─────────────────────────────────────────────────────── */
.panel-preview { background: var(--card-bg); }
.preview-stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  /* The preview stage stays dark regardless of theme — pro editors keep
   * the canvas dark so the video isn't fighting bright UI. */
  background:
    repeating-conic-gradient(rgba(255,255,255,.018) 0% 25%, transparent 0% 50%) 50%/14px 14px,
    #0a0a0a;
}
.preview-letterbox {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.preview-letterbox video, .preview-letterbox canvas {
  max-width: 100%; max-height: 100%;
  background: #000;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  border-radius: 6px;
}
#previewVideo { display: block; }
#previewVideo.is-empty { display: none; }
.preview-empty {
  position: absolute; inset: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: rgba(255,255,255,.4); pointer-events: none;
}
.preview-empty i { font-size: 36px; color: rgba(255,255,255,.15); }
.preview-empty.is-hidden { display: none; }
.transport {
  flex: 0 0 auto; padding: 12px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border-top: 1px solid var(--border); background: var(--card-bg);
}
.xport-btn {
  appearance: none; border: 1px solid var(--card-border); background: transparent;
  color: var(--fg); width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 11px;
  transition: background .15s, border-color .15s, transform .15s;
}
.xport-btn:hover { background: var(--surface); transform: translateY(-1px); }
.xport-play { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); width: 44px; height: 44px; font-size: 13px; }
.xport-play:hover { background: var(--fg); border-color: var(--fg); color: var(--bg); }

/* ── Inspector ───────────────────────────────────────────────────── */
.insp-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; }
.insp-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); padding: 40px 12px; text-align: center;
}
.insp-empty i { font-size: 22px; color: var(--card-border); }
.insp-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.insp-field label {
  font-size: 8px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--muted);
}
.insp-field input, .insp-readout {
  appearance: none; background: var(--surface); border: 1px solid transparent;
  color: var(--fg); padding: 8px 12px; border-radius: 10px; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, background .15s;
}
.insp-field input:focus { outline: none; border-color: var(--fg); background: var(--card-bg); }
.insp-readout { font-size: 12.5px; }
.insp-actions { display: flex; gap: 8px; margin-top: 16px; }
.insp-btn {
  appearance: none; border: 1px solid var(--card-border); background: transparent;
  color: var(--fg); padding: 8px 14px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; flex: 1; justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}
.insp-btn:hover { background: var(--surface); border-color: var(--fg); }
.insp-btn-danger:hover { border-color: var(--danger); color: var(--danger); background: rgba(224,90,43,.08); }

/* ── Timeline ────────────────────────────────────────────────────── */
.timeline {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-rows: var(--tl-tools-h) 1fr;
  min-height: 0;
  overflow: hidden;
  position: relative; z-index: 1;
}
.tl-toolbar {
  display: flex; align-items: center; padding: 0 14px; gap: 16px;
  border-bottom: 1px solid var(--border); background: var(--card-bg);
}
.tl-time {
  font-variant-numeric: tabular-nums; font-size: 12px; color: var(--fg);
  font-weight: 600; min-width: 120px; letter-spacing: .02em;
}
.tl-zoom {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 8px; color: var(--muted);
}
.tl-zoom input[type=range] {
  width: 140px; accent-color: var(--fg);
}

.tl-scroller {
  position: relative;
  overflow: auto;
  min-height: 0;
  background: var(--surface);
}
.tl-grid {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}
.tl-ruler {
  position: sticky; top: 0; z-index: 3;
  height: var(--ruler-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  cursor: ew-resize;
  overflow: hidden;
}
.tl-ruler-tick {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid var(--border);
  padding: 5px 0 0 5px;
  font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.tl-ruler-tick.is-major { border-left-color: var(--card-border); color: var(--fg); }
.tl-tracks { display: flex; flex-direction: column; }
.tl-track {
  position: relative;
  height: var(--track-h);
  border-bottom: 1px solid var(--border);
}
.tl-track:last-child { border-bottom: none; }
.tl-track-label {
  position: sticky; left: 0; z-index: 2;
  width: 64px; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-bg); border-right: 1px solid var(--border);
  font-size: 8px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--muted);
  flex: 0 0 64px;
}
.tl-track.tl-track-video .tl-track-label { color: var(--clip-video); }
.tl-track.tl-track-audio .tl-track-label { color: var(--clip-audio); }
.tl-track-content {
  position: absolute; inset: 0 0 0 64px;
  overflow: hidden;
}

/* Clips */
.tl-clip {
  position: absolute; top: 5px; bottom: 5px;
  background: var(--clip-video);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  display: flex; align-items: stretch;
  cursor: grab;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  transition: box-shadow .15s, transform .12s;
}
.tl-clip:hover { box-shadow: 0 4px 14px rgba(0,0,0,.28); }
.tl-clip.is-selected {
  outline: 2px solid var(--fg); outline-offset: 2px;
  z-index: 2;
}
.tl-clip.is-dragging { cursor: grabbing; opacity: .85; }
.tl-clip.kind-video { background: linear-gradient(180deg, #3a7bf0 0%, #2d6cdf 100%); }
.tl-clip.kind-audio { background: linear-gradient(180deg, #3dbf85 0%, #36a572 100%); }
.tl-clip.kind-image { background: linear-gradient(180deg, #b377e8 0%, #a063d9 100%); }
.tl-clip-label {
  flex: 1; min-width: 0; padding: 7px 9px;
  color: #fff; font-size: 11px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  pointer-events: none;
  letter-spacing: .02em;
}
.tl-clip-handle {
  flex: 0 0 6px; cursor: ew-resize;
  background: rgba(0,0,0,.20);
  transition: background .12s;
}
.tl-clip-handle:hover { background: rgba(255,255,255,.32); }
.tl-clip-handle-l { order: -1; }
.tl-clip-handle-r { order: 1; }

body.tool-blade .tl-clip,
body.tool-blade .tl-track-content { cursor: crosshair; }

/* Playhead */
.tl-playhead {
  position: absolute; top: 0; bottom: 0; left: 64px;
  width: 2px;
  background: var(--fg);
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 0 8px rgba(0,0,0,.25);
}
html.dark .tl-playhead { box-shadow: 0 0 8px rgba(255,255,255,.25); }
.tl-playhead::before {
  content: '';
  position: absolute; top: 0; left: -5px;
  width: 12px; height: 12px;
  background: var(--fg);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.tl-track-content.is-drop-target {
  background: var(--surface-strong);
  outline: 1px dashed var(--fg);
  outline-offset: -2px;
}
