/* =====================================================================
   app.css — Kagaz app-specific styles that EXTEND (never override) base.css.
   base.css owns the design system + tokens (incl. the teal accent block).
   This file adds the chrome the design system doesn't ship: the brand
   lockup, the privacy badge, the tool grid, the file-tray strip, the
   drag-drop overlay, and the Inspect facts + thumbnail grid. Every color
   comes from a token so both themes stay correct.
   ===================================================================== */

/* Vertical rhythm helpers used by the views. */
.stack-lg > * + * { margin-top: var(--sp-6); }

/* ---------------------------------------------------------------------
   K9 AA-contrast text tones. --warn/--success are tuned as ACCENTS (fills,
   dots, large text); as SMALL text on light surfaces/tints they fall short
   of 4.5:1 (warn 3.19 on white, 2.86 on warn-bg; success 3.0 on its tint).
   These darker text-only tones pass AA in light; dark theme's brighter
   values already pass (8.1–10.3:1) so they simply alias them there.
   Mirrors base.css's dark-mode precedence (media query + data-theme).
   --------------------------------------------------------------------- */
:root {
  --warn-text: #92400e;    /* 7.09:1 on surface, 6.37:1 on warn-bg (light) */
  --success-text: #166534; /* 7.13:1 on surface, 6.49:1 on success-bg (light) */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --warn-text: var(--warn);
    --success-text: var(--success);
  }
}
:root[data-theme="dark"] {
  --warn-text: var(--warn);
  --success-text: var(--success);
}

/* Topbar icon buttons (back arrow, theme) — square 44px taps. */
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--r-input);
  cursor: pointer;
}
.iconbtn:hover { background: var(--accent-soft); }
.iconbtn svg { width: 22px; height: 22px; display: block; }
@media (prefers-reduced-motion: no-preference) {
  .iconbtn { transition: background-color var(--dur-fast) var(--ease); }
  .iconbtn:active { transform: scale(0.94); }
}

/* ---------------------------------------------------------------------
   Brand lockup — folded-paper logo mark + wordmark in the top bar.
   --------------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-input);
  padding: var(--sp-1) var(--sp-1);
}
.brand svg { display: block; }
.brand__word {
  font-size: var(--fs-20);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.topbar .title { font-size: var(--fs-20); font-weight: 700; letter-spacing: -0.01em; }

/* ---------------------------------------------------------------------
   Privacy badge — the identity line, prominent on home.
   --------------------------------------------------------------------- */
.privacy-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: var(--r-card);
  /* It is a real button now (tap → Privacy sheet): reset button chrome, keep the card look. */
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.privacy-badge:hover { background: color-mix(in srgb, var(--accent) 26%, transparent); }
.privacy-badge:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.privacy-badge__icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--r-input);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent-soft-text);
}
.privacy-badge__body { flex: 1 1 auto; min-width: 0; }
.privacy-badge__title { font-size: var(--fs-15); font-weight: 700; }
.privacy-badge__sub { font-size: var(--fs-13); opacity: 0.9; }
.privacy-badge__chevron { flex: 0 0 auto; display: inline-flex; opacity: 0.7; }

/* ---------------------------------------------------------------------
   Home intake row + section headings.
   --------------------------------------------------------------------- */
