/* ═══════════════════════════════════════════════════════
   LAYOUTS — Shell, sidebar, wizard, editor patterns
   ═══════════════════════════════════════════════════════ */


/* ── App Shell ── */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Decorative bg blobs (behind glass panels) */
.app-shell::before {
  content: '';
  position: fixed;
  top: -20vh;
  right: -10vw;
  width: 60vw;
  height: 60vh;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(5, 99, 235, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app-shell::after {
  content: '';
  position: fixed;
  bottom: -10vh;
  left: -10vw;
  width: 50vw;
  height: 50vh;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(34, 197, 94, 0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}


/* ── Header ── */

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--header-h);
  padding: 0 var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.app-header-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 800;
  box-shadow: var(--shadow-brand);
}

.app-header-title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--text);
}


/* ── Sidebar (future: multi-tool nav) ── */

.app-sidebar {
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  position: fixed;
  top: var(--header-h);
  left: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--border);
  padding: var(--sp-4);
  overflow-y: auto;
  z-index: var(--z-sticky);
  display: none; /* hidden until multi-tool */
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  margin-bottom: var(--sp-1);
}

.sidebar-nav-item:hover { background: var(--brand-subtle); color: var(--text); }
.sidebar-nav-item-active { background: var(--brand-subtle); color: var(--brand); font-weight: var(--weight-semibold); }


/* ── Main content area ── */

.app-main {
  flex: 1;
  position: relative;
  z-index: 1;
}


/* ── Wizard layout ── */

.wizard-container {
  max-width: var(--wizard-max-w);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
}

.wizard-step {
  animation: fadeUp var(--dur-slow) var(--ease) both;
  /* fadeUp ("both") jättää transformin voimaan → wizard-step on pysyvä
     stacking context. Ilman z-indexiä se maalautuu DOM-järjestyksessä
     ENNEN nav-riviä, jonka Previous-napin backdrop-filter luo oman
     contextin → nappi piirtyi avattujen dropdownien (esim. Output
     language) päälle. z-index 1 nostaa step-sisällön navin yläpuolelle. */
  position: relative;
  z-index: 1;
}

.wizard-step-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text);
  margin-bottom: var(--sp-1);
}

.wizard-step-desc {
  font-size: var(--text-sm);
  color: var(--text-3);
  margin-bottom: var(--sp-6);
}

/* Step indicator dots */
.wizard-steps-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-5) 0;
}

.wizard-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: all var(--dur) var(--ease);
  cursor: pointer;
}

.wizard-dot-active {
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  box-shadow: 0 0 0 3px var(--brand-subtle);
  transform: scale(1.2);
}

.wizard-dot-done {
  background: var(--brand);
}

.wizard-connector {
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background: var(--border);
}

.wizard-connector-done {
  background: var(--brand-glass);
}


/* ── Wizard footer (fixed bottom nav) ── */

.wizard-footer {
  padding: var(--sp-5) var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--border);
}


/* ── Editor layout ── */

.editor-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  max-width: var(--editor-max-w);
  margin: 0 auto;
  width: 100%;
}

/* Editor step tabs */
.editor-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4) var(--sp-5) 0;
  gap: var(--sp-2);
}

.editor-step-tab {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  font-family: inherit;
  transition: all var(--dur) var(--ease);
}

.editor-step-tab:hover { color: var(--text-2); }
.editor-step-tab-active { background: var(--brand-subtle); border-color: var(--brand-glass); color: var(--brand); }
.editor-step-tab-done { color: var(--text-2); }

.editor-step-connector {
  width: 20px;
  height: 1px;
  background: var(--border);
}

/* Video preview area */
.editor-preview {
  padding: var(--sp-4) var(--sp-5) 0;
  display: flex;
  justify-content: center;
}

.editor-preview-frame {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, #1a1a2e, #0f0f1a);
  border: 1px solid var(--border);
  position: relative;
  box-shadow: var(--shadow-lg);
}

/* Editor panel (below preview) */
.editor-panel {
  flex: 1;
  overflow: auto;
  padding: var(--sp-4) var(--sp-5);
}

/* Editor footer */
.editor-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur-sm));
  display: flex;
  align-items: center;
  justify-content: space-between;
}


/* ── Selection grid (styles, substyles, dimensions) ── */

.selection-grid {
  display: grid;
  gap: var(--sp-3);
}

.selection-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.selection-grid-2 { grid-template-columns: 1fr 1fr; }

.selection-card {
  padding: var(--sp-5);
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--surface);
  transition: all var(--dur) var(--ease);
  position: relative;
}

.selection-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.selection-card-active {
  border-color: var(--brand);
  background: var(--brand-subtle);
  box-shadow: var(--shadow-brand);
}

.selection-card-active:hover {
  border-color: var(--brand);
  background: var(--brand-subtle);
  box-shadow: var(--shadow-brand);
  filter: brightness(0.97);
}

