/*
 * Studio — /cv/:cvId (views/studio.js and app/studio/*: canvas, editor,
 * design, ats, export). The chat panel is styled by chat.css.
 *
 * Lecture Notebook world: the rail of index tabs sits on the desk at the
 * inline-start edge and is attached to the notebook panel; the panel is
 * squared paper; the A4 sheet lies on the desk and is ALWAYS white paper
 * (engine/cv-engine.css owns everything inside .cv-doc). State is carried by
 * stamp line forms (solid = done, dashed = pending) plus labels, never colour
 * alone. Motion: tab pull (base.css), highlighter sweep, stamp press, and
 * state transitions only; base.css honours prefers-reduced-motion.
 *
 * Tokens only, logical properties only (RTL-first, LTR-safe). The only raw
 * colours are the sheet's own paper white and its highlighter yellow, which
 * must not follow the dark theme because the sheet never does.
 *
 * Breakpoints (views/studio.js uses the same queries):
 *   >= 1100px     rail 64px | panel 400px | desk
 *   760-1099px    rail | desk, the panel is a drawer over the desk (.is-drawer)
 *   < 760px       one surface (panel, or the sheet with .is-sheet) + bottom tab bar
 *
 * Class prefixes: .st-* studio shell · .desk-* / .sheet-* canvas · .ed-* editor ·
 *                 .ds-* design · .ats-* ATS · .ex-* export dialog
 */

/* =========================================================================
 * Shell
 * ======================================================================= */
.st {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--desk);
  overflow: hidden;
  /* clip, not hidden: scrollIntoView() inside a pane must never scroll the shell */
  overflow: clip;
}
.st > .topbar { flex: none; position: relative; }