.home-intake { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.home-section { margin-bottom: calc(-1 * var(--sp-3)); color: var(--text); }

/* ---------------------------------------------------------------------
   Tool grid — data-driven cards, one per registered tool.
   --------------------------------------------------------------------- */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-3);
}
.tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  color: var(--text);
  text-decoration: none;
  min-height: 128px;
}
.tool-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: var(--r-input);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}
.tool-card__name { font-size: var(--fs-17); font-weight: 700; }
.tool-card__tag { font-size: var(--fs-13); line-height: var(--lh); }
@media (prefers-reduced-motion: no-preference) {
  .tool-card { transition: box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
  .tool-card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
  .tool-card:active { transform: translateY(0); }
}

/* ---------------------------------------------------------------------
   File-tray strip — persistent horizontal list of loaded PDFs.
   --------------------------------------------------------------------- */
.tray {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tray.is-empty { color: var(--text-muted); }
.tray__empty { font-size: var(--fs-13); padding: 0 var(--sp-2); flex: 0 0 auto; }
.tray__label { font-size: var(--fs-13); padding: 0 var(--sp-1); flex: 0 0 auto; white-space: nowrap; }
.tray__add {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-input);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.tray__add:hover { background: var(--accent-soft); color: var(--accent-soft-text); border-color: var(--accent); }

.tray-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  max-width: 220px;
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  overflow: hidden;
}
.tray-chip.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tray-chip__main {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  padding: var(--sp-1) var(--sp-2);
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.tray-chip__icon { flex: 0 0 auto; color: var(--accent-soft-text); display: inline-flex; }
.tray-chip__text { min-width: 0; display: flex; flex-direction: column; }
.tray-chip__name {
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tray-chip__meta { font-size: 11px; white-space: nowrap; }
.tray-chip__x {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.tray-chip__x:hover { color: var(--danger); background: var(--danger-bg); }

/* ---------------------------------------------------------------------
   Drag-drop overlay — whole-app dropzone with a visual active state.
   --------------------------------------------------------------------- */
.dropzone {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background: color-mix(in srgb, var(--accent) 22%, var(--overlay));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.dropzone.is-active { display: flex; }
.dropzone__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-6);
  min-width: 260px;
  background: var(--raised);
  border: 2px dashed var(--accent);
  border-radius: var(--r-sheet);
  box-shadow: var(--shadow-2);
  color: var(--accent-soft-text);
  text-align: center;
}
.dropzone__title { font-size: var(--fs-17); font-weight: 700; color: var(--text); }
.dropzone__sub { font-size: var(--fs-13); }

/* ---------------------------------------------------------------------
   Inspect tool — facts grid + metadata + thumbnail grid.
   --------------------------------------------------------------------- */
.inspect-head { display: flex; align-items: center; gap: var(--sp-3); }
.inspect-head__icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: var(--r-input);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}
.inspect-head__text { min-width: 0; flex: 1 1 auto; }
.inspect-head__name {
  word-break: break-word;
}
.inspect-head__meta { font-size: var(--fs-13); }

.card__title { margin-bottom: var(--sp-3); }

.facts { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0; }
.fact {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-4);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.fact:last-child { border-bottom: none; }
.fact__k { flex: 0 0 auto; font-size: var(--fs-13); }
.fact__v {
  flex: 1 1 auto;
  text-align: right;
  font-size: var(--fs-15);
  word-break: break-word;
  min-width: 0;
}
.fact-skel { padding: var(--sp-2) 0; }
.inspect-error { color: var(--danger); font-size: var(--fs-13); }

/* Thumbnail grid — lazy-rendered page previews (~140px wide). */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--sp-3);
}
.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
}
.thumb__canvas {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  overflow: hidden;
}
.thumb__canvas .skeleton--thumb { border-radius: 0; height: 100%; }
.thumb__img {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  display: block;
  box-shadow: var(--shadow-1);
}
.thumb__label { font-size: var(--fs-13); color: var(--text-muted); }
.thumb__err {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  color: var(--danger); font-weight: 700; font-size: var(--fs-20);
}

/* =====================================================================
   K2 — Merge + Split tools.
   ===================================================================== */

/* Small variants used by the tool rows. */
.iconbtn--sm { width: 36px; height: 36px; }
.iconbtn--sm svg { width: 18px; height: 18px; }
.iconbtn:disabled { opacity: 0.4; pointer-events: none; }
.input--sm { min-height: 40px; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-13); }
.label { display: block; font-size: var(--fs-13); font-weight: 600; color: var(--text-muted); margin-bottom: var(--sp-2); }
.label--sm { font-size: 11px; margin-bottom: var(--sp-1); }

/* A "chip" line showing describeRanges() output under a range input. */
.range-chip {
  min-height: 1.2em;
  margin-top: var(--sp-1);
  font-size: var(--fs-13);
  color: var(--accent-soft-text);
  font-variant-numeric: tabular-nums;
}
.range-chip:empty { display: none; }

/* ---------------------------------------------------------------------
   Merge — the reorderable file list.
   --------------------------------------------------------------------- */
