/* ─────────────────────────────── tokens ─────────────────────────────── */
:root {
  --bg:        #0e0f12;
  --bg-panel:  #15171b;
  --bg-sunken: #101216;
  --bg-input:  #1b1e24;
  --bg-hover:  #22262e;

  --line:       #262a33;
  --line-soft:  #1e222a;
  --line-strong:#343a45;

  --ink:      #e9ecf1;
  --ink-mid:  #a3abb8;
  --ink-dim:  #6d7684;

  --accent:      #e4573d;
  --accent-soft: rgba(228, 87, 61, 0.14);
  --accent-line: rgba(228, 87, 61, 0.42);

  --ok:   #3fb27f;
  --warn: #d9a03a;
  --bad:  #e05252;

  --radius:    10px;
  --radius-sm: 7px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.is-hidden { display: none !important; }

/* Several toggled elements carry `display: flex/grid`, which would otherwise
   beat the UA rule behind the `hidden` attribute. */
[hidden] { display: none !important; }

/* ─────────────────────────────── topbar ─────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand__mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  flex: 0 0 auto;
}

.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__text strong { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.brand__text small {
  font-size: 11.5px; color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar__actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ────────────────────────────── workspace ───────────────────────────── */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  min-height: 0;
}

.panel { min-height: 0; min-width: 0; }

.panel--controls {
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 4px 18px 28px;
  margin: 0;
}

.panel--preview {
  display: flex;
  flex-direction: column;
  background: var(--bg-sunken);
  min-height: 0;
}

/* ─────────────────────────────── groups ─────────────────────────────── */
.group {
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  margin: 0;
  padding: 20px 0;
}
.group:last-of-type { border-bottom: 0; }

.group__title {
  display: flex; align-items: center; gap: 9px;
  padding: 0 0 14px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-mid);
}

.group__step {
  display: grid; place-items: center;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  color: var(--ink-mid);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0;
}

/* ─────────────────────────────── fields ─────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field:last-child { margin-bottom: 0; }

.field__label {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-mid);
}

.field__value { font-variant-numeric: tabular-nums; color: var(--ink); font-size: 12px; }
.field__hint, .hint { font-size: 11.5px; line-height: 1.45; color: var(--ink-dim); margin: 0; }
.hint code {
  font-family: var(--mono); font-size: 10.5px;
  background: var(--bg-input); border: 1px solid var(--line);
  padding: 0.5px 4px; border-radius: 4px; color: var(--ink-mid);
}
.hint--meta { margin-top: 10px; font-variant-numeric: tabular-nums; }

.row { display: grid; gap: 10px; margin-bottom: 14px; }
.row--2 { grid-template-columns: 1fr 1fr; }
.row--3 { grid-template-columns: repeat(3, 1fr); }
.row--5 { grid-template-columns: repeat(5, 1fr); }
.row .field { margin-bottom: 0; }

/* Two selects fit legibly at this panel width; the quality slider takes its
   own full-width row when JPEG is chosen. */
#rasterOptions { grid-template-columns: 1fr 1fr; }
#jpegQualityField { grid-column: 1 / -1; }

.input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder { color: var(--ink-dim); }
.input:hover { border-color: #414855; }
.input:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select.input {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 8l3-3.5' fill='none' stroke='%236d7684' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
  cursor: pointer;
}
select.input option { background: var(--bg-input); color: var(--ink); }

.code {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 11px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  tab-size: 2;
}
.code::placeholder { color: var(--ink-dim); }
.code:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* range */
.range {
  width: 100%;
  appearance: none;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 3px; background: var(--line-strong);
}
.range::-webkit-slider-thumb {
  appearance: none;
  width: 15px; height: 15px; margin-top: -5.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent-line); }
.range::-moz-range-track { height: 4px; border-radius: 3px; background: var(--line-strong); }
.range::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--bg-panel);
}
.range--sm { width: 96px; height: 18px; }