/* topbar parts (chrome.js builds the bar; these are the studio's pieces) */
.st-top .spacer { flex: 0 0 0; }
.st-top .tb-title { flex: 1 1 auto; min-width: 0; }
.st-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.st-name {
  flex: 0 1 300px;
  min-width: 64px;
  min-height: 40px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: 600;
  text-overflow: ellipsis;
  transition: border-color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
.st-name:hover { border-color: var(--line-strong); }
.st-name:focus { outline: none; border-color: var(--primary); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.st-save { flex: none; display: inline-flex; align-items: center; }
.st-save .stamp { font-size: 11.5px; }
.st-save-stamp:not(.is-done) svg { opacity: 0.8; }
.st-save-btn { background: none; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; min-height: 28px; }
.st-save-btn:hover { background: var(--bad-soft); }
.st-export { padding-inline: 14px 16px; }
.st-export-short { display: none; }

/* body grid */
.st-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-columns: 64px 400px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: clip;
}
.st-rail { grid-column: 1; grid-row: 1; }
.st-panel { grid-column: 2; grid-row: 1; }
.st-desk { grid-column: 3; grid-row: 1; }

/* ---- index-tab rail: tabs hang off the panel's inline-start edge ---------- */
.st-rail {
  align-items: flex-end;           /* hug the panel (inline-end of the rail) */
  gap: 8px;
  padding-block: 14px;
  overflow-x: hidden;
  overflow-y: auto;
}
.st-rail .tab { width: 58px; min-height: 58px; }   /* 6px spare so the pulled tab stays on screen */
.tab .tab-label { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tab .dot { box-shadow: 0 0 0 2px var(--paper-2); }
.tab[aria-selected="true"] .dot { background: var(--coral-ink); box-shadow: 0 0 0 2px var(--coral); }

/* ---- the notebook panel ------------------------------------------------------ */
.st-panel {
  --tabc: var(--teal);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--paper);
  border-inline: 1px solid var(--line);
}
.st[data-tab="chat"] .st-panel { --tabc: var(--violet); }
.st[data-tab="content"] .st-panel { --tabc: var(--teal); }
.st[data-tab="design"] .st-panel { --tabc: var(--amber); }
.st[data-tab="ats"] .st-panel { --tabc: var(--coral); }

.st-panel-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding-block: 6px;
  padding-inline: 16px 8px;
  border-block-end: 2px solid var(--tabc);
  background: var(--paper);
}
.st-panel-title { flex: 1; min-width: 0; font-size: var(--fs-lg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-panel-close { display: none; }
/* the chat draws its own header */
.st[data-tab="chat"] .st-panel-head { display: none; }

.st-panes { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.st-tabpanel {
  position: relative;               /* contains the panes' .sr-only live regions */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 48px;
  /* squared notebook paper that scrolls with the writing */
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  background-position: -1px -1px;
  background-attachment: local;
}
.st-pane-chat { overflow: hidden; padding: 0; display: flex; flex-direction: column; background-image: none; }
.st-chat-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.st-chat-status { display: flex; align-items: center; justify-content: center; gap: 10px; flex: 1; color: var(--ink-3); font-size: var(--fs-sm); }
.st-chat-failed { flex: 1; align-content: center; }
.st-chat-failed p { max-width: 36ch; color: var(--ink-2); }
.st-chat-failed .row { flex-wrap: wrap; justify-content: center; }

/* ---- the desk ------------------------------------------------------------------ */
.st-desk {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--desk);
}

/* ---- phone tab bar (hidden until < 760px) -------------------------------------- */
.st-tabbar {
  display: none;
  flex: none;
  padding: 0 6px env(safe-area-inset-bottom);
  background: var(--desk);
  border-block-start: 1px solid var(--line);
}
.st-tabbar-list { display: flex; gap: 4px; }
/* tabs hang from the bottom edge of the page: the free end faces down */
.st-tabbar .tab-h {
  min-width: 0;
  min-height: 54px;
  padding: 7px 2px 6px;
  border-radius: 0 0 var(--r-md) var(--r-md) !important;
}
.st-tabbar .tab-h::before { inset-block: 0 auto; }

/* ---- shared bits ------------------------------------------------------------------ */
.st-spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-inline-end-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
.st-progress { display: flex; align-items: center; gap: 12px; color: var(--ink-2); padding-block: 8px; }

/* payment return: "Confirming your payment…" / not confirmed yet (views/studio.js) */
.st-pay { display: grid; gap: 12px; }
.st-pay-note { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); }
.st-pay-note svg { flex: none; width: 18px; height: 18px; margin-block-start: 3px; color: var(--ink-2); }
.st-pay-actions { flex-wrap: wrap; }
/* rescue offer: unsaved edits kept on this device */
.st-rescue { display: grid; gap: 8px; }
.st-rescue p:first-child { color: var(--ink); }

/* loading + error states before the studio exists */
.st-boot-body {
  flex: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  padding: 24px 16px;
  text-align: center;
}
.st-boot-sheet { inline-size: min(340px, 64vw); aspect-ratio: 210 / 297; border-radius: 3px; }
.st-boot-body > .muted { color: var(--ink-2); }  /* on the desk, --ink-3 is below 4.5:1 */
.st-boot .empty { max-width: 460px; }
.st-boot .empty p { color: var(--ink-2); }
.st-boot .empty .row { flex-wrap: wrap; justify-content: center; }

/* version history dialog */
.st-v { display: grid; gap: 12px; }
.st-v-status { display: grid; gap: 8px; }
.st-v-status:empty { display: none; }
.st-v-sk { height: 46px; }
.st-versions {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(52vh, 440px);
  overflow-y: auto;
  border-block-start: 1px solid var(--line);
}
.st-version {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 2px;
  border-block-end: 1px dashed var(--rule);
}
.st-version-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.st-version-when { font-weight: 500; }
.st-version.is-current .st-version-when { color: var(--ok); }

/* =========================================================================
 * Canvas: the desk, the sheet(s), zoom tools
 * ======================================================================= */
.desk-scroll { position: relative; flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.desk-stage {
  display: grid;
  justify-items: center;
  gap: 28px;
  padding: 28px 24px 44px;
}
.sheet-wrap { display: grid; justify-items: center; gap: 8px; }
/* The frame is the page's SCALED size, so zoom never leaves layout gaps. The
   true 794 x 1123 page inside is scaled from its top-left corner; the frame is
   LTR only for that geometry (the .cv-doc inside sets its own direction). */
.sheet-frame {
  inline-size: calc(var(--page-w) * var(--z, 1));
  block-size: calc(var(--page-h) * var(--z, 1));
  overflow: hidden;
  direction: ltr;
  background: #fff;                 /* the sheet is paper in both themes */
  border-radius: 2px;
  box-shadow: var(--shadow-sheet);
}
.sheet-scale {
  inline-size: var(--page-w);
  block-size: var(--page-h);
  transform: scale(var(--z, 1));
  transform-origin: 0 0;
}
/* tap any line to edit it */
.sheet-frame .cv-block { cursor: pointer; }
@media (hover: hover) {
  .sheet-frame .cv-block:hover { outline: 1px dashed color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
}
/* The highlighter on the sheet keeps its light-paper yellow in dark mode too. */
.sheet-frame { --highlight: rgba(255, 224, 70, 0.78); }
.sheet-frame .hl-tx { color: inherit; }

.sheet-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-xs);
  color: var(--ink-2);             /* on the desk, --ink-3 is below 4.5:1 */
}
.sheet-fill {
  display: inline-block;
  inline-size: 64px;
  block-size: 6px;
  border-radius: 3px;
  background: var(--line-strong);
  overflow: hidden;
}
.sheet-fill-bar { display: block; block-size: 100%; background: var(--teal-text); border-radius: 3px; }

/* the calm one-page suggestion + the overflow note above the sheet */
.desk-suggest-slot:empty { display: none; }
.desk-suggest {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-inline-size: min(560px, calc(100% - 32px));
  margin: 18px auto 0;
  padding-block: 12px;
  padding-inline: 16px 8px;
  background: var(--paper);
  border: 1px solid color-mix(in srgb, var(--amber) 55%, var(--line));
  border-radius: var(--r-md);
  box-shadow: var(--shadow-tab);
}
.desk-suggest-text { flex: 1; min-width: 0; display: grid; gap: 6px; justify-items: start; }
.desk-suggest-text strong { font-size: var(--fs-md); font-weight: 600; }
.desk-suggest-text p { font-size: var(--fs-sm); color: var(--ink-2); }
.desk-suggest-text .btn { margin-block-start: 4px; }
.desk-note {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-inline-size: min(560px, calc(100% - 32px));
  margin: 14px auto 0;
  padding: 8px 12px;
  border: 1.5px dashed var(--warn);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-sm);
}
.desk-note svg { width: 18px; height: 18px; }