.merge-hint { font-size: var(--fs-13); margin-bottom: var(--sp-3); }
.merge-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.merge-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "handle head moves" "range range range";
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3);
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.merge-row.is-dragging { box-shadow: var(--shadow-2); border-color: var(--accent); opacity: 0.95; }
.merge-row__handle {
  grid-area: handle;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 40px;
  border: none; background: transparent; color: var(--text-faint);
  cursor: grab; touch-action: none; border-radius: var(--r-input);
}
.merge-row__handle:hover { color: var(--text-muted); background: var(--surface); }
.merge-row__handle:active { cursor: grabbing; }
.merge-row__head { grid-area: head; display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.merge-row__pos {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-soft-text);
  font-size: var(--fs-13); font-weight: 700;
}
.merge-row__id { min-width: 0; }
.merge-row__name {
  font-size: var(--fs-15); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.merge-row__meta { font-size: 11px; }
.merge-row__moves { grid-area: moves; display: flex; flex-direction: column; gap: 2px; }
.merge-row__range { grid-area: range; margin: 0; display: flex; flex-direction: column; }

.merge-output { margin-top: 0; }

/* ---------------------------------------------------------------------
   Split — mode switcher + range mode + visual-select grid.
   --------------------------------------------------------------------- */
.split-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.split-head__icon {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: var(--r-input);
  background: var(--accent-soft); color: var(--accent-soft-text);
}
/* Long filenames must ellipsize, not force horizontal page scroll. The flex
   text column (the unnamed div) needs min-width:0 so it can shrink below the
   filename's intrinsic width — otherwise the nowrap name overflows the row and
   drags the whole page wider than the viewport. */
.split-head { min-width: 0; }
.split-head > div { min-width: 0; flex: 1 1 auto; }
.split-head__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-head__meta { font-size: var(--fs-13); }
.split__seg, .split__outseg { display: flex; width: 100%; margin-bottom: var(--sp-4); }
.split__seg .seg-tab, .split__outseg .seg-tab { flex: 1 1 0; }
.split__outseg { margin-bottom: 0; }
.split-mode { margin-top: var(--sp-4); }

/* Visual-select thumbnails: tappable buttons with a selection badge. */
.thumb-grid--select { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.thumb-sel {
  appearance: none; border: none; background: transparent; font: inherit;
  padding: 0; cursor: pointer; color: inherit;
}
.thumb-sel .thumb__canvas { position: relative; transition: none; }
.thumb-sel.is-selected .thumb__canvas {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.thumb-sel__badge {
  position: absolute; top: 4px; right: 4px;
  display: none; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px;
  background: var(--accent-solid); color: #fff;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-1);
}
.thumb-sel__badge.is-on { display: inline-flex; }
@media (prefers-reduced-motion: no-preference) {
  .thumb-sel .thumb__canvas { transition: box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
  .thumb-sel:active { transform: scale(0.98); }
}

.visual-toolbar { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.visual-toolbar__count { font-size: var(--fs-13); font-variant-numeric: tabular-nums; }

/* =====================================================================
   K3 — Page Organizer.
   ===================================================================== */

.organize__tray { margin-bottom: var(--sp-2); }
.organize-head { display: flex; align-items: flex-start; gap: var(--sp-3); }
.organize-head__icon { flex: 0 0 auto; color: var(--accent-soft-text); display: inline-flex; margin-top: 2px; }
.organize-head__id { min-width: 0; }
.organize-head__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.organize-head__meta { font-size: var(--fs-13); margin-top: 2px; }
.organize-loading { padding: var(--sp-4) 0; }

/* Toolbar: undo/redo/reset on the left, page-count + save on the right. */
.organize-toolbar {
  display: flex; align-items: center; gap: var(--sp-2);
  flex-wrap: wrap;
  position: sticky; top: calc(var(--topbar-h, 56px) + var(--sp-2));
  z-index: 5;
}
.organize-toolbar__group { display: flex; align-items: center; gap: var(--sp-2); }
.organize-toolbar__count {
  font-size: var(--fs-13); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.organize-toolbar__count.is-dirty { color: var(--warn-text); font-weight: 600; }
.organize-toolbar__count.is-dirty::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); margin-right: 6px; vertical-align: middle;
}

/* The page grid: cells interleaved with thin "+" insert separators. */
.organize-grid {
  display: flex; flex-wrap: wrap; align-items: stretch;
  gap: var(--sp-1);
}
.organize-grid__empty { width: 100%; text-align: center; padding: var(--sp-6) 0; }

/* Insert-blank separator — a thin tappable column between thumbs. */
.organize-sep {
  appearance: none; border: none; background: transparent; cursor: pointer;
  flex: 0 0 auto; width: 22px; align-self: stretch; min-height: 150px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); padding: 0; border-radius: var(--r-input);
}
.organize-sep__plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px dashed var(--border-strong); background: var(--surface);
}
.organize-sep:hover { color: var(--accent); }
.organize-sep:hover .organize-sep__plus { border-color: var(--accent); border-style: solid; background: var(--accent-soft); }
.organize-sep:disabled { opacity: 0.4; pointer-events: none; }

/* A page cell — thumb, overlay controls, page label. */
.organize-cell {
  flex: 0 0 auto; width: 132px;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-1);
  padding: var(--sp-2); border-radius: var(--r-card);
  border: 1px solid transparent;
  touch-action: none; /* let pointer drag work without the page scrolling */
}
.organize-cell.is-dragging { opacity: 0.5; border-color: var(--accent); background: var(--accent-soft); }
.organize-cell__thumb {
  width: 100%; aspect-ratio: 3 / 4;
  display: flex; align-items: center; justify-content: center;
  background: var(--gray-100); border: 1px solid var(--border);
  border-radius: var(--r-input); overflow: hidden; cursor: grab;
  /* The user's applied rotation is shown by rotating the thumb contents. */
}
.organize-cell__canvas { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  transform: rotate(var(--rot, 0deg)); }
.organize-cell__thumb > .organize-blank { transform: rotate(var(--rot, 0deg)); }
.organize-cell__img { max-width: 100%; max-height: 100%; height: auto; display: block; box-shadow: var(--shadow-1); }
.organize-cell__canvas .skeleton--thumb { border-radius: 0; height: 100%; width: 100%; }

/* Blank-page glyph. */
.organize-blank {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-1); width: 76%; height: 88%;
  border: 2px dashed var(--border-strong); border-radius: 6px;
  color: var(--text-faint); background: var(--surface);
}
.organize-blank__label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }

