/* ===========================================================================
   APP — the studio chrome around the deck.

   Four zones, the arrangement that works for document editing: controls left,
   the live document centre, pages along the bottom, section progress right.
   The chrome is APEX-branded but deliberately quieter than the document, so
   the artwork is what your eye lands on.
   =========================================================================== */

@import url("../brand/fonts.css");
@import url("../brand/ds-colors.css");
@import url("../brand/ds-shape.css");

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Zalando Sans', system-ui, sans-serif;
  background: var(--apex-page);
  color: var(--apex-navy);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---- Shell grid ---------------------------------------------------------- */
.studio {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  grid-template-rows: 62px minmax(0, 1fr) 168px;
  grid-template-areas:
    "top   top    top"
    "left  stage  right"
    "left  strip  right";
  height: 100vh;
}

/* ---- Top bar ------------------------------------------------------------- */
.top {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--apex-navy-deep);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.top .mark { height: 26px; }
.top h1 { font-family: 'GC Sublime', sans-serif; font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .01em; }
.top .sub { font-size: 12px; color: #8FA0B8; }
.top .spacer { flex: 1; }

.chip {
  font-family: 'Zalando Sans SemiExpanded', sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  padding: 5px 11px; border-radius: 50px;
  background: rgba(236,179,84,.16); color: var(--apex-gold);
  border: 1px solid rgba(236,179,84,.3);
}

.btn {
  font-family: 'Zalando Sans', sans-serif; font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--apex-gold); color: var(--apex-navy);
  transition: filter .15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: #C8D2E0; border: 1px solid rgba(255,255,255,.22); }
.btn.ghost:hover { background: rgba(255,255,255,.08); }

/* ---- Side rails ---------------------------------------------------------- */
.rail {
  overflow-y: auto; overflow-x: hidden;
  background: #fff;
  padding: 18px 18px 40px;
}
.rail.left  { grid-area: left;  border-right: 1px solid var(--apex-border); }
.rail.right { grid-area: right; border-left: 1px solid var(--apex-border); }

.sec-head {
  font-family: 'Zalando Sans SemiExpanded', sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--apex-slate-500);
  margin: 22px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.sec-head:first-child { margin-top: 4px; }
.sec-head::after { content: ""; flex: 1; height: 1px; background: var(--apex-border); }

label.field { display: block; margin-bottom: 12px; }
label.field .lb {
  display: block; font-size: 11px; font-weight: 600; color: var(--apex-slate-500);
  margin-bottom: 5px; letter-spacing: .02em;
}
select, input[type="text"] {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 13px;
  border: 1px solid var(--apex-border); border-radius: 10px;
  background: #fff; color: var(--apex-navy);
}
select:focus, input[type="text"]:focus {
  outline: none; border-color: var(--apex-gold); box-shadow: var(--focus-ring);
}

/* ---- Colour swatches ----------------------------------------------------- */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw {
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; transition: transform .15s ease;
  position: relative;
}
.sw:hover { transform: translateY(-3px); }
.sw[aria-pressed="true"] { border-color: var(--apex-navy); }
.sw[aria-pressed="true"]::after {
  content: "✓"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 13px; text-shadow: 0 1px 2px rgba(0,0,0,.45);
}

/* ---- Toggle rows --------------------------------------------------------- */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.toggle .tl { font-size: 13px; color: var(--apex-navy); }
.toggle .td { font-size: 11px; color: var(--apex-slate-400); }
.sw-toggle {
  appearance: none; width: 38px; height: 22px; border-radius: 50px; flex: 0 0 auto;
  background: #D7D9DC; position: relative; cursor: pointer; transition: background .15s ease;
}
.sw-toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .15s ease;
}
.sw-toggle:checked { background: var(--apex-gold); }
.sw-toggle:checked::after { transform: translateX(16px); }

/* ---- Stage --------------------------------------------------------------- */
.stage {
  grid-area: stage;
  overflow: auto;
  background: #5A6577;
  background-image: radial-gradient(circle at 50% 0%, #6B7688 0%, #4A5568 70%);
}

/* ---- Filmstrip ----------------------------------------------------------- */
.strip {
  grid-area: strip;
  background: #fff; border-top: 1px solid var(--apex-border);
  padding: 10px 16px; overflow-x: auto; overflow-y: hidden;
  display: flex; flex-direction: column; gap: 8px;
}
.strip-head {
  display: flex; align-items: center; gap: 12px;
  font-family: 'Zalando Sans SemiExpanded', sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--apex-slate-500);
}
.thumbs { display: flex; gap: 10px; align-items: flex-start; }