/* zoom + page tools under the sheet */
.desk-tools {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  padding: 8px 12px;
  border-block-start: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, var(--desk));
}
.desk-seg button { min-height: 30px; }
.desk-seg svg { width: 16px; height: 16px; }
.desk-zoom-now { min-width: 42px; text-align: center; font-size: var(--fs-xs); color: var(--ink-3); }
.desk-sep { inline-size: 1px; block-size: 22px; background: var(--line-strong); margin-inline: 6px; }
.desk-count { font-size: var(--fs-sm); color: var(--ink-2); padding-inline: 4px; }
.desk-fit { margin-inline-start: 4px; }

/* the offscreen render host (canvas.js / design.js measure pages in it) */
.cv-offscreen {
  position: fixed;
  inset-block-start: 0;
  inset-inline-start: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
  contain: layout style;
}

/* =========================================================================
 * Editor (Content tab)
 * ======================================================================= */
.ed { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 12px; }
/* "the assistant is writing" note over the Content and Design tabs */
.ed-lock,
.ds-lock {
  position: sticky;
  inset-block-start: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1.5px dashed var(--violet);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--violet-soft) 88%, var(--paper));
  color: var(--violet);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.ed-lock svg,
.ds-lock svg { flex: none; width: 18px; height: 18px; }
.ed[disabled] .ed-card { opacity: 0.86; }

.ed-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ed-card {
  position: relative;
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 1px 0 var(--line);
  transition: box-shadow var(--t-med) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.ed-list > .ed-card { transition: transform var(--t-med) var(--ease-out), box-shadow var(--t-med) var(--ease-out); }
.ed-card.is-dragging { z-index: 5; transition: none; box-shadow: var(--shadow-pop); cursor: grabbing; }
.ed-card.is-ai { border-color: color-mix(in srgb, var(--violet) 42%, var(--line)); }
.ed-card.is-target,
.ed-item.is-target { box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 32%, transparent); }

.ed-card-head { display: flex; align-items: center; gap: 2px; min-height: 52px; padding: 4px; }
.ed-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink);
  text-align: start;
}
.ed-toggle:hover { background: var(--paper-2); }
.ed-toggle > svg:first-child:not(.ed-chev) { color: var(--ink-3); }
.ed-title-wrap { flex: 1; min-width: 0; display: grid; }
.ed-title {
  justify-self: start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-md);
  font-weight: 600;
}
.ed-sub { font-size: var(--fs-xs); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-chev { width: 18px; height: 18px; color: var(--ink-3); transition: transform var(--t-med) var(--ease-out); }
[aria-expanded="true"] > .ed-chev { transform: rotate(180deg); }
.ed-handle {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 30px;
  min-height: 44px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink-3);
  cursor: grab;
  touch-action: none;
}
.ed-handle:hover { background: var(--paper-2); color: var(--ink); }
.ed-handle svg { width: 18px; height: 18px; }
.ed-card.is-hidden .ed-title-wrap { opacity: 0.55; }
.ed-hidden-stamp { flex: none; }
.ed-rename { flex: 1; min-width: 0; font-weight: 600; }