/* Overlay controls under each thumb. */
/* K9: a 2×2 grid of full ≥44px tap targets. The old 4-in-a-row 30px buttons overflowed the
   132px cell at 375px (126px of buttons in 114px of content box) AND missed the ≥44px
   touch-target bar. Order: move ◀ ▶ on top, rotate/delete below (via the modifier classes). */
.organize-cell__ctrls {
  display: grid; grid-template-columns: repeat(2, var(--tap)); gap: 4px;
  justify-content: center;
}
.organize-ctrl {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer;
  width: var(--tap); height: var(--tap); border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
}
.organize-cell__move-l { order: 1; }
.organize-cell__move-r { order: 2; }
.organize-cell__rotate { order: 3; }
.organize-cell__del { order: 4; }
.organize-ctrl:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-soft-text); }
.organize-ctrl.is-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.organize-ctrl:disabled { opacity: 0.35; pointer-events: none; }
.organize-ctrl svg { width: 16px; height: 16px; display: block; }
.organize-cell__label { font-size: var(--fs-13); color: var(--text-muted); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  .organize-cell, .organize-ctrl, .organize-sep__plus, .organize-cell__canvas, .organize-cell__thumb > .organize-blank {
    transition: transform var(--dur) var(--ease), background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
  }
  .organize-ctrl:active { transform: scale(0.92); }
}

@media (max-width: 420px) {
  .organize-cell { width: 116px; }
  .organize-sep { min-height: 130px; }
  .organize-toolbar { position: static; }
}

/* =====================================================================
   K4 — Images↔PDF tools (img2pdf + pdf2img).
   ===================================================================== */

/* Segmented controls used across both tools (each seg tab flexes to fill). */
.img2pdf-seg { display: flex; width: 100%; }
.img2pdf-seg .seg-tab { flex: 1 1 0; }

/* ---- Images → PDF: local drop target ---- */
.img2pdf-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--r-card);
  color: var(--text);
  cursor: pointer;
}
.img2pdf-drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-text); }
.img2pdf-drop.is-compact { padding: var(--sp-4); }
.img2pdf-drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.img2pdf-drop__icon { color: var(--accent-soft-text); display: inline-flex; }
.img2pdf-drop__title { font-size: var(--fs-15); font-weight: 700; }
.img2pdf-drop__sub { font-size: var(--fs-13); }

/* ---- Images → PDF: reorderable list ---- */
.img2pdf-list__head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.img2pdf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.img2pdf-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
.img2pdf-row__num {
  flex: 0 0 auto;
  width: 1.6em; text-align: right;
  font-size: var(--fs-13); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.img2pdf-row__thumb {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  overflow: hidden;
}
.img2pdf-row__img { max-width: 100%; max-height: 100%; height: auto; display: block; }
.img2pdf-row__meta { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.img2pdf-row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-15); }
.img2pdf-row__sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.img2pdf-row__ctrls { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; }
.img2pdf-row__del:hover { color: var(--danger); }
.img2pdf-note { font-size: var(--fs-13); line-height: var(--lh); }

/* ---- PDF → Images ---- */
.pdf2img__tray { margin-bottom: var(--sp-2); }
.pdf2img-progress { min-height: 1.2em; font-size: var(--fs-13); font-variant-numeric: tabular-nums; }
.pdf2img-progress:empty { display: none; }
.pdf2img-qual__row { display: flex; align-items: center; gap: var(--sp-3); }
.pdf2img-qual__slider { flex: 1 1 auto; accent-color: var(--accent); }
.pdf2img-qual__val { flex: 0 0 auto; font-size: var(--fs-13); color: var(--text-muted); min-width: 3.2em; text-align: right; }