.selection-card-check {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  box-shadow: var(--shadow-sm);
}


/* ── Timeline (shared across editor steps) ── */

.timeline-ruler {
  position: relative;
  height: 18px;
  margin-bottom: var(--sp-1);
}

.timeline-ruler-mark {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timeline-ruler-label {
  font-size: 8px;
  font-family: var(--font-mono);
  color: var(--text-4);
  margin-top: 2px;
}

.timeline-playhead {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--danger);
  z-index: 10;
  pointer-events: none;
}

.timeline-playhead-head {
  position: absolute;
  top: -8px;
  left: -5px;
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--danger);
  pointer-events: none;
}

.timeline-track {
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  margin-bottom: var(--sp-1);
}


/* ── Loading screen ── */

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - var(--header-h));
}

.loading-card {
  text-align: center;
  max-width: 440px;
  width: 100%;
  padding: var(--sp-8);
}

/* ── Preview split layout: video top / scrollable controls bottom ── */
.preview-split-page {
  display: flex;
  flex-direction: column;
  /* 52px shell header + 24px container padding top & bottom */
  height: calc(100vh - 100px);
  height: calc(100dvh - 100px);
  min-height: 480px;
}
/* Desktop: no header, 8px top frame gap */
@media (min-width: 800px) {
  .preview-split-page {
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
  }
}
.preview-split-head { flex-shrink: 0; }
.preview-split-head .wizard-step-desc { margin-bottom: var(--sp-3); }

.preview-split {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* Light gray frame around the whole preview area so the video pane and the
     controls pane read as two sections of one unit, with the divider between. */
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 12px;
}
.preview-split.dragging { user-select: none; }
/* iframes swallow pointer events — disable them while dragging the divider */
.preview-split.dragging iframe { pointer-events: none; }

/* Top pane: video stage + transport. Height driven by inline clamp() from state. */
.preview-split-top {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 170px;
  overflow: hidden;
}
.preview-split-stage {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Contain-fit: width = min(pane width, pane height × aspect). Exact ratio so
   the %-anchored caption/logo overlays match the rendered output. */
.preview-split-stagebox {
  position: relative;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  width: 100%;
  max-height: 100%;
  width: min(100cqw, calc(100cqh * var(--arn, 0.5625)));
}
.preview-split-transport {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0 2px;
}

/* Divider — full-width bar with an up/down chevron handle in the middle so
   it is clearly visible and clearly draggable. */
.preview-split-divider {
  flex-shrink: 0;
  height: 24px;
  position: relative;
  display: flex;
  align-items: center;
  cursor: row-resize;
  touch-action: none;
}
.preview-split-grip {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(0,0,0,.10);
  transition: background .15s ease;
}
.preview-split-handle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 3px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
  color: rgba(0,0,0,.45);
  pointer-events: none;
  transition: color .15s ease, border-color .15s ease;
}
.preview-split-divider:hover .preview-split-grip,
.preview-split.dragging .preview-split-grip { background: rgba(0,0,0,.22); }
.preview-split-divider:hover .preview-split-handle,
.preview-split.dragging .preview-split-handle { color: rgba(0,0,0,.7); border-color: rgba(0,0,0,.2); }
@media (pointer: coarse) {
  .preview-split-divider { height: 30px; }
}

/* Bottom pane: scrollable controls + sticky render footer */
.preview-split-bottom {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.preview-split-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 8px;
}
.preview-split-controls {
  /* Stacked vertically — one section card per row (was a 2-up grid). */
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}
/* Order: captions, logo, music, sfx (DOM order differs) */
.psec-captions { order: 1; }
.psec-logo { order: 2; }
.psec-audio { display: contents; }
.psec-audio > div:first-child { order: 3; }
.psec-audio > div:last-child { order: 4; }
.psec:empty { display: none; }
/* Compact section cards inside the controls grid */
.preview-split-controls > div > div {
  padding: 14px !important;
  font-size: 11px;
  margin-bottom: 0 !important;
  /* Cards sit on the gray frame — keep them white so sections stand out. */
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
}
.preview-split-controls .section-label { font-size: 9px; }

/* ── Final Touches toolbar ── */

.ft-toolbar {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex-shrink: 0;
  /* 4px top padding (§192): under 1200px this is a scroll container
     (overflow-x:auto) which clips at its content edge — the Render button's
     hover/press lift (translateY(-1px) + glow) sliced its rounded top flat.
     Desktop ≥1200px overrides with its own 10px padding and never clipped. */
  padding: 4px 0 10px;
  overflow-x: auto;
  align-items: flex-start;
  justify-content: center;
}
.ft-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 62px;
  height: 62px;
  padding: 8px 6px 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur-sm));
  -webkit-backdrop-filter: blur(var(--glass-blur-sm));
  cursor: pointer;
  color: var(--text-3);
  font-family: inherit;
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
}
.ft-btn:hover { background: var(--glass-bg-strong); color: var(--text-2); border-color: var(--border-strong); }
.ft-btn.active {
  border-color: var(--brand-glass);
  background: var(--brand-subtle);
}
/* Icon + label color follows the tool's On/Off state, not the panel state:
   Off = grey icon (even when panel is active), On = brand blue icon. */