.ed-card-body {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 6px 14px 16px;
  border-block-start: 1px dashed var(--rule);
}
.ed-card-body > .ed-ai { margin-block-start: 6px; }
.ed-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.ed-with-ai { display: flex; align-items: flex-start; gap: 6px; }
.ed-with-ai > .input,
.ed-with-ai > .textarea { flex: 1; min-width: 0; }
.ed-ai-btn { color: var(--violet); }
.btn-sm.ed-ai-btn { border-color: color-mix(in srgb, var(--violet) 38%, transparent); }
.btn-sm.ed-ai-btn:hover { background: var(--violet-soft); }
.ed-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ed-counter.is-warn { color: var(--warn); }
.ed-empty { color: var(--ink-3); }
.ed-add-row { justify-self: start; }
.ed-add-section { justify-self: stretch; border-style: dashed; min-height: 48px; }

/* AI note: the section was written by the assistant; review it */
.ed-ai {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--highlight-soft);
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.ed-ai-text { flex: 1 1 160px; }

/* auto-growing textareas (editor.js falls back to measuring without field-sizing) */
.textarea.ed-grow { resize: none; overflow: hidden; min-height: 42px; }
@supports (field-sizing: content) {
  .textarea.ed-grow { field-sizing: content; }
}
.textarea.ed-grow[rows="5"] { min-height: 128px; }

/* rows (links, list items) */
.ed-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ed-row { display: flex; align-items: center; gap: 4px; }
.ed-row > .input { flex: 1; min-width: 0; }

/* optional personal details */
.ed-optional { border-block-start: 1px dashed var(--rule); padding-block-start: 6px; }
.ed-optional > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
  border-radius: var(--r-sm);
}
.ed-optional-body { display: grid; gap: 10px; padding-block-start: 6px; }

/* entries: items are index cards with the margin rule on their inline-start edge */
.ed-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ed-item {
  position: relative;
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
/* the notebook margin rule: a thin red line inset from the inline-start edge */
.ed-item::before, .ed-group::before {
  content: "";
  position: absolute;
  inset-block: 8px;
  inset-inline-start: 5px;
  width: 1.5px;
  background: var(--margin);
  opacity: 0.45;
  pointer-events: none;
}
.ed-item-head { display: flex; align-items: center; gap: 2px; padding: 2px; padding-inline-start: 12px; }
.ed-item-toggle .ed-title-wrap { display: flex; align-items: baseline; gap: 10px; }
.ed-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ed-item-date { flex: none; font-size: var(--fs-xs); color: var(--ink-3); }
.ed-item-body { display: grid; gap: 12px; min-width: 0; padding: 4px 12px 12px; padding-inline-start: 18px; }

/* the smart date builder */
.ed-date {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 6px 10px 10px;
  border: 1px dashed var(--rule);
  border-radius: var(--r-sm);
}
.ed-date > legend { padding-inline: 4px; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.ed-date-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.ed-date-label { min-width: 44px; font-size: var(--fs-sm); color: var(--ink-3); }
.ed-month { flex: 1 1 120px; width: auto; min-width: 0; }
.ed-year { flex: 1 1 96px; width: auto; min-width: 0; max-width: 130px; }
.ed-present { align-items: center; min-height: 40px; }
.ed-present input { margin: 0; }
.ed-date-shows { font-size: var(--fs-xs); }
.ed-date-out { color: var(--ink); font-weight: 500; font-size: var(--fs-sm); }
.ed-link {
  justify-self: start;
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: var(--fs-sm);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

/* bullets */
.ed-bullets-wrap { display: grid; gap: 8px; }
.ed-bullets { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ed-bullet-row { position: relative; display: flex; align-items: flex-start; gap: 2px; padding-inline-start: 14px; }
.ed-bullet-row::before {
  content: "";
  position: absolute;
  inset-inline-start: 2px;
  inset-block-start: 19px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
}
.ed-bullet-row > .textarea { flex: 1; min-width: 0; }

/* the ✦ improve tray: three options inline under the field */
.ed-tray {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1.5px dashed var(--violet);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--violet-soft) 70%, var(--paper));
}
.ed-tray-status { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); }
.ed-tray-status svg { width: 18px; height: 18px; color: var(--violet); }
.ed-tray-status.is-bad,
.ed-tray-status.is-bad svg { color: var(--bad); }
.ed-sk { height: 44px; }
.ed-sk.short { width: 62%; }
.ed-opts { display: grid; gap: 6px; }
.ed-opt {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.55;
  text-align: start;
  transition: border-color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
.ed-opt:hover { border-color: var(--violet); background: var(--paper-2); }
.ed-tray-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.ed-suggest-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* skills */
.ed-groups { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ed-group {
  display: grid;
  gap: 10px;
  min-width: 0;
  position: relative;
  padding: 10px 10px 10px 10px;
  padding-inline-start: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
}
.ed-group-head { display: flex; align-items: center; gap: 4px; }
.ed-group-head > .input { flex: 1; min-width: 0; }
.ed-group-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ed-cols { display: inline-flex; align-items: center; gap: 8px; }
.ed-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--paper);
  cursor: text;
  transition: border-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
}
.ed-chips:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.ed-chip-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.ed-chip-list .chip { color: var(--ink); }
.ed-chip-list .chip .x { position: relative; }
.ed-chip-list .chip .x::after { content: ""; position: absolute; inset: -8px; } /* a larger tap area */
.ed-chip-input {
  flex: 1 1 120px;
  min-width: 100px;
  min-height: 32px;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-md);
}
.ed-chip-input:focus { outline: none; } /* the box shows focus (:focus-within) */