@media (prefers-reduced-motion: no-preference) {
  .img2pdf-drop, .img2pdf-row { transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
}

/* =====================================================================
   K5 — Watermark (text/image) + Page numbers. Both tools share the
   controls + approximate-preview layout and most control atoms.
   ===================================================================== */

.watermark__tray, .pagenum__tray { margin-bottom: var(--sp-2); }

/* Mode + layout segmented controls stretch full-width like split's. */
.watermark__seg, .watermark__lay, .pagenum__fmt {
  display: flex; width: 100%;
}
.watermark__seg .seg-tab, .watermark__lay .seg-tab, .pagenum__fmt .seg-tab { flex: 1 1 0; }
.watermark__seg { margin-bottom: var(--sp-2); }

/* Two-pane layout: narrow controls beside a LARGE sticky preview on desktop;
   stacks to a single column below 960px (where the shell is still phone-width). */
.watermark-layout { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
.watermark-controls { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.watermark-preview { min-width: 0; }
@media (min-width: 960px) {
  .watermark-layout { grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); align-items: start; }
  .watermark-preview { position: sticky; top: calc(var(--topbar-h, 56px) + var(--sp-3)); }
  .watermark-preview__page { max-width: 520px; margin-inline: auto; }
  .watermark-preview__page .skeleton--thumb { width: 320px; height: 420px; }
}

/* =====================================================================
   Desktop layout (≥960px). Kagaz is a productivity tool, so the shell
   widens to use the screen instead of stranding a phone-width column in
   the centre. Grid + preview screens (home, inspect, split, organize,
   sign, watermark, page numbers) fill the width; single-column form
   tools stay centred at a readable width so they don't stretch. The
   mobile-first base (640px shell) is untouched below this breakpoint.
   ===================================================================== */
@media (min-width: 960px) {
  /* Widen the shell. --content-max also drives the topbar span + FAB
     offset, so both track the new width automatically. */
  :root { --content-max: 1120px; }

  /* Single-column form tools: readable + centred, never full-bleed. */
  .content > .merge,
  .content > .metadata,
  .content > .compress,
  .content > .pdf2img,
  .content > .img2pdf {
    max-width: 820px;
    margin-inline: auto;
  }
}

/* Slider + numeric read-out row (font size, opacity, scale, margin). */
.watermark-sliderrow { display: flex; align-items: center; gap: var(--sp-3); }
.watermark-slider { flex: 1 1 auto; accent-color: var(--accent); }
.watermark-num {
  flex: 0 0 auto; min-width: 3.4em; text-align: right;
  font-size: var(--fs-13); color: var(--text-muted); font-variant-numeric: tabular-nums;
}

/* Rotation presets + free number field. */
.watermark-rot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.watermark-rot__preset {
  flex: 0 0 auto; min-width: 52px;
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); color: var(--text);
  padding: var(--sp-2) var(--sp-2); font-size: var(--fs-13); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.watermark-rot__preset.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-text); font-weight: 700; }
.watermark-rot__num { width: 84px; flex: 0 0 auto; }

/* Colour swatches. */
.watermark-swatches { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.watermark-swatch {
  width: 30px; height: 30px; flex: 0 0 auto; padding: 0; cursor: pointer;
  border: 2px solid var(--border); border-radius: 50%;
  background: var(--sw, var(--accent));
  box-shadow: inset 0 0 0 2px var(--surface);
}
.watermark-swatch.is-active { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 2px var(--accent); }
.watermark-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Position grid — a 3×3 pad; disabled cells for tools with fewer positions. */
.watermark-posgrid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-1);
  width: 132px; aspect-ratio: 1 / 1;
  padding: var(--sp-1);
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--gray-100);
}
.watermark-poscell {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer;
}
.watermark-poscell:hover:not(.is-off) { background: var(--surface); }
.watermark-poscell__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.watermark-poscell.is-active { background: var(--accent-soft); border-color: var(--accent); }
.watermark-poscell.is-active .watermark-poscell__dot { background: var(--accent-solid); }
.watermark-poscell.is-off { cursor: default; opacity: 0.35; }
.watermark-poscell.is-off .watermark-poscell__dot { background: transparent; }
.watermark-poscell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Image picker (watermark image mode). */
.watermark-imgpick {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4); text-align: left;
  border: 2px dashed var(--border); border-radius: var(--r-card);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.watermark-imgpick:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-text); }