.thumb {
  flex: 0 0 auto; width: 132px; cursor: pointer; position: relative;
}
.thumb .frame {
  position: relative; width: 132px; height: 102px; overflow: hidden;
  border: 2px solid var(--apex-border); border-radius: 6px; background: #fff;
  transition: border-color .15s ease;
}
.thumb.on .frame { border-color: var(--apex-gold); }
.thumb.hidden-page .frame { opacity: .32; }
.thumb .cap {
  font-size: 10px; color: var(--apex-slate-500); margin-top: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .n {
  position: absolute; top: 3px; left: 3px; z-index: 2;
  background: var(--apex-navy); color: #fff; font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 4px; display: grid; place-items: center; padding: 0 3px;
}
.thumb .eye {
  position: absolute; top: 3px; right: 3px; z-index: 2;
  width: 18px; height: 18px; border: 0; border-radius: 4px; cursor: pointer;
  background: rgba(255,255,255,.92); color: var(--apex-slate-500);
  font-size: 10px; display: grid; place-items: center; padding: 0;
}
.thumb .eye:hover { background: #fff; color: var(--apex-navy); }
.thumb.drag-over .frame { border-color: var(--apex-gold); border-style: dashed; }
.thumb[draggable="true"] { cursor: grab; }

/* The thumbnail is a real render, scaled — never a screenshot, so it can
   never drift from the page it represents. */
.thumb .frame .ds-canvas { transform-origin: top left; }

/* ---- Section list (right rail) ------------------------------------------ */
.seclist { display: flex; flex-direction: column; gap: 1px; }
.secrow {
  display: flex; align-items: center; gap: 9px; padding: 9px 8px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
  border: 0; background: transparent; width: 100%; text-align: left;
  color: var(--apex-navy); font-family: inherit;
}
.secrow:hover { background: var(--apex-cream); }
.secrow.on { background: var(--apex-cream); font-weight: 600; }
.secrow .dot {
  flex: 0 0 auto; width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
  background: #E4E6EA; color: var(--apex-slate-400);
}
.secrow.done .dot { background: var(--pass-green, #15803D); color: #fff; }
.secrow.off { opacity: .42; }
.secrow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Progress ------------------------------------------------------------ */
.progress { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--apex-border); }
.progress .row { display: flex; justify-content: space-between; font-size: 11px; color: var(--apex-slate-500); margin-bottom: 6px; }
.progress .bar { height: 6px; border-radius: 50px; background: #E8E6DE; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--grad-gold); transition: width .25s ease; }
.blocking { margin-top: 10px; font-size: 11px; color: var(--apex-rust); line-height: 1.5; }

/* ---- Misc ---------------------------------------------------------------- */
.hint { font-size: 11px; color: var(--apex-slate-400); line-height: 1.5; margin-top: 6px; }
.count { font-size: 10px; color: var(--apex-slate-400); font-weight: 600; }

/* ===========================================================================
   FORM — the editing layer. Generated from the field registry, so these
   styles have to serve every field type without knowing which is coming.
   =========================================================================== */

/* ---- Rail tabs ----------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin: 0 0 14px; padding: 3px; background: var(--apex-cream); border-radius: 10px; }
.tab {
  flex: 1; padding: 7px 10px; border: 0; border-radius: 8px; cursor: pointer;
  font-family: 'Zalando Sans SemiExpanded', sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--apex-slate-500); background: transparent;
}
.tab.on { background: #fff; color: var(--apex-navy); box-shadow: 0 1px 3px rgba(15,37,64,.12); }
.pane[hidden] { display: none; }

/* ---- Group ---------------------------------------------------------------- */
.fgroup { border: 1px solid var(--apex-border); border-radius: 12px; margin-bottom: 8px; background: #fff; }
.fgroup[open] { border-color: #D8DAE0; }
.fsum {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--apex-navy);
}
.fsum::-webkit-details-marker { display: none; }
.fsum::before { content: "▸"; color: var(--apex-slate-400); font-size: 10px; transition: transform .15s ease; }
.fgroup[open] .fsum::before { transform: rotate(90deg); }
.fsum-t { flex: 1; }
.fsum-jump {
  border: 0; background: transparent; cursor: pointer; color: var(--apex-slate-400);
  font-size: 13px; padding: 2px 5px; border-radius: 6px; line-height: 1;
}
.fsum-jump:hover { background: var(--apex-cream); color: var(--apex-gold-deep); }
.fbody { padding: 2px 12px 12px; }

/* ---- Field ---------------------------------------------------------------- */
.fld { margin-bottom: 12px; }
.flb { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--apex-slate-500); margin-bottom: 4px; }
.flb .req { color: var(--apex-gold-deep); font-size: 7px; font-style: normal; }
.fin {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 12px;
  border: 1px solid var(--apex-border); border-radius: 8px; background: #fff; color: var(--apex-navy);
}
textarea.fin { resize: vertical; line-height: 1.5; font-size: 11.5px; }
.fin:focus { outline: none; border-color: var(--apex-gold); box-shadow: var(--focus-ring); }
.fhint { font-size: 10px; color: var(--apex-slate-400); margin: 4px 0 0; line-height: 1.4; }

/* ---- Buttons -------------------------------------------------------------- */
.mini {
  font-family: inherit; font-size: 11px; font-weight: 500; padding: 5px 10px;
  border: 1px solid var(--apex-border); border-radius: 8px; background: #fff;
  color: var(--apex-navy); cursor: pointer;
}
.mini:hover { background: var(--apex-cream); }
.mini.ghost { color: var(--apex-slate-500); }
.mini-row { display: flex; gap: 6px; margin-top: 6px; }

/* ---- Image ---------------------------------------------------------------- */
.img-row { display: flex; gap: 9px; align-items: flex-start; }
.img-prev {
  flex: 0 0 auto; width: 56px; height: 44px; border-radius: 7px; overflow: hidden;
  background: var(--apex-cream); border: 1px solid var(--apex-border);
  display: grid; place-items: center;
}
.img-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-prev span { font-size: 9px; color: var(--apex-slate-400); }
.img-ctl { flex: 1; min-width: 0; }
.img-file { display: none; }

.imgs-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 7px; }
.imgs-cell { position: relative; aspect-ratio: 4/3; border-radius: 6px; overflow: hidden; background: var(--apex-cream); }
.imgs-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imgs-x {
  position: absolute; top: 2px; right: 2px; width: 15px; height: 15px; padding: 0;
  border: 0; border-radius: 4px; cursor: pointer; background: rgba(255,255,255,.92);
  color: var(--apex-navy); font-size: 11px; line-height: 1;
}
.imgs-empty { grid-column: 1 / -1; font-size: 10px; color: var(--apex-slate-400); padding: 10px 0; text-align: center; }

/* ---- Repeating rows -------------------------------------------------------- */
.lst-head { display: flex; gap: 4px; margin-bottom: 4px; }
.lst-head span { font-size: 9px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--apex-slate-400); min-width: 0; }
.lst-head .lst-sp { flex: 0 0 18px; }
.lst-row { display: flex; gap: 4px; margin-bottom: 4px; align-items: center; }
.lin {
  min-width: 0; padding: 5px 7px; font: inherit; font-size: 11px;
  border: 1px solid var(--apex-border); border-radius: 6px; background: #fff; color: var(--apex-navy);
}
.lin:focus { outline: none; border-color: var(--apex-gold); }
.lst-x {
  flex: 0 0 18px; width: 18px; height: 24px; padding: 0; border: 0; background: transparent;
  color: var(--apex-slate-400); cursor: pointer; font-size: 14px; line-height: 1; border-radius: 5px;
}
.lst-x:hover { background: #FBEAE6; color: var(--apex-rust); }
.lst-empty { font-size: 10px; color: var(--apex-slate-400); padding: 6px 0; }

/* ---- Save state ------------------------------------------------------------ */
.saved { font-size: 11px; color: var(--apex-slate-400); }
.saved.warn { color: var(--apex-rust); }