/* =========================================================================
 * Design tab
 * ======================================================================= */
.ds { display: grid; gap: 22px; }
.ds-section { display: grid; gap: 10px; min-width: 0; }
.ds-h { font-size: var(--fs-md); font-weight: 600; }

/* templates with live thumbnails */
.ds-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.ds-template {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper);
  color: var(--ink);
  text-align: start;
  transition: border-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
}
.ds-template:hover { border-color: var(--line-strong); }
.ds-template[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.ds-thumb {
  position: relative;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  direction: ltr;
  background: #fff;                 /* sheet paper */
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--line), var(--shadow-tab);
}
.ds-thumb-scale { inline-size: 210mm; block-size: 297mm; transform: scale(var(--tz, 0.2)); transform-origin: 0 0; pointer-events: none; }
.ds-thumb-sk { position: absolute; inset: 0; border-radius: 3px; }
.ds-thumb.is-ready .ds-thumb-sk { display: none; }
.ds-template-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: var(--fs-sm); font-weight: 600; }
.ds-ats-stamp { font-size: 10.5px; padding: 0 6px; }
.ds-template-note { font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.45; }
.ds-ats { display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); }
.ds-ats svg { width: 18px; height: 18px; color: var(--ok); margin-block-start: 2px; }

/* colour */
.ds-colors { border: 0; margin: 0; padding: 0; min-width: 0; }
.ds-colors.is-off { opacity: 0.45; }
.ds-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.ds-swatch { position: relative; display: inline-grid; cursor: pointer; }
.ds-sw-input,
.ds-custom-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.ds-sw {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--line-strong);
  color: white;                     /* a check mark on the CV colour itself */
  transition: box-shadow var(--t-fast) var(--ease-out);
}
.ds-sw svg { width: 18px; height: 18px; opacity: 0; }
.ds-sw-input:checked + .ds-sw { box-shadow: 0 0 0 2px var(--ink); }
.ds-sw-input:checked + .ds-sw svg { opacity: 1; }
.ds-sw-input:focus-visible + .ds-sw,
.ds-custom-input:focus-visible + .ds-sw { outline: 2px solid var(--focus); outline-offset: 3px; }
.ds-sw-custom { background: var(--paper-2); color: var(--ink-2); }
.ds-sw-custom svg { opacity: 1; }
.ds-custom.is-checked .ds-sw { box-shadow: 0 0 0 2px var(--ink); color: white; }
.ds-colors:disabled .ds-swatch { cursor: not-allowed; }
.ds-off { max-width: 48ch; }