.watermark-imgpick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.watermark-imgpick.has-image { flex-direction: row; }
.watermark-imgpick__icon { color: var(--accent-soft-text); display: inline-flex; flex: 0 0 auto; }
.watermark-imgpick__title { font-size: var(--fs-15); font-weight: 700; }
.watermark-imgpick__sub { font-size: var(--fs-13); }
.watermark-imgpick__preview {
  flex: 0 0 auto; width: 48px; height: 48px; object-fit: contain;
  background: var(--gray-100); border: 1px solid var(--border); border-radius: var(--r-input);
}
.watermark-imgpick__meta { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.watermark-imgpick__name { font-size: var(--fs-15); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watermark-imgpick__sub { font-size: 11px; }
.watermark-imgpick__change { flex: 0 0 auto; font-size: var(--fs-13); font-weight: 600; }

/* Approximate live preview — page-1 thumbnail + CSS overlay. */
.watermark-preview__label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}
.watermark-preview__stage { display: flex; justify-content: center; }
.watermark-preview__page {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  max-width: 100%;
  background: var(--gray-100); border: 1px solid var(--border); border-radius: var(--r-input);
  overflow: hidden; box-shadow: var(--shadow-1);
  min-height: 120px; min-width: 90px;
}
.watermark-preview__page .skeleton--thumb { width: 180px; height: 240px; border-radius: 0; }
.watermark-preview__img { display: block; max-width: 100%; height: auto; }

.watermark-preview__overlay { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.watermark-preview__overlay.is-tile {
  display: grid; grid-template-columns: repeat(3, 1fr); align-content: center; justify-items: center; align-items: center;
  gap: 6% 4%; padding: 6%;
}
.watermark-preview__wm {
  font-weight: 800; white-space: nowrap; line-height: 1;
  transform-origin: center;
}
.watermark-preview__wm.is-center { position: absolute; top: 50%; left: 50%; }

.watermark-preview__imgpos { position: absolute; display: block; }
.watermark-preview__imgpos .watermark-preview__imgwm { display: block; width: 100%; height: auto; }
.watermark-preview__imgpos.pos-center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.watermark-preview__imgpos.pos-top-left { top: 6%; left: 6%; }
.watermark-preview__imgpos.pos-top-right { top: 6%; right: 6%; }
.watermark-preview__imgpos.pos-bottom-left { bottom: 6%; left: 6%; }
.watermark-preview__imgpos.pos-bottom-right { bottom: 6%; right: 6%; }

/* Page-number preview label — positioned by the 6 corner/centre classes. */
.pagenum-preview__label {
  position: absolute; white-space: nowrap; font-weight: 600; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.pagenum-preview__label.pos-top-left { top: var(--m, 4%); left: var(--m, 4%); }
.pagenum-preview__label.pos-top-center { top: var(--m, 4%); left: 50%; transform: translateX(-50%); }
.pagenum-preview__label.pos-top-right { top: var(--m, 4%); right: var(--m, 4%); }
.pagenum-preview__label.pos-bottom-left { bottom: var(--m, 4%); left: var(--m, 4%); }
.pagenum-preview__label.pos-bottom-center { bottom: var(--m, 4%); left: 50%; transform: translateX(-50%); }
.pagenum-preview__label.pos-bottom-right { bottom: var(--m, 4%); right: var(--m, 4%); }

.pagenum-posgrid { /* same visual as watermark grid */ }

@media (prefers-reduced-motion: no-preference) {
  .watermark-rot__preset, .watermark-swatch, .watermark-poscell, .watermark-imgpick {
    transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
}

/* =====================================================================
   K6 — Sign (pad + library + placement) & Metadata editor.
   ===================================================================== */

/* ---- Signature pad ---- */
.sign-pad {
  border: 1px dashed var(--border);
  border-radius: var(--r-input);
  background:
    repeating-linear-gradient(0deg, transparent, transparent 43px, color-mix(in srgb, var(--border) 60%, transparent) 44px);
  background-color: var(--raised);
  padding: var(--sp-2);
}
.sign-pad__canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 600 / 220;
  touch-action: none;                 /* let pointer drawing own the gesture */
  cursor: crosshair;
  border-radius: calc(var(--r-input) - 2px);
}
.sign-pad__tools { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin-top: var(--sp-3); }
.sign-pad__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-3); }

.sign-pen-row { display: flex; gap: var(--sp-2); }
.sign-pen {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); cursor: pointer;
}
.sign-pen__dot { width: var(--pw, 6px); height: var(--pw, 6px); border-radius: 50%; background: var(--text); display: block; }
.sign-pen.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sign-pen:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Library ---- */
.sign-lib__empty { padding: var(--sp-2) 0; }
.sign-lib__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--sp-3);
}
.sign-lib-card {
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); overflow: hidden;
}
.sign-lib-card.is-chosen { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sign-lib-card__pick {
  display: block; width: 100%; padding: var(--sp-2);
  background: var(--raised); border: none; cursor: pointer;
  min-height: 64px;
}
.sign-lib-card__img { display: block; max-width: 100%; max-height: 72px; margin: 0 auto; object-fit: contain; }
.sign-lib-card__row { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1) var(--sp-2); }
.sign-lib-card__name {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-13);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Placement ---- */
.sign-place__empty { padding: var(--sp-2) 0 var(--sp-3); }
.sign-place__layout { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); align-items: start; }
@media (min-width: 720px) {
  .sign-place__layout { grid-template-columns: 1fr minmax(280px, 360px); }
}
.sign-place__controls { min-width: 0; }
.sign-place__chosen { display: flex; align-items: center; gap: var(--sp-2); }
.sign-place__chosenimg {
  max-height: 40px; max-width: 120px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 6px; background: var(--raised); padding: 2px;
}

.sign-stage { display: flex; justify-content: center; min-width: 0; }
.sign-stage__page {
  position: relative; display: inline-block; line-height: 0;
  border: 1px solid var(--border); border-radius: 4px; overflow: hidden;
  background: var(--raised); touch-action: none;
}
.sign-stage__page .skeleton--thumb { width: 240px; height: 320px; }
.sign-stage__canvas { display: block; max-width: 100%; height: auto; }
.sign-stage__sig {
  position: absolute; display: block; height: auto;
  pointer-events: auto; cursor: grab; user-select: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.18));
}
.sign-stage__sig.is-dragging { cursor: grabbing; }

.sign-nudge {
  display: inline-grid; grid-template-columns: repeat(3, 40px); grid-auto-rows: 40px; gap: var(--sp-1);
}
.sign-nudge__btn, .sign-nudge__center {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); color: var(--text); font-size: var(--fs-17); cursor: pointer;
}
.sign-nudge__btn:hover, .sign-nudge__center:hover { background: var(--accent-soft); }
.sign-nudge__btn:focus-visible, .sign-nudge__center:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sign-nudge__center { color: var(--text-muted); }

