/* Timeline Composer — dark editor theme */
* { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --bg: #16161c;
  --panel: #1e1e26;
  --panel-2: #24242e;
  --border: #32323e;
  --text: #e6e6ee;
  --text-dim: #9a9aac;
  --accent: #4f8cff;
  --accent-2: #7a5cff;
  --danger: #e05555;
  --success: #3fb968;
  --clip-image: #3b6ea5;
  --clip-video: #7550b8;
  --clip-audio: #2f8f6b;
  --track-h: 56px;
  --ruler-h: 26px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { background: #2c2c38; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #3f7df2; }
button.accent { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.accent:hover { background: #6a4cf0; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(224, 85, 85, 0.15); }
button:disabled { opacity: 0.5; cursor: default; }

input[type="text"], input[type="number"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

/* --- toolbar ------------------------------------------------------------- */

#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.app-title { font-weight: 700; white-space: nowrap; }
#project-name { width: 180px; color: var(--text-dim); }
#project-name:focus { color: var(--text); }
.toolbar-group { display: flex; gap: 6px; align-items: center; }
.toolbar-settings { margin-left: auto; }

/* --- workspace ------------------------------------------------------------ */

#workspace {
  flex: 1;
  display: flex;
  gap: 8px;
  padding: 8px;
  min-height: 0;
}

#media-bin, #inspector {
  width: 240px;
  flex: none;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}

#preview-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0c10;
  border-radius: 6px;
  overflow: hidden;
}
#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  background: #000;
  box-shadow: 0 0 0 1px var(--border);
}

#transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: none;
}
#transport button { min-width: 42px; font-size: 15px; }
#time-display {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  margin-left: 10px;
  min-width: 120px;
}

/* --- media bin -------------------------------------------------------------- */

.bin-empty, .inspector-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 18px 6px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: grab;
  user-select: none;
}
.media-item:hover { background: var(--panel-2); border-color: var(--border); }
.media-item.media-missing { opacity: 0.55; cursor: default; }
.media-thumb {
  width: 52px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  flex: none;
}
.media-thumb-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--panel-2);
}
.media-meta { min-width: 0; flex: 1; }
.media-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.media-sub { color: var(--text-dim); font-size: 11px; }
.media-remove {
  flex: none;
  padding: 0 7px;
  font-size: 14px;
  line-height: 1.4;
  border: none;
  background: transparent;
  color: var(--text-dim);
  visibility: hidden;
}
.media-item:hover .media-remove { visibility: visible; }
.media-remove:hover { color: var(--danger); background: transparent; }

/* --- inspector --------------------------------------------------------------- */

#inspector-body { display: flex; flex-direction: column; gap: 8px; }
.inspector-clip-name {
  font-weight: 600;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field span { color: var(--text-dim); font-size: 12px; }
.field input, .field select { width: 110px; }
.inspector-actions { display: flex; gap: 6px; margin-top: 6px; }
.inspector-actions button { flex: 1; }

/* --- timeline ------------------------------------------------------------------ */

#timeline-panel {
  flex: none;
  margin: 0 8px 8px;
  display: flex;
  flex-direction: column;
  min-height: 208px; /* grows with extra layers */
}

#timeline-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.timeline-hint { color: var(--text-dim); font-size: 11px; }
.spacer { flex: 1; }
#timeline-toolbar button { padding: 1px 10px; font-size: 14px; }

#timeline-body { flex: 1; display: flex; min-height: 0; }

#track-labels {
  flex: none;
  width: 56px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.label-ruler-spacer { height: var(--ruler-h); flex: none; }
.track-label {
  height: var(--track-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 1px solid var(--border);
  position: relative;
}
.track-remove {
  position: absolute;
  right: 3px;
  padding: 0 5px;
  font-size: 12px;
  line-height: 1.3;
  border: none;
  background: transparent;
  color: var(--text-dim);
  visibility: hidden;
}
.track-label:hover .track-remove { visibility: visible; }
.track-remove:hover { color: var(--danger); background: transparent; }

#timeline-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
}

#timeline-content {
  position: relative;
  height: 100%;
  min-width: 100%;
}

#ruler {
  position: relative;
  height: var(--ruler-h);
  cursor: ew-resize;
  background: var(--panel-2);
  overflow: hidden;
}
.tick {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--border);
  pointer-events: none;
}
.tick span {
  position: absolute;
  left: 4px;
  top: 4px;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

.track {
  position: relative;
  height: var(--track-h);
  border-top: 1px solid var(--border);
  background:
    repeating-linear-gradient(to right, transparent 0, transparent 99px, rgba(255,255,255,0.03) 99px, rgba(255,255,255,0.03) 100px);
}
.track[data-track-type="audio"] { background-color: rgba(47, 143, 107, 0.05); }

.clip {
  position: absolute;
  top: 5px;
  bottom: 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  background-color: var(--clip-image);
  background-size: auto 100%;
  background-repeat: repeat-x;
  display: flex;
  align-items: flex-end;
}
.clip-video { background-color: var(--clip-video); }
.clip-audio { background-color: var(--clip-audio); }
.clip-missing-media { background-image: none !important; opacity: 0.6; border-style: dashed; }
.clip.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 2;
}
.clip-label {
  font-size: 10px;
  padding: 1px 8px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.clip-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 1;
}
.clip-handle-l { left: 0; border-radius: 5px 0 0 5px; }
.clip-handle-r { right: 0; border-radius: 0 5px 5px 0; }
.clip:hover .clip-handle { background: rgba(255, 255, 255, 0.35); }

#playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-left: 2px solid #ff5252;
  pointer-events: none;
  z-index: 5;
}
.playhead-cap {
  position: absolute;
  top: 0;
  left: -6px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid #ff5252;
}

/* --- drop overlay ------------------------------------------------------------------ */

#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
}
.drop-message {
  font-size: 22px;
  font-weight: 600;
  padding: 24px 48px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: var(--panel);
}

/* --- modals ---------------------------------------------------------------------- */

#modal-root .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  width: min(440px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal h2 { margin: 0 0 8px; font-size: 16px; }
.modal p { color: var(--text-dim); margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal .field { margin: 10px 0; }

.relink-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.relink-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.relink-row:last-child { border-bottom: none; }
.relink-status { color: var(--danger); font-weight: 700; }
.relink-row.relinked .relink-status { color: var(--success); }
.relink-row.relinked { opacity: 0.7; }

.export-info { font-size: 12px; }
.export-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.2s; }
.progress-label { font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }

body.exporting #workspace, body.exporting #timeline-panel, body.exporting #toolbar {
  pointer-events: none;
  opacity: 0.7;
}
body.exporting #modal-root { pointer-events: auto; }

/* --- toasts ----------------------------------------------------------------------- */

#toast-root {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 70;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 340px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.25s ease;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