/* fonts: each label is drawn in its own font */
.ds-fonts { display: grid; gap: 6px; }
.ds-font {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
  cursor: pointer;
}
.ds-font input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.ds-font:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.ds-font-text { display: grid; min-width: 0; }
.ds-font-name { font-size: var(--fs-sm); color: var(--ink-2); }
.ds-font-sample { font-size: var(--fs-lg); line-height: 1.4; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* size */
.ds-size { display: flex; align-items: center; gap: 12px; }
.ds-size .range { flex: 1; min-height: 40px; }
.ds-size-out { min-width: 48px; text-align: end; font-weight: 600; }
.ds-fit-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ds-fit-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1.5px dashed var(--warn);
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}
.ds-fit-note > svg { width: 18px; height: 18px; color: var(--warn); }

/* photo */
.ds-photo-toggle { align-items: center; min-height: 40px; font-size: var(--fs-md); color: var(--ink); }
.ds-photo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.ds-photo-preview img,
.ds-photo-empty {
  width: 72px;
  height: 72px;
  border-radius: var(--r-sm);
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--line-strong);
}
.ds-photo-empty { display: grid; place-items: center; background: var(--paper-2); color: var(--ink-3); }
.ds-photo-empty svg { width: 28px; height: 28px; }
.ds-photo-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* every control waits while an AI turn runs (design.js paintLock; .ds-lock explains why) */
.ds-template:disabled,
.ds-font:has(input:disabled),
.ds-photo-toggle:has(input:disabled),
.ds-size .range:disabled { opacity: 0.6; cursor: not-allowed; }
.ds-template:disabled:hover { border-color: var(--line); }
.ds-template[aria-pressed="true"]:disabled:hover { border-color: var(--primary); }
.ds-colors:disabled:not(.is-off) { opacity: 0.6; }

/* =========================================================================
 * ATS tab
 * ======================================================================= */
.ats { display: grid; gap: 16px; }
.ats-head { display: grid; gap: 8px; justify-items: start; }
.ats-score .stamp { font-size: var(--fs-sm); padding: 3px 10px; }
.ats-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.ats-item {
  display: grid;
  justify-items: start;
  gap: 6px;
  padding: 12px 14px;
  border-block-end: 1px dashed var(--rule);
}
.ats-item:last-child { border-block-end: 0; }
.ats-item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; inline-size: 100%; }
.ats-item-title { font-size: var(--fs-md); font-weight: 600; }
.ats-stamp { flex: none; }
.ats-item-text { font-size: var(--fs-sm); color: var(--ink-2); }
.ats-fix { margin-block-start: 2px; }
.ats-plain {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.ats-plain > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
}
.ats-plain > summary svg { width: 18px; height: 18px; color: var(--ink-3); }
.ats-plain-body { display: grid; gap: 10px; padding: 0 14px 14px; }
.ats-plain-text {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  border-radius: var(--r-sm);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;         /* each line takes its own direction */
}
.ats-plain-foot { display: flex; justify-content: flex-end; }

/* =========================================================================
 * Export dialog
 * ======================================================================= */
.ex { display: grid; gap: 14px; min-height: 120px; }
.ex-loading { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: var(--fs-sm); }
.ex-sk { height: 52px; }
.ex-sk.short { width: 60%; height: 40px; }
.ex-error { display: flex; align-items: flex-start; gap: 8px; color: var(--bad); font-size: var(--fs-sm); }
.ex-error svg { width: 18px; height: 18px; margin-block-start: 2px; }
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ex-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border: 1.5px dashed var(--warn);
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}
.ex-notice > svg { width: 18px; height: 18px; color: var(--warn); margin-block-start: 2px; }
.ex-notice.is-ok { border: 0; background: none; padding: 0; }

.ex-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line));
  border-radius: var(--r-md);
  background: var(--paper-2);
}
.ex-card-title { font-size: var(--fs-lg); }
.ex-lead { color: var(--ink-2); font-size: var(--fs-sm); }
.ex-price { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; margin-block: 4px 2px; }
.ex-amount { font-size: var(--fs-2xl); font-weight: 700; color: var(--ink); }
.ex-old { font-size: var(--fs-md); color: var(--ink-3); text-decoration-thickness: 1.5px; }
.ex-sub { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); margin-block-end: 6px; }
.ex-incl { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ex-incl li { display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-sm); }
.ex-incl svg { width: 18px; height: 18px; color: var(--ok); flex: none; margin-block-start: 1px; }
.ex-pay-actions { display: grid; gap: 8px; }
.ex-pay-actions .hint { text-align: center; }
.ex-coupon { display: grid; gap: 6px; }
.ex-coupon > label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.ex-coupon-row { display: flex; gap: 8px; }
.ex-code-input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.04em; }