.sign-readout {
  font-size: var(--fs-13); color: var(--accent-soft-text);
  font-variant-numeric: tabular-nums;
}

/* ---- Metadata editor ---- */
.metadata__status { padding: var(--sp-2) 0; }
.metadata-ro { display: flex; flex-direction: column; gap: var(--sp-2); }
.metadata-ro__row { display: flex; gap: var(--sp-3); align-items: baseline; }
.metadata-ro__label { flex: 0 0 84px; font-size: var(--fs-13); }
.metadata-ro__value {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-13); word-break: break-word;
  font-variant-numeric: tabular-nums;
}
.metadata-diff { min-height: 1.2em; font-size: var(--fs-13); color: var(--text-muted); }
.metadata-diff.is-dirty { color: var(--accent-soft-text); font-weight: 600; }

/* Keywords chips-input (also reusable elsewhere). */
.chips {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2); min-height: 44px;
  border: 1px solid var(--border); border-radius: var(--r-input); background: var(--surface);
}
.chips:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px 4px 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-soft-text); font-size: var(--fs-13);
}
.chip__x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; border: none; border-radius: 50%;
  background: transparent; color: inherit; cursor: pointer;
}
.chip__x:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.chip__x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips__input {
  flex: 1 1 120px; min-width: 100px; border: none; background: transparent; color: var(--text);
  font: inherit; padding: 4px 2px; outline: none;
}

/* =====================================================================
   K7 — Compress (raster-recompress). Warning banner + preset cards +
   custom expander + honest before/after result panel.
   ===================================================================== */

.compress__tray { margin-bottom: var(--sp-2); }

/* The permanent flatten warning (shown BEFORE apply). Amber, note-style. */
.compress-warn {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3); border-radius: var(--r-input);
  background: var(--warn-bg); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  font-size: var(--fs-13); line-height: var(--lh);
}
.compress-warn__icon { color: var(--warn); flex: 0 0 auto; display: inline-flex; margin-top: 1px; }
.compress-warn__text { min-width: 0; }

/* Preset cards — a single column of tappable radios. */
.compress-presets { display: grid; grid-template-columns: 1fr; gap: var(--sp-2); }
.compress-preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.compress-preset:hover { border-color: var(--border-strong); }
.compress-preset.is-active {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.compress-preset__label { font-size: var(--fs-15); font-weight: 700; }
.compress-preset.is-active .compress-preset__label { color: var(--accent-soft-text); }
.compress-preset__sub { font-size: var(--fs-13); }

/* Custom expander. */
.compress-custom {
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); overflow: hidden;
}
.compress-custom__toggle {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  width: 100%; padding: var(--sp-3) var(--sp-4); background: transparent;
  border: none; color: var(--text); cursor: pointer; font-size: var(--fs-15); font-weight: 600;
}
.compress-custom__toggle.is-active { color: var(--accent-soft-text); background: var(--accent-soft); }
.compress-custom__chev { display: inline-flex; color: var(--text-faint); }
.compress-custom__toggle[aria-expanded="true"] .compress-custom__chev { transform: rotate(90deg); }
.compress-custom__body {
  display: flex; flex-direction: column; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--border);
}
.compress-custom__row { display: flex; align-items: center; gap: var(--sp-3); }
.compress-custom__slider { flex: 1 1 auto; accent-color: var(--accent); }
.compress-custom__val {
  flex: 0 0 auto; font-size: var(--fs-13); color: var(--text-muted);
  min-width: 4.2em; text-align: right;
}

/* Progress line during a run. */
.compress-progress { min-height: 1.2em; font-size: var(--fs-13); font-variant-numeric: tabular-nums; }
.compress-progress:empty { display: none; }

/* Result panel. */
.compress-result:empty { display: none; }
.compress-result__panel { display: flex; flex-direction: column; gap: var(--sp-3); }
.compress-result__title { font-size: var(--fs-17); font-weight: 700; }
.compress-result__panel.is-grew .compress-result__title { color: var(--warn-text); }
.compress-result__panel.is-smaller .compress-result__title { color: var(--success-text); }
.compress-result__sizes {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2);
  font-size: var(--fs-20); font-weight: 700; font-variant-numeric: tabular-nums;
}
.compress-result__arrow { color: var(--text-faint); font-weight: 400; }
.compress-result__after { color: var(--text); }
.compress-result__pct {
  font-size: var(--fs-13); font-weight: 700; padding: 2px 8px; border-radius: 999px;
  align-self: center;
}
.compress-result__pct.is-smaller { background: var(--success-bg); color: var(--success-text); }
.compress-result__pct.is-grew { background: var(--warn-bg); color: var(--warn-text); }
.compress-result__msg { font-size: var(--fs-13); line-height: var(--lh); margin: 0; }

