/* Timeline editor mode — token fallbacks so it renders even if the design
 * system vars aren't present (defensive, like the other panels).
 *
 * Layout v2: a two-column grid — main column (toolbar → preview → canvas)
 * plus a 300px right side panel (Inspect | Library | AI tabs). Below 1200px
 * the panel becomes a slide-over drawer (.open). Output/Text settings live in
 * toolbar popovers (.tl-pop.open). Nothing renders below the canvas. */
.tl-wrap { display: flex; flex-direction: column; gap: 12px; padding: 4px 2px; }
.tl-wrap.tl-v2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto auto;
  grid-template-areas: "bar bar" "main side";
  gap: 12px;
  align-items: start;
}
.tl-v2 .tl-bar { grid-area: bar; }
.tl-main { grid-area: main; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.tl-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-1, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
}
.tl-bar-right { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.tl-input {
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 8px; color: var(--t1, #f2f2f5);
  padding: 7px 10px; font-size: 13px;
}
#tl-name { flex: 0 1 180px; min-width: 120px; }
.tl-btn {
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  border-radius: 8px; color: var(--t1, #f2f2f5);
  padding: 7px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.tl-btn:hover { background: var(--surface-3, rgba(255, 255, 255, 0.1)); }
.tl-btn-sm { padding: 4px 11px; font-size: 12px; line-height: 1; } /* -sm must sit BELOW .tl-btn's 13px — it shipped at 15px, then 14px, both larger than base */
.tl-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tl-btn-primary:hover { filter: brightness(1.08); }
.tl-bar-sep { width: 1px; align-self: stretch; background: var(--glass-border, rgba(255, 255, 255, 0.12)); margin: 2px 4px; }
.tl-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tl-timecode {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums; font-size: 12px;
  color: var(--t2, #b4b4bd); padding: 0 6px; white-space: nowrap;
}

/* ── toolbar popovers (Output ▾ / Text ▾) — .open convention ─────────── */
.tl-pop-wrap { position: relative; display: inline-flex; }
.tl-pop {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  min-width: 260px; max-width: min(320px, 90vw);
  flex-direction: column; gap: 8px;
  padding: 12px;
  background: var(--bg, #0a0a0c);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.tl-pop.open { display: flex; }
.tl-pop-f {
  display: grid; grid-template-columns: 76px minmax(0, 1fr);
  align-items: center; gap: 8px;
  font-size: 12px; color: var(--t2, #b4b4bd);
}
.tl-pop-f select { width: 100%; }
.tl-pop-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tl-pop-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--t2, #b4b4bd);
}

/* ── right side panel (Inspect | Library | AI) ───────────────────────── */
.tl-side {
  grid-area: side;
  display: flex; flex-direction: column;
  min-height: 320px;
  max-height: calc(100vh - 32px);
  position: sticky; top: 8px;
  background: var(--surface-1, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
  overflow: hidden;
}
.tl-side-tabs {
  flex: none;
  display: flex; gap: 4px; padding: 8px;
  border-bottom: 1px solid var(--glass-border, rgba(255, 255, 255, 0.08));
}
.tl-side-tab {
  flex: 1;
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--t3, #8a8a93); font-size: 12px; font-weight: 600;
  padding: 6px 8px; cursor: pointer;
}
.tl-side-tab:hover { color: var(--t1, #f2f2f5); background: var(--surface-2, rgba(255, 255, 255, 0.06)); }
.tl-side-tab.on {
  color: var(--t1, #f2f2f5);
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.35);
}
.tl-side-panel { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }
.tl-side-panel[hidden] { display: none; }
.tl-side-empty { display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--t2, #b4b4bd); }
.tl-side-empty[hidden] { display: none; }
/* The drawer toggle only exists below 1200px (see the media query). */
.tl-side-toggle { display: none; }
.tl-side-close { align-self: flex-end; margin: 8px 12px 0; min-height: 40px; }

/* ── inspector: sectioned labeled rows (Inspect tab) ─────────────────── */
.tl-inspector { font-size: 12px; color: var(--t2, #b4b4bd); }
.tl-inspector[hidden] { display: none; }
.tl-insp-src {
  display: block; font-weight: 600; color: var(--t1, #f2f2f5);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 4px;
}
.tl-sec {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--t3, #8a8a93);
  margin: 12px 0 4px;
}
.tl-insp-f {
  display: grid; grid-template-columns: 76px minmax(0, 1fr);
  align-items: center; gap: 8px;
  min-height: 28px; padding: 2px 0;
}
.tl-insp-f input[type=number] {
  width: 100%; background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 6px; color: var(--t1, #f2f2f5); padding: 4px 6px; font-size: 12px;
}
.tl-insp-f input[type=range] { width: 100%; min-width: 0; accent-color: var(--accent, #606068); }
.tl-insp-f select {
  width: 100%; background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 6px; color: var(--t1, #f2f2f5); padding: 4px 6px; font-size: 12px;
}
.tl-insp-gen { display: flex; gap: 6px; flex-wrap: wrap; }
.tl-insp-takes { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tl-insp-takes[hidden] { display: none; }
.tl-take-btn {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.32);
  border-radius: 6px; color: var(--t1, #f2f2f5);
  padding: 4px 8px; font-size: 12px; cursor: pointer;
}
.tl-take-btn:hover { background: rgba(34, 197, 94, 0.2); }
.tl-insp-gen-takes {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  min-height: 28px; padding: 2px 0;
}
.tl-insp-gen-takes[hidden] { display: none; }
.tl-gen-take {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 2px; cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 6px; color: var(--t2, #b4b4bd);
}
.tl-gen-take.is-active {
  border-color: var(--accent, #606068); color: var(--t1, #f2f2f5);
}
.tl-gen-take img, .tl-gen-take video {
  width: 48px; height: 32px; object-fit: cover; border-radius: 4px;
  display: block; background: #111;
}
.tl-gen-take-meta {
  font-size: 10px; line-height: 1.2; max-width: 72px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── AI tab: actions + operator + beatgrid regions ───────────────────── */
.tl-ai-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tl-regions {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px;
  font-size: 12px; color: var(--t2, #b4b4bd);
}
.tl-regions[hidden] { display: none; }
.tl-operator { display: flex; flex-direction: column; gap: 6px; }
.tl-op-row { display: flex; align-items: center; gap: 8px; }
.tl-op-input { flex: 1 1 auto; min-width: 0; }
.tl-op-led {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--accent); box-shadow: 0 0 6px var(--accent);
}
.tl-operator.busy .tl-op-led { animation: tl-op-pulse 1s ease-in-out infinite; }
@keyframes tl-op-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.tl-op-out {
  font-size: 12px; color: var(--t2, #b4b4bd);
  white-space: pre-wrap; max-height: 180px; overflow-y: auto;
}
.tl-op-out:empty { display: none; }

.tl-titles { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tl-title-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px;
  background: var(--surface-1, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  border-radius: 12px; padding: 2px 4px 2px 8px; color: var(--t2, #b4b4bd);
}
.tl-title-chip button { background: none; border: none; color: inherit; cursor: pointer; padding: 0 2px; }
.uikit-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
.uikit-modal {
  width: min(440px, 92vw);
  background: var(--surface-2, #16161c);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.uikit-modal-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.uikit-modal-body { font-size: 13px; color: var(--t2, #b4b4bd); }
/* Generic body-content styling (ported from Sound Lab's .sl-modal-body so both
 * modes' modal bodies look right inside the shared component). */
.uikit-modal-body label { display: flex; flex-direction: column; gap: 5px; }
.uikit-modal-body label > span {
  color: var(--t2, #b4b4bd); font-size: 11px;  letter-spacing: 0.04em;
}
.uikit-modal-body input, .uikit-modal-body select, .uikit-modal-body textarea {
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  color: var(--text, #f5f5f7); border-radius: 8px; padding: 8px 10px; font: inherit;
}
.uikit-modal-body .sl-modal-check { flex-direction: row; align-items: center; }
.uikit-modal-f { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-size: 12px; }
.uikit-modal-f input {
  width: 100%; padding: 6px 8px; color: inherit; font-size: 13px;
  background: var(--surface-1, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12)); border-radius: 8px;
}
.uikit-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
/* Keyboard focus rings (a11y) — visible only for keyboard users. */
.tl-btn:focus-visible,
.tl-input:focus-visible,
.tl-op-input:focus-visible,
.tl-side-tab:focus-visible,
.tl-pop input:focus-visible,
.uikit-modal [data-tlm]:focus-visible,
.uikit-modal-f input:focus-visible,
.tl-insp-f input:focus-visible,
.tl-insp-f select:focus-visible,
.tl-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.tl-regions-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Region rows stack vertically in the 300px AI tab. */
.tl-region-list { display: flex; flex-direction: column; gap: 6px; }
.tl-region-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 6px; border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 8px; background: var(--surface-2, rgba(255, 255, 255, 0.05));
}
.tl-region-row label { display: inline-flex; align-items: center; gap: 4px; }
.tl-region-row input {
  background: var(--surface-1, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 6px; color: var(--t1, #f2f2f5); padding: 4px 6px; font-size: 12px;
}
.tl-region-name { width: 86px; }
.tl-region-row input[type=number] { width: 56px; }
.tl-flag-note { font-size: 11px; color: var(--t3, #8a8a93); }

.tl-preview {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  height: 300px; padding: 8px;
  background: var(--surface-1, #0e0e12);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 10px; overflow: hidden;
}
/* Output frame: shaped to the project aspect ratio (set inline from doc.w/h).
   Height-led with a width cap so 16:9 letterboxes instead of overflowing. */
.tl-frame {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  height: 100%; max-width: 100%; aspect-ratio: 9 / 16;
  background: #000; border-radius: 6px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.tl-media { max-width: 100%; max-height: 100%; display: block; }
.tl-comp {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; pointer-events: none; z-index: 1;
}
#tl-video-overlay, #tl-img-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none;
}
#tl-frame:not([data-preview-fallback]) > #tl-video,
#tl-frame:not([data-preview-fallback]) > #tl-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none;
}
#tl-frame[data-preview-fallback] > #tl-comp,
#tl-frame[data-preview-fallback] > #tl-video-overlay,
#tl-frame[data-preview-fallback] > #tl-img-overlay { display: none; }
.tl-preview-empty { color: var(--t3, #8a8a93); font-size: 13px; text-align: center; padding: 0 8px; }
.tl-preview-only-note {
  position: absolute; top: 6px; left: 8px; right: 8px;
  font-size: 11px; line-height: 1.3; text-align: center;
  color: var(--t1, #f2f2f5); background: rgba(0, 0, 0, 0.6);
  padding: 4px 8px; border-radius: 4px;
  pointer-events: none; z-index: 2;
}
#tl-frame:not([data-preview-only]) > .tl-preview-only-note { display: none; }
.tl-cap-overlay {
  position: absolute; left: 8%; right: 8%;
  padding: 4px 8px; text-align: center;
  font-weight: 700; line-height: 1.25;
  text-shadow: 0 1px 2px #000, 0 0 8px #000;
  pointer-events: none; z-index: 3;
}
.tl-cap-overlay[data-pos="top"] { top: 10%; }
.tl-cap-overlay[data-pos="center"] { top: 50%; transform: translateY(-50%); }
.tl-cap-overlay[data-pos="bottom"] { bottom: 10%; }

.tl-stage { position: relative; overflow-x: auto; overflow-y: hidden; }
.tl-markers { position: absolute; left: 0; top: 0; height: 22px; pointer-events: none; z-index: 3; }
.tl-marker { position: absolute; top: 2px; transform: translateX(-50%); color: var(--accent-strong, #c8c8d0); font-size: 10px; line-height: 1; white-space: nowrap; }
.tl-marker i { display: block; width: 0; height: 0; margin: 0 auto 1px; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 6px solid currentColor; }
.tl-menu { position: fixed; z-index: 80; min-width: 188px; padding: 4px; background: var(--surface-2, #16161a); border: 1px solid var(--glass-border, rgba(255,255,255,0.12)); border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.45); }
.tl-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: var(--t1, #f2f2f5); padding: 8px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.tl-menu button:hover, .tl-menu button:focus-visible { background: rgba(255,255,255,0.08); outline: none; }
.tl-lint { margin: 0; padding-left: 18px; }
.tl-lint li[data-level="error"] { color: #f0a8a8; }
.tl-lint li[data-level="warn"] { color: #e6d39a; }
.tl-canvas {
  display: block; width: 100%;
  background: var(--surface-1, #0e0e12);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
  cursor: crosshair;
}
/* Stage tool strip: clip-edit icon buttons + zoom, pinned top-right. */
.tl-stage-tools {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; gap: 8px; z-index: 2;
}
.tl-edit-strip, .tl-zoom { display: flex; gap: 4px; }
.tl-edit-more { display: inline-flex; flex-wrap: wrap; gap: 4px; max-width: 100%; align-items: center; }
.tl-range-note { color: var(--t2, #b4b4bd); font-size: 12px; padding: 0 4px; }
.tl-range { position: absolute; top: 0; bottom: 0; background: rgba(230, 193, 90, 0.16); border-left: 2px solid #e6c15a; border-right: 2px solid #e6c15a; pointer-events: none; z-index: 1; }
.tl-ic { display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px; }
.tl-ic svg { display: block; pointer-events: none; }
/* Add-track mini buttons — live in the track-header gutter's ruler corner.
   Translated along the stage's scrollLeft from render() so they stay pinned
   with the drawn gutter. */
.tl-gutter-actions {
  position: absolute; top: 4px; left: 6px;
  display: flex; gap: 4px; z-index: 2;
}
.tl-gutter-actions .tl-btn {
  padding: 1px 7px; font-size: 11px; line-height: 1.4;
  border-radius: 6px; color: var(--t2, #b4b4bd);
}
.tl-gutter-actions .tl-btn:hover { color: var(--t1, #f2f2f5); }
.tl-gutter-actions .tl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Library tab ─────────────────────────────────────────────────────── */
.tl-assets-head { font-size: 12px; color: var(--t2, #b4b4bd); margin-bottom: 8px; }
.tl-assets-actions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.tl-assets-actions .tl-btn { width: 100%; }
.tl-muted { color: var(--t3, #8a8a93); }
/* Tiles wrap into a grid inside the panel (the old strip scrolled sideways). */
.tl-assets-rail { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; min-height: 56px; }
.tl-asset {
  position: relative; flex: 0 0 auto; width: 80px; height: 50px;
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  border-radius: 6px; overflow: hidden; cursor: grab;
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
}
.tl-asset:active { cursor: grabbing; }
.tl-asset img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tl-asset-audio {
  width: 100%; height: 100%; display: flex; align-items: center;
  justify-content: center; padding: 6px; pointer-events: none;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(var(--accent-rgb), 0.16));
  color: rgba(255, 255, 255, 0.82); font-size: 10px; line-height: 1.15;
  text-align: center; word-break: break-word;
}
.tl-asset-badge {
  position: absolute; bottom: 2px; right: 3px; font-size: 10px;
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Keyframe / animation authoring (P3) */
.tl-insp-kf { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tl-kf-label { font-size: 11px; color: rgba(255,255,255,0.5); margin-right: 2px; }
.tl-kf-btn { font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  color: inherit; cursor: pointer; }
.tl-kf-btn:hover { background: rgba(255,255,255,0.1); }
.tl-kf-btn.on { background: rgba(var(--accent-rgb),0.25); border-color: var(--accent); color: #fff; }

/* ── below 1200px: the side panel becomes a slide-over drawer (.open) ── */
@media (max-width: 1199px) {
  .tl-wrap.tl-v2 { display: flex; flex-direction: column; }
  .tl-side-toggle { display: inline-block; }
  .tl-side {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(320px, 92vw);
    max-height: none; min-height: 0;
    border-radius: 12px 0 0 12px;
    border-right: none;
    /* solid base + token wash: content must not bleed through the drawer */
    background:
      linear-gradient(var(--surface-1, rgba(255, 255, 255, 0.04)),
        var(--surface-1, rgba(255, 255, 255, 0.04))) var(--bg, #0a0a0c);
    box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
    transform: translateX(102%);
    transition: transform 0.2s ease;
    z-index: 90;
  }
  .tl-side.open { transform: translateX(0); }
}

/* Honor reduced-motion: stop the operator-busy LED pulse (global app.css
   reduced-motion block doesn't reach this section keyframe) + the drawer
   slide transition. */
@media (prefers-reduced-motion: reduce) {
  .tl-operator.busy .tl-op-led { animation: none; }
  .tl-side { transition: none; }
}