.ex-paid { display: grid; gap: 14px; }
.ex-file { display: flex; align-items: stretch; }
.ex-file-input { flex: 1; min-width: 0; border-start-end-radius: 0; border-end-end-radius: 0; }
.ex-ext {
  display: inline-flex;
  align-items: center;
  padding-inline: 12px;
  border: 1px solid var(--line-strong);
  border-inline-start: 0;
  border-start-end-radius: var(--r-sm);
  border-end-end-radius: var(--r-sm);
  background: var(--paper-2);
  color: var(--ink-3);
  font-size: var(--fs-sm);
}
.ex-meta { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); }
.ex-meta svg { width: 18px; height: 18px; color: var(--ink-3); }
.ex-result { display: grid; gap: 10px; }
.ex-result:empty { display: none; }
.ex-done { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--ink-2); }
.ex-stamp { font-size: var(--fs-sm); padding: 3px 10px; }
.ex-link-row { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: var(--fs-sm); }
.ex-link-row svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.ex-link { overflow-wrap: anywhere; }

/* =========================================================================
 * Responsive
 * ======================================================================= */
@media (pointer: coarse) {
  .desk-seg button,
  .desk-tools .btn-sm,
  .seg button { min-height: 40px; }
  .desk-tools .btn-icon.btn-sm { width: 40px; }
}

@media (max-width: 899.98px) {
  .st-top .st-save-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* tablet: the panel becomes a drawer over the desk */
@media (min-width: 760px) and (max-width: 1099.98px) {
  .st-body { grid-template-columns: 64px minmax(0, 1fr); }
  .st-desk { grid-column: 2; }
  .st-panel {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 64px;
    z-index: 8;
    inline-size: min(400px, calc(100% - 64px - 40px));
    box-shadow: var(--shadow-pop);
    animation: st-drawer var(--t-med) var(--ease-out);
  }
  .st:not(.is-drawer) .st-panel { display: none; }
  .st-panel-close { display: inline-flex; }
}
@keyframes st-drawer { from { opacity: 0.4; } }

/* phone: one surface at a time + the bottom tab bar */
@media (max-width: 759.98px) {
  .st-body { grid-template-columns: minmax(0, 1fr); }
  .st-rail { display: none; }
  .st-panel, .st-desk { grid-column: 1; }
  .st-panel { border-inline: 0; }
  .st.is-sheet .st-panel { display: none; }
  .st:not(.is-sheet) .st-desk { display: none; }
  .st-tabbar { display: block; }
  .st-tabpanel { padding: 14px 12px 40px; }
  .st-tabpanel.st-pane-chat { padding: 0; }      /* the chat runs edge to edge down to the tab bar */
  .st-top .st-undo,
  .st-top .st-redo { display: none; }             /* folded into the "more" menu */
  .desk-stage { padding: 16px 12px 28px; gap: 20px; }
  .desk-seg .z-extra,
  .desk-zoom-now,
  .desk-sep { display: none; }
  body.in-studio .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); }
  .ed-card-body { padding: 6px 10px 14px; }
  .ed-item-body { padding: 4px 8px 10px; }
}
/* phone: while typing, the keyboard needs the room the tab bar takes */
@supports selector(:has(*)) {
  @media (max-width: 759.98px) {
    .st:has(.st-panel :is(textarea, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"])):focus) .st-tabbar { display: none; }
  }
}

@media (max-width: 559.98px) {
  .st-top .tb-user { display: none; } /* its items fold into the studio's more menu */
  .st-top .st-export { width: auto; padding: 0 12px; } /* keep a visible 'PDF' so the paid action never reads as a free download */
  .st-top .st-export-short { display: inline; font-weight: 600; }
  .st-top .st-export-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .st-top .tb-actions { gap: 2px; }
  .st-title { gap: 6px; }
  .st-name { min-width: 48px; padding-inline: 6px; }
}
@media (max-width: 479.98px) {
  .st-top .brand { display: none; }
  .st-top .tb-title { border-inline-start: 0; padding-inline-start: 0; }
}

/* iOS Safari / in-app WebViews zoom into fields under 16px on focus */
@media (pointer: coarse) {
  .st-name, .ed-chip-input { font-size: max(16px, var(--fs-md)); }
}