@media (prefers-reduced-motion: no-preference) {
  .compress-preset, .compress-custom__toggle { transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
  .compress-custom__chev { transition: transform var(--dur-fast) var(--ease); }
}

/* ---------------------------------------------------------------------
   Privacy sheet (L1) — reassurance copy + the analytics opt-out toggle.
   Opened by tapping the home privacy badge.
   --------------------------------------------------------------------- */
.privacy-sheet { display: flex; flex-direction: column; gap: var(--sp-4); }
.privacy-copy {
  margin: 0;
  font-size: var(--fs-15);
  line-height: var(--lh);
  color: var(--text);
}
.privacy-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  cursor: pointer;
}
.privacy-toggle__label { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.privacy-toggle__title { font-size: var(--fs-15); font-weight: 600; color: var(--text); }
.privacy-toggle__sub { font-size: var(--fs-13); line-height: var(--lh); }
/* Visually-hidden native checkbox drives state + focus; the track/thumb render it. */
.privacy-toggle__input {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}
.privacy-toggle__track {
  flex: 0 0 auto;
  position: relative;
  width: 44px; height: 26px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 160ms ease;
}
.privacy-toggle__thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 160ms ease;
}
.privacy-toggle__input:checked ~ .privacy-toggle__track { background: var(--accent-solid); }
.privacy-toggle__input:checked ~ .privacy-toggle__track .privacy-toggle__thumb { transform: translateX(18px); }
.privacy-toggle__input:focus-visible ~ .privacy-toggle__track {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .privacy-toggle__track, .privacy-toggle__thumb, .privacy-badge { transition: none; }
}

/* ---------------------------------------------------------------------
   Credit UI (Phase L3) — DORMANT at launch. These styles only apply when
   credits.js CONFIG.CREDITS_ENABLED is true (the JS returns null otherwise,
   so nothing carrying these classes is ever inserted while dormant). All
   colors come from tokens so both themes stay correct.
   --------------------------------------------------------------------- */

/* Top-bar meter: a subtle coin glyph + the balance count. */
.credit-meter {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  height: 32px;
  padding: 0 var(--sp-2);
  margin-right: var(--sp-1);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: var(--fs-13);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.credit-meter__icon { display: inline-flex; }
.credit-meter__icon svg { width: 18px; height: 18px; display: block; }
/* Low balance: shift the meter to the warn accent so it reads as a gentle heads-up. */
.credit-meter--low {
  background: var(--warn-bg);
  color: var(--warn-text);
}

/* Home-screen low-balance nudge — a dismissible CARD (never a modal, never mid-task). */
.credit-nudge {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--warn-bg);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: var(--r-card);
  font-size: var(--fs-13);
}
.credit-nudge__icon { flex: 0 0 auto; color: var(--warn-text); display: inline-flex; }
.credit-nudge__icon svg { width: 22px; height: 22px; }
.credit-nudge__body { flex: 1 1 auto; min-width: 0; }
.credit-nudge__title { font-size: var(--fs-15); font-weight: 700; }
.credit-nudge__sub { color: var(--text-muted); margin-top: 2px; }
.credit-nudge__actions { margin-top: var(--sp-2); }
.credit-nudge__close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap); height: var(--tap); /* >=44px touch target */
  margin: calc(var(--sp-1) * -1) calc(var(--sp-2) * -1) calc(var(--sp-1) * -1) 0;
  border: none;
  background: transparent;
  color: inherit;
  border-radius: 50%;
  cursor: pointer;
}
.credit-nudge__close:hover { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.credit-nudge__close svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------------
   Family footer (L4) — small, muted, centered; HOME view only. Wraps
   gracefully at 375px. Brand links use the accent + underline-on-hover.
   Tokens only; light/dark parity is automatic.
   --------------------------------------------------------------------- */
.app-footer {
  margin-top: var(--sp-8);
  padding: var(--sp-6) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--border);
  text-align: center;
}
.app-footer__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1) var(--sp-2);
  font-size: var(--fs-13);
  line-height: 1.6;
  color: var(--text-faint);
}
.app-footer__text { color: var(--text-faint); white-space: nowrap; }
.app-footer__sep { color: var(--text-faint); opacity: 0.6; user-select: none; }
/* Links + link-styled buttons share one look so the row reads as one line. */
.app-footer__link {
  display: inline;
  padding: 2px 1px;
  margin: 0;
  font: inherit;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: var(--r-input);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.app-footer__link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.app-footer__link--brand { color: var(--accent); font-weight: 600; }
.app-footer__link--brand:hover { color: var(--accent-hover, var(--accent)); text-decoration: underline; text-underline-offset: 2px; }
.app-footer__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Subscribe opt-in sheet (L4) — email opt-in opened from the footer.
   Reuses the shared .field / .input / .btn components; just the layout.
   --------------------------------------------------------------------- */
.subscribe-sheet { display: flex; flex-direction: column; gap: var(--sp-4); }
.subscribe-copy {
  margin: 0;
  font-size: var(--fs-15);
  line-height: var(--lh);
  color: var(--text);
}
.subscribe-consent {
  margin: 0;
  font-size: var(--fs-13);
  line-height: var(--lh);
}