.ft-btn.enabled { color: var(--brand); }
.ft-btn.enabled svg { color: var(--brand); }
.ft-btn svg { color: var(--text-4); transition: color var(--dur) var(--ease); }
/* Grey hover-icon is for the tool buttons only — the Render CTA keeps its
   white icon on hover (.ft-btn-render svg is #fff in every state). */
.ft-btn:not(.enabled):not(.ft-btn-render):hover svg { color: var(--text-3); }
/* ── Final Touches: prominent colored On/Off switch (Watermark / Music / Sound FX) ── */
.ft-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; padding: 3px 4px;
}
.ft-toggle-track {
  position: relative; width: 42px; height: 23px; border-radius: 999px;
  background: var(--surface-inset, #E5E7EB); border: 1px solid var(--border, rgba(0,0,0,.12));
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  flex-shrink: 0;
}
.ft-toggle.on .ft-toggle-track { background: var(--ft-ui, #0563EB); border-color: transparent; }
.ft-toggle-thumb {
  /* §337: 1px, ei 2px. Rata on border-box (base.css:8), joten sen 23px
     korkeus SISALTAA 1px reunukset -> sisamitta 21px, ja absoluuttisen
     pallon top mitataan reunuksen sisapuolelta. 2px teki valeista 3/1;
     1px tekee niista 2/2. translateX(19px) sailyy sellaisenaan. */
  position: absolute; top: 1px; left: 1px; width: 19px; height: 19px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform var(--dur) var(--ease);
}
.ft-toggle.on .ft-toggle-thumb { transform: translateX(19px); }
.ft-toggle-label {
  font-size: 12px; font-weight: 800; letter-spacing: .05em;
  color: var(--text-4); transition: color var(--dur) var(--ease);
}
.ft-toggle.on .ft-toggle-label { color: var(--ft-ui, #0563EB); }
/* Panel body reads as inactive (faded grey) until the section is switched On */
.ft-dim { opacity: .4; filter: grayscale(.75); transition: opacity var(--dur) var(--ease), filter var(--dur) var(--ease); }
.ft-btn-label {
  font-size: 9px;
  font-weight: var(--weight-semibold);
  line-height: 1;
  white-space: nowrap;
}
/* Render button — brand gradient (matches .btn-primary) */
.ft-btn.ft-btn-render {
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  color: var(--text-on-brand);
  border-color: transparent;
  box-shadow: var(--shadow-brand);
}
.ft-btn.ft-btn-render svg { color: #fff; }
.ft-btn.ft-btn-render:hover {
  background: linear-gradient(135deg, var(--brand-light), #3B82F6);
  box-shadow: 0 6px 24px rgba(5, 99, 235, 0.30);
  transform: translateY(-1px);
  color: #fff;
  border-color: transparent;
}
.ft-btn.ft-btn-render:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* Desktop ≥ 1200px — toolbar is a fixed right column aligned with video area */
@media (min-width: 1200px) {
  .ft-toolbar {
    position: fixed;
    right: 0;
    top: 128px;  /* clears shell header + "Final Touches" heading */
    bottom: auto;
    width: 88px;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    gap: 8px;
    overflow-x: visible;
    overflow-y: auto;
    background: transparent;
    border-left: none;
    z-index: 90;
  }
  .ft-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    min-width: 68px;
    height: 68px;
    padding: 10px 6px 6px;
    background: transparent;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-3);
  }
  .ft-btn svg { width: 22px; height: 22px; }
  .ft-btn-label { font-size: 9px; }
  .ft-btn:hover { background: var(--surface-inset); border-color: rgba(0,0,0,.18); color: var(--text-2); }
  .ft-btn.active {
    background: var(--brand-subtle);
    border-color: var(--brand-glass);
  }
  .ft-btn.enabled { color: var(--brand); }
  .ft-btn.enabled svg { color: var(--brand); }
  .ft-btn.ft-btn-render {
    min-width: 68px;
    height: 68px;
    border: 2px solid transparent;
  }
  /* Push content away from toolbar */
  .preview-split-page { margin-right: 88px; }
}

/* Mobile compact: smaller buttons */
@media (max-width: 599px) {
  .ft-btn { min-width: 52px; height: 52px; padding: 6px 4px 4px; border-radius: var(--radius-sm); }
  .ft-btn svg { width: 18px; height: 18px; }
}

.preview-split-render {
  flex-shrink: 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  max-height: 45%;
  overflow-y: auto;
}
