/* ==========================================================================
   App shell — chrome around the CV. Nothing here affects the CV itself
   (that lives in cv.css) so the printed page is never polluted by app styles.
   ========================================================================== */

:root{
  --bg:            #eef1f5;
  --bg-2:          #e5e9ef;
  --panel:         #ffffff;
  --panel-2:       #eef2f6;
  --line:          #d8dee6;
  --line-soft:     #e4e8ee;
  --txt:           #1a2230;
  --txt-dim:       #5b6675;
  --txt-faint:     #93a0b0;
  --accent:        #2f6fe0;
  --accent-ink:    #ffffff;
  --danger:        #d64550;
  --ok:            #16a34a;
  --radius:        10px;
  --radius-sm:     7px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0; font-family:var(--font); background:var(--bg); color:var(--txt);
  -webkit-font-smoothing:antialiased; overflow:hidden;
}

/* ------------------------------- Buttons -------------------------------- */
.btn{
  font:inherit; font-size:13px; font-weight:600; line-height:1;
  padding:9px 14px; border-radius:var(--radius-sm); border:1px solid transparent;
  background:transparent; color:var(--txt); cursor:pointer; white-space:nowrap;
  transition:background .13s, border-color .13s, color .13s, transform .06s;
}
.btn:active{ transform:translateY(1px); }
.btn-primary{ background:var(--accent); color:var(--accent-ink); }
.btn-primary:hover{ background:#255cc0; }
.btn-ghost{ border-color:var(--line); color:var(--txt-dim); }
.btn-ghost:hover{ border-color:#b7c1cd; color:var(--txt); background:var(--panel-2); }
.btn-soft{ background:var(--panel-2); border-color:var(--line); }
.btn-soft:hover{ background:#e0e6ee; }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-danger:hover{ background:#b3323c; }
.btn-block{ display:block; width:100%; padding:11px; }
.btn-sm{ padding:7px 10px; font-size:12px; }
.btn-file{ display:inline-block; text-align:center; }

/* Signed-in identity in the top bar, shared by the app and the admin panel. */
.who{ font-size:12.5px; color:var(--txt-dim); white-space:nowrap; }
.who b{ color:var(--txt); font-weight:700; }

.icon-btn{
  width:26px; height:26px; display:grid; place-items:center; flex:none;
  border:1px solid var(--line); background:var(--panel-2); color:var(--txt-dim);
  border-radius:6px; cursor:pointer; font-size:13px; line-height:1; padding:0;
}
.icon-btn:hover{ color:var(--txt); border-color:#b7c1cd; }
.icon-btn.danger:hover{ color:var(--danger); border-color:#f0b8bd; background:#fbe9ea; }

/* ----------------------------- Password gate ---------------------------- */
.gate{
  position:fixed; inset:0; z-index:100; display:grid; place-items:center; padding:24px;
  background:radial-gradient(1000px 600px at 50% -10%, #dbe6f7 0%, var(--bg) 62%);
}
.gate[hidden]{ display:none; }
.gate-card{
  width:100%; max-width:340px; background:var(--panel); border:1px solid var(--line);
  border-radius:14px; padding:30px 26px; text-align:center;
  box-shadow:0 24px 60px rgba(0,0,0,.5);
}
.gate-mark{ width:44px; height:44px; margin:0 auto 16px; display:grid; place-items:center; }
.gate-mark img{ width:100%; height:100%; object-fit:contain; }

/* The full icon+wordmark lockup, used in place of .gate-mark + <h1> on the
   main sign-in card (login.php) — the logo already carries the site name, so
   a separate text heading next to it would just repeat it. */
.gate-logo{ display:block; width:100%; max-width:200px; height:auto; margin:0 auto 14px; }

.gate-card h1{ margin:0 0 6px; font-size:19px; font-weight:700; letter-spacing:-.2px; }
.gate-sub{ margin:0 0 20px; font-size:13px; color:var(--txt-dim); }
.gate-card input{
  width:100%; padding:11px 13px; font:inherit; font-size:14px; text-align:center;
  background:var(--bg-2); border:1px solid var(--line); border-radius:var(--radius-sm);
  color:var(--txt); margin-bottom:12px; letter-spacing:2px;
}
.gate-card input:focus{ outline:none; border-color:var(--accent); }

.gate-divider{
  display:flex; align-items:center; gap:10px; margin:18px 0 14px;
  font-size:11px; font-weight:700; letter-spacing:.5px; text-transform:uppercase; color:var(--txt-faint);
}
.gate-divider::before, .gate-divider::after{ content:""; flex:1; height:1px; background:var(--line); }
.gate-guest-note{ margin:9px 0 0; font-size:11.5px; color:var(--txt-faint); line-height:1.4; }
.gate-err{ margin:0 0 12px; font-size:12.5px; color:var(--danger); }

/* Shop contact, under a hairline at the foot of the sign-in card. */
.gate-contact{ margin-top:20px; padding-top:16px; border-top:1px solid var(--line); }
.gate-contact-lbl{
  display:block; margin-bottom:9px; font-size:11px; font-weight:700;
  letter-spacing:.5px; text-transform:uppercase; color:var(--txt-faint);
}
.gate-contact-row{ display:flex; gap:8px; }
.gate-contact-btn{
  flex:1; display:inline-flex; align-items:center; justify-content:center; gap:6px;
  text-decoration:none;
}
.gate-contact-btn.is-wa:hover{ border-color:#25d366; color:#128c4a; background:rgba(37,211,102,.08); }
.gate-contact-num{
  display:block; margin-top:9px; font-size:12px; color:var(--txt-dim); letter-spacing:.3px;
}

/* Software credit at the very foot of the card — deliberately no border above
   it, so it reads as a quiet footnote rather than another section on par with
   "Need help?" above it. */
.gate-powered{
  display:flex; align-items:center; justify-content:center; gap:6px;
  margin-top:14px; font-size:11px; color:var(--txt-faint);
}
.gate-powered-logo{ width:16px; height:16px; border-radius:50%; flex:none; }
.gate-powered b{ color:var(--txt-dim); font-weight:700; }

.gate.shake .gate-card{ animation:shake .32s; }
@keyframes shake{ 0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)} 40%{transform:translateX(7px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }

/* --------------------------------- App ---------------------------------- */
.app{ height:100%; display:flex; flex-direction:column; }
.app[hidden]{ display:none; }

.topbar{
  flex:none; height:54px; display:flex; align-items:center; gap:16px;
  padding:0 14px; background:var(--panel); border-bottom:1px solid var(--line);
}
.brand{ display:flex; align-items:center; gap:9px; font-weight:700; font-size:14.5px; letter-spacing:-.2px; }
.brand-mark{ width:26px; height:26px; display:grid; place-items:center; flex:none; }
.brand-mark img{ width:100%; height:100%; object-fit:contain; }
.topbar-actions{ margin-left:auto; display:flex; align-items:center; gap:8px; }

/* CV title + autosave status, shown in the editor's topbar between the
   "back to dashboard" link and the toolbar buttons. */
.cv-meta{ display:flex; align-items:center; gap:10px; min-width:0; flex:1 1 auto; }
.cv-title-input{
  font:inherit; font-size:14px; font-weight:600; color:var(--txt);
  background:transparent; border:1px solid transparent; border-radius:var(--radius-sm);
  padding:6px 9px; min-width:0; flex:0 1 200px; max-width:40vw;
}
.cv-title-input:hover{ border-color:var(--line); }
.cv-title-input:focus{ outline:none; border-color:var(--accent); background:var(--panel-2); }
.save-status{ font-size:11.5px; color:var(--txt-faint); white-space:nowrap; flex:none; }
.save-status.is-saving{ color:var(--txt-dim); }
.save-status.is-err{ color:var(--danger); font-weight:600; }

/* Guest mode's stand-in for the title/save-status pair — same slot, same
   sizing, but a single fixed notice instead of an editable field. */
.guest-badge{
  font-size:11.5px; font-weight:600; color:#9a6b00; white-space:nowrap;
  background:rgba(217,155,0,.12); border:1px solid rgba(217,155,0,.28);
  border-radius:20px; padding:5px 12px;
}

.seg{ display:none; background:var(--bg-2); border:1px solid var(--line); border-radius:var(--radius-sm); padding:2px; }
.seg-btn{
  font:inherit; font-size:12.5px; font-weight:600; padding:6px 13px; border:0;
  background:transparent; color:var(--txt-dim); border-radius:5px; cursor:pointer;
}
.seg-btn.is-active{ background:var(--panel-2); color:var(--txt); }

/* ------------------------------- Split view ------------------------------ */
.split{ flex:1; display:grid; grid-template-columns:minmax(340px, 430px) 1fr; min-height:0; }
.panel{ min-height:0; min-width:0; display:flex; flex-direction:column; }
.panel-form{ background:var(--panel); border-right:1px solid var(--line); }
.panel-preview{ background:var(--bg); }

.form-scroll{ flex:1; overflow-y:auto; overscroll-behavior:contain; padding:14px 14px 40px; }
.form-scroll::-webkit-scrollbar,
.preview-scroll::-webkit-scrollbar{ width:10px; height:10px; }
.form-scroll::-webkit-scrollbar-thumb,
.preview-scroll::-webkit-scrollbar-thumb{ background:#c8d0da; border-radius:6px; border:3px solid transparent; background-clip:content-box; }

/* --------------------------------- Blocks -------------------------------- */
.block{
  background:var(--bg-2); border:1px solid var(--line-soft);
  border-radius:var(--radius); margin-bottom:10px; overflow:hidden;
}
.block-title{
  margin:0; padding:12px 14px; font-size:12px; font-weight:700;
  letter-spacing:.7px; text-transform:uppercase; color:var(--txt-dim);
  cursor:pointer; list-style:none; user-select:none; position:relative;
}
.block-title::-webkit-details-marker{ display:none; }
details > .block-title::after{
  content:""; position:absolute; right:15px; top:50%; width:6px; height:6px;
  border-right:1.6px solid var(--txt-faint); border-bottom:1.6px solid var(--txt-faint);
  transform:translateY(-70%) rotate(45deg); transition:transform .15s;
}
details[open] > .block-title::after{ transform:translateY(-30%) rotate(225deg); }
details[open] > .block-title{ color:var(--txt); }
.block-body{ padding:2px 14px 15px; }

.sub{ padding:12px 0 2px; border-top:1px solid var(--line-soft); margin-top:12px; }
.sub:first-child{ border-top:0; margin-top:0; padding-top:2px; }
.sub-title{ margin:0 0 9px; font-size:12px; font-weight:700; color:var(--txt); }

/* --------------------------------- Fields -------------------------------- */
.field{ display:block; margin-bottom:10px; }
.field > span{ display:block; font-size:11.5px; font-weight:600; color:var(--txt-dim); margin-bottom:5px; }
.field > span i{ font-style:normal; color:var(--txt-faint); font-weight:500; }
.field input, .field select, .field textarea,
.rep input, .rep select, .rep textarea{
  width:100%; font:inherit; font-size:13px; color:var(--txt);
  background:var(--panel); border:1px solid var(--line); border-radius:var(--radius-sm);
  padding:8px 10px; transition:border-color .12s;
}
.field textarea, .rep textarea{ resize:vertical; line-height:1.45; min-height:34px; }
.field input:focus, .field select:focus, .field textarea:focus,
.rep input:focus, .rep select:focus, .rep textarea:focus{ outline:none; border-color:var(--accent); }
.field select, .rep select{ appearance:none; background-image:linear-gradient(45deg,transparent 50%,var(--txt-faint) 50%),linear-gradient(135deg,var(--txt-faint) 50%,transparent 50%); background-position:calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size:5px 5px; background-repeat:no-repeat; }
.field input[type="date"]{ min-height:35px; }
.grid-2{ display:grid; grid-template-columns:1fr 1fr; gap:0 10px; }
.hint{ margin:7px 0 0; font-size:11.5px; color:var(--txt-faint); line-height:1.4; }

/* ---------------------------- Photo controls ----------------------------- */
.photo-row{ display:flex; gap:13px; align-items:flex-start; margin-bottom:14px; }
.photo-preview{
  width:76px; height:76px; flex:none; border-radius:50%; overflow:hidden;
  background:var(--panel); border:1px dashed var(--line);
  display:grid; place-items:center; font-size:10px; color:var(--txt-faint); text-align:center;
  touch-action:none; /* let pointermove pan the photo instead of scrolling the page */
}
.photo-preview.has-photo{ cursor:grab; border-style:solid; }
.photo-preview.is-dragging{ cursor:grabbing; }
.photo-preview img{ width:100%; height:100%; object-fit:cover; display:block; pointer-events:none; }
.photo-ctl{ flex:1; min-width:0; display:flex; flex-wrap:wrap; gap:7px; }
.photo-ctl .hint{ flex-basis:100%; margin-top:2px; }

.photo-align{ margin:-3px 0 14px; padding:10px 12px; background:var(--panel); border:1px solid var(--line-soft); border-radius:var(--radius-sm); }
.align-row{ display:flex; align-items:center; gap:10px; margin-bottom:11px; }
.align-row:last-of-type{ margin-bottom:9px; }
.align-lbl{ flex:none; width:70px; font-size:11.5px; color:var(--txt-dim); }
/* Fully custom-styled rather than left to the native appearance: relying on
   accent-color + a transparent background rendered inconsistently across
   browsers — sometimes with no fill at all, sometimes with a stray default
   focus-outline box around the whole control — which is what made the bar
   look broken. --val (kept current by js/cards.js and js/form.js on every
   'input') draws the filled portion in Chromium/WebKit; Firefox fills
   ::-moz-range-progress natively from the value, no JS needed there.
   Sized generously (24px tall row, 18px thumb) and spaced further apart
   above — with three of these stacked close together, a mis-click a few
   px off the intended row is exactly what makes one axis "stop working"
   while the other one moves instead. */
.align-row input[type="range"]{
  flex:1; min-width:0; cursor:pointer; margin:0; height:24px;
  -webkit-appearance:none; appearance:none; background:transparent; outline:none;
}
.align-row input[type="range"]::-webkit-slider-runnable-track{
  height:6px; border-radius:3px;
  background:linear-gradient(to right,
    var(--accent) 0%, var(--accent) var(--val, 50%),
    var(--line) var(--val, 50%), var(--line) 100%);
}
.align-row input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none; appearance:none;
  width:18px; height:18px; margin-top:-6px; border-radius:50%;
  background:#fff; border:3px solid var(--accent); box-shadow:0 1px 3px rgba(20,30,50,.25);
}
.align-row input[type="range"]::-moz-range-track{ height:6px; border-radius:3px; background:var(--line); }
.align-row input[type="range"]::-moz-range-progress{ height:6px; border-radius:3px; background:var(--accent); }
.align-row input[type="range"]::-moz-range-thumb{
  width:18px; height:18px; border-radius:50%;
  background:#fff; border:3px solid var(--accent); box-shadow:0 1px 3px rgba(20,30,50,.25);
}
.align-row input[type="range"]:focus-visible::-webkit-slider-thumb{ box-shadow:0 0 0 4px rgba(47,111,224,.28); }
.align-row input[type="range"]:focus-visible::-moz-range-thumb{ box-shadow:0 0 0 4px rgba(47,111,224,.28); }
.align-presets{ display:flex; gap:6px; }
.align-presets button{
  flex:1; font:inherit; font-size:11.5px; font-weight:600; color:var(--txt-dim);
  background:var(--panel-2); border:1px solid var(--line); border-radius:6px;
  padding:6px 4px; cursor:pointer;
}
.align-presets button:hover{ color:var(--txt); border-color:#3a4553; }

/* --------------------------- Repeatable lists ---------------------------- */
.rep-row{ display:flex; gap:7px; align-items:flex-start; margin-bottom:7px; }
.rep-row .idx{
  flex:none; width:20px; padding-top:9px; font-size:11px;
  color:var(--txt-faint); text-align:right; font-variant-numeric:tabular-nums;
}
.rep-row .grow{ flex:1; min-width:0; display:flex; gap:7px; }
.rep-row .grow > *:first-child{ flex:1 1 62%; min-width:0; }
.rep-row .grow > *:nth-child(2){ flex:1 1 38%; min-width:0; }
.rep-row .icon-btn{ margin-top:4px; }

/* Work-experience rows stack role/duration/company/description instead of
   the two-column layout other repeatable rows use. */
.work-grow{ flex:1; min-width:0; display:flex; flex-direction:column; gap:6px; }
.work-line1{ display:flex; gap:7px; }
.work-line1 > *:first-child{ flex:1 1 62%; min-width:0; }
.work-line1 > *:nth-child(2){ flex:1 1 38%; min-width:0; }

/* Social links: a short platform picker beside a (usually longer) URL —
   the reverse ratio of .work-line1's role/duration split. */
.social-line1{ display:flex; gap:7px; }
.social-line1 > *:first-child{ flex:1 1 34%; min-width:0; }
.social-line1 > *:nth-child(2){ flex:1 1 66%; min-width:0; }

.add-btn{
  font:inherit; font-size:12.5px; font-weight:600; color:var(--accent);
  background:transparent; border:1px dashed var(--line); border-radius:var(--radius-sm);
  padding:8px 12px; cursor:pointer; width:100%; margin-top:2px;
}
.add-btn:hover{ border-color:var(--accent); background:rgba(47,111,224,.07); }
.rep-empty{ font-size:12px; color:var(--txt-faint); padding:2px 0 9px; }
.rep-head{ display:flex; gap:7px; padding:0 33px 5px 27px; font-size:10.5px; font-weight:700; letter-spacing:.5px; text-transform:uppercase; color:var(--txt-faint); }
.rep-head span:first-child{ flex:1 1 62%; }
.rep-head span:nth-child(2){ flex:1 1 38%; }

.save-note{ font-size:11.5px; color:var(--txt-faint); text-align:center; margin:16px 0 0; }

/* Finish/Preview at the foot of the form, and the matching Edit button at the
   top of the preview panel (.preview-edit-btn, in the preview-bar rules
   below) — mobile only (shown in the @media block below). Both land you on
   the rendered CV a tap away without hunting for the topbar's own Edit/
   Preview toggle. */
.form-end{ display:none; gap:10px; margin-top:18px; }
.form-end .btn{ flex:1; padding:12px; font-size:14px; }

/* ------------------------------- Template picker ------------------------- */
.tpl-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:9px; padding:0 14px 15px; }
.tpl-card{
  padding:0; background:var(--panel); border:1.5px solid var(--line);
  border-radius:9px; cursor:pointer; overflow:hidden; text-align:left;
  transition:border-color .13s, transform .08s;
}
.tpl-card:hover{ border-color:#aab6c4; }
.tpl-card.is-active{ border-color:var(--accent); box-shadow:0 0 0 3px rgba(47,111,224,.16); }
.tpl-meta{ display:block; padding:7px 8px 8px; border-top:1px solid var(--line-soft); }
.tpl-meta b{ display:block; font-size:11.5px; color:var(--txt); }
.tpl-meta i{ display:block; font-style:normal; font-size:10px; color:var(--txt-faint); margin-top:2px; line-height:1.3; }

.accent-row{ display:flex; align-items:center; gap:9px; padding:12px 14px 2px; }
.accent-swatch{ flex:none; width:30px; height:30px; border-radius:8px; border:1.5px solid var(--line); overflow:hidden; cursor:pointer; padding:0; }
.accent-swatch input[type="color"]{
  width:calc(100% + 8px); height:calc(100% + 8px); margin:-4px; border:0; padding:0; cursor:pointer;
}
.accent-lbl{ flex:1; font-size:12px; color:var(--txt-dim); }
.accent-row .btn{ flex:none; }

/* Real miniature renders of a sample CV, one per template — built by
   js/form.js renderTemplateThumbnails() using the actual CVRender output
   (css/cv.css), not an abstract mock-up. .thumb-live-inner is rendered at
   full size and shrunk with a JS-computed transform:scale, the same way
   shrinking a full-size printed page down to a thumbnail works — nothing
   here needs to know it's small. pointer-events:none so the thumbnail is
   inert; the surrounding .tpl-card button is what's actually clickable. */
.thumb{ display:block; position:relative; height:88px; background:#fff; overflow:hidden; }
.thumb-live-inner{ position:absolute; top:0; left:0; transform-origin:top left; pointer-events:none; }

/* ------------------------------ Preview pane ----------------------------- */
.preview-bar{
  flex:none; height:40px; display:flex; align-items:center; gap:10px;
  padding:0 14px; border-bottom:1px solid var(--line-soft); background:var(--bg-2);
}
.pv-label{ font-size:11.5px; font-weight:600; letter-spacing:.5px; text-transform:uppercase; color:var(--txt-faint); }
/* Mobile only — see .form-end above and the @media block below. */
.preview-edit-btn{ display:none; flex:none; }
/* Shown by js/cards.js flagOverflow() when the sheet's content no longer
   fits the chosen paper. */
.pv-warn{
  margin-left:10px; padding:3px 9px; border-radius:20px; white-space:nowrap;
  font-size:11px; font-weight:700;
  background:rgba(214,69,80,.12); color:#b3323c; border:1px solid rgba(214,69,80,.30);
}
.pv-warn[hidden]{ display:none; }
.spacer{ flex:1; }
.fit-badge{
  font-size:11px; font-weight:600; padding:3px 8px; border-radius:20px;
  background:rgba(22,163,74,.12); color:var(--ok); border:1px solid rgba(22,163,74,.25);
}
.fit-badge.warn{ background:rgba(214,69,80,.12); color:var(--danger); border-color:rgba(214,69,80,.28); }
.zoom{ display:flex; align-items:center; gap:4px; }
.zoom-val{
  font:inherit; font-size:11.5px; font-weight:600; color:var(--txt-dim); min-width:44px;
  background:transparent; border:0; cursor:pointer; padding:0 2px;
}
.zoom-val:hover{ color:var(--txt); }

.preview-scroll{ flex:1; overflow:auto; padding:22px; display:flex; justify-content:center; }
.preview-scroll.is-panning{ cursor:grabbing; user-select:none; }
.stage-wrap{ position:relative; flex:none; }
.stage{ position:absolute; top:0; left:0; transform-origin:top left; }

/* --------------------------------- Mobile -------------------------------- */
@media (max-width: 900px){
  .split{ grid-template-columns:1fr; }
  .panel-form{ border-right:0; }
  .seg{ display:flex; }
  .topbar{ height:auto; flex-wrap:wrap; padding:8px 10px; gap:8px; }
  .topbar-actions{ width:100%; margin-left:0; flex-wrap:wrap; }
  .cv-meta{ flex:1; min-width:0; }
  .cv-title-input{ width:100%; max-width:none; }
  .app.view-preview .panel-form{ display:none; }
  .app.view-edit   .panel-preview{ display:none; }
  .preview-scroll{ padding:12px; }
  .tpl-grid{ gap:7px; }
  .form-end{ display:flex; }
  .preview-edit-btn{ display:inline-flex; }
}

/* --------------------------------- Print --------------------------------- */
#print-root{ display:none; }
@media print{
  html,body{ background:#fff !important; height:auto; overflow:visible; }
  body > *:not(#print-root){ display:none !important; }
  #print-root{ display:block !important; }
}