/* checkboxes */
.checks { display: flex; flex-direction: column; gap: 9px; margin: 4px 0 14px; }
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-size: 13px; color: var(--ink-mid); }
.check input {
  appearance: none;
  flex: 0 0 auto;
  width: 16px; height: 16px; margin: 1px 0 0;
  border: 1px solid var(--line-strong);
  border-radius: 4.5px;
  background: var(--bg-input);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.check input:checked {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2 4.8 8.5 9.5 3.8' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/11px no-repeat;
  border-color: var(--accent);
}
.check input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.check:hover > span { color: var(--ink); }
.check code {
  font-family: var(--mono); font-size: 11px;
  background: var(--bg-input); border: 1px solid var(--line);
  padding: 0.5px 4px; border-radius: 4px;
}
.check__note {
  display: block;
  margin-top: 2px;
  font-size: 11px; font-style: normal; line-height: 1.4;
  color: var(--ink-dim);
}

/* ──────────────────────────────── tabs ──────────────────────────────── */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 12px;
}
.tab {
  border: 0; background: transparent;
  padding: 5px 13px;
  border-radius: 6px;
  color: var(--ink-dim);
  font: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.tab:hover { color: var(--ink-mid); }
.tab.is-active { background: var(--bg-hover); color: var(--ink); }
.tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.tabpanel { display: none; }
.tabpanel.is-active { display: block; }

/* dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 190px;
  padding: 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--ink-dim);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.dropzone:hover, .dropzone.is-over {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--ink-mid);
}
.dropzone__title { font-size: 13px; font-weight: 500; color: var(--ink); }
.dropzone__title code { font-family: var(--mono); font-size: 12px; }
.dropzone__hint { font-size: 11.5px; }

/* ─────────────────────────────── cards ──────────────────────────────── */
.cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.cards--2 { grid-template-columns: 1fr 1fr; margin-bottom: 14px; }

.card { display: block; cursor: pointer; }
.card input { position: absolute; opacity: 0; pointer-events: none; }

.card__body {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "fig name" "fig desc";
  align-items: start;
  column-gap: 12px; row-gap: 3px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  transition: border-color 0.13s, background 0.13s;
}
.card--compact .card__body { grid-template-columns: 1fr; grid-template-areas: "name" "desc"; }

.card:hover .card__body { border-color: #414855; background: var(--bg-hover); }
.card input:checked + .card__body { border-color: var(--accent-line); background: var(--accent-soft); }
.card input:focus-visible + .card__body { box-shadow: 0 0 0 3px var(--accent-soft); }

.card__name {
  grid-area: name;
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.card__desc { grid-area: desc; font-size: 11.5px; line-height: 1.45; color: var(--ink-dim); }
.card input:checked + .card__body .card__desc { color: var(--ink-mid); }

.card__figure {
  grid-area: fig;
  display: flex; gap: 2px; align-items: flex-start;
  width: 34px; height: 34px;
  padding-top: 3px;
}
.card__figure i {
  display: block; flex: 1;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--bg-sunken);
}
.card__figure--tall i { height: 32px; flex: 0 0 16px; margin: 0 auto; }
.card__figure--fit i { height: 20px; flex: 0 0 18px; margin: 4px auto 0; }
.card input:checked + .card__body .card__figure i { border-color: var(--accent-line); }

.badge {
  padding: 1.5px 6px;
  border-radius: 20px;
  background: rgba(63, 178, 127, 0.14);
  border: 1px solid rgba(63, 178, 127, 0.32);
  color: var(--ok);
  font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
  text-transform: none;
}
.badge--alt {
  background: rgba(148, 163, 255, 0.13);
  border-color: rgba(148, 163, 255, 0.3);
  color: #a3b0ff;
}

/* segmented */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.segmented__item { position: relative; }
.segmented__item input { position: absolute; opacity: 0; pointer-events: none; }
.segmented__item span {
  display: block;
  padding: 5px 10px;
  border-radius: 5px;
  text-align: center;
  font-size: 12.5px; color: var(--ink-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.segmented__item:hover span { color: var(--ink-mid); }
.segmented__item input:checked + span { background: var(--bg-hover); color: var(--ink); }
.segmented__item input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.segmented--sm span { padding: 3px 11px; font-size: 12px; }
.segmented--sm { flex: 0 0 auto; }

/* details */
.advanced {
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
}
.advanced > summary {
  padding: 9px 12px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-mid);
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 7px;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 4.5px solid var(--ink-dim);
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  transition: transform 0.15s;
}
.advanced[open] > summary::before { transform: rotate(90deg); }
.advanced > summary:hover { color: var(--ink); }
.advanced > *:not(summary) { margin-left: 12px; margin-right: 12px; }
.advanced > *:last-child { margin-bottom: 12px; }

/* ─────────────────────────────── buttons ────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.13s, border-color 0.13s, color 0.13s, opacity 0.13s;
  white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn--primary:hover:not(:disabled) { background: #ef6549; }

.btn--secondary { background: var(--bg-input); border-color: var(--line-strong); color: var(--ink); }
.btn--secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: #414855; }

.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-mid); font-size: 12.5px; padding: 6px 12px; }
.btn--ghost:hover:not(:disabled) { background: var(--bg-input); color: var(--ink); }

.actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  padding: 18px 0 0;
  border-top: 1px solid var(--line-soft);
}

/* progress */
.progress { margin-top: 14px; }
.progress__bar {
  height: 4px;
  border-radius: 3px;
  background: var(--bg-input);
  overflow: hidden;
}
.progress__bar i {
  display: block; height: 100%; width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.25s ease;
}
.progress__text { margin: 7px 0 0; font-size: 12px; color: var(--ink-mid); }

/* notices */
.notices { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.notices:empty { margin-top: 0; }

.notice {
  display: flex; gap: 9px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-input);
  font-size: 12.5px; line-height: 1.5;
  color: var(--ink-mid);
}
.notice strong { color: var(--ink); font-weight: 600; }
.notice--ok   { border-color: rgba(63, 178, 127, 0.32); background: rgba(63, 178, 127, 0.09); }
.notice--warn { border-color: rgba(217, 160, 58, 0.32); background: rgba(217, 160, 58, 0.09); }
.notice--bad  { border-color: rgba(224, 82, 82, 0.32);  background: rgba(224, 82, 82, 0.09); }
.notice__icon { flex: 0 0 auto; margin-top: 1px; }
.notice--ok .notice__icon { color: var(--ok); }
.notice--warn .notice__icon { color: var(--warn); }
.notice--bad .notice__icon { color: var(--bad); }

/* ─────────────────────────────── preview ────────────────────────────── */
.preview__bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
}
.preview__meta {
  flex: 1 1 auto; margin: 0;
  font-size: 12px; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.zoom { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.zoom output { font-size: 11.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums; min-width: 34px; }

.preview__stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background:
    linear-gradient(var(--bg-sunken), var(--bg-sunken)),
    repeating-conic-gradient(#141519 0% 25%, #101216 0% 50%) 0 0/18px 18px;
  background-blend-mode: normal;
}

.preview__live { display: flex; justify-content: center; min-height: 100%; }
.preview__live.is-empty .sheet { display: none; }

.sheet {
  position: relative;
  flex: 0 0 auto;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 40px rgba(0,0,0,0.45);
  transform-origin: top center;
}
.sheet iframe {
  display: block;
  width: 100%; height: 100%;
  border: 0;
  background: #fff;
}
/* The border draws the margin band; the inner outline traces the content box.
   Kept neutral so the sheet still reads as white paper. */
.sheet__guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  border-style: solid;
  border-color: rgba(23, 32, 56, 0.05);
}
.sheet__guides::after {
  content: "";
  position: absolute; inset: 0;
  outline: 1px dashed rgba(228, 87, 61, 0.38);
  outline-offset: -1px;
}

.preview__empty {
  align-self: center;
  margin: auto;
  max-width: 280px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-dim);
}

.preview__pages { min-height: 100%; }
.pagegrid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}
.pagecard { position: relative; }
.pagecard img {
  display: block;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 10px 32px rgba(0,0,0,0.4);
}
.pagecard__num {
  position: absolute;
  bottom: -19px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ────────────────────────────── responsive ──────────────────────────── */
@media (max-width: 1080px) {
  body { overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .panel--controls { overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel--preview { min-height: 70vh; }
  .preview__stage { max-height: none; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 12px; }
  .brand__text small { display: none; }
  .panel--controls { padding: 4px 14px 24px; }
  .cards--2 { grid-template-columns: 1fr; }
  .row--3, .row--5 { grid-template-columns: 1fr 1fr; }
  .actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
