/* PDFPane editor. One screen: a bar, a hint line, the pages. */

@font-face {
  /* The font text stamps are written with. The preview uses the same file, so typed text sits on
     the page exactly where it is shown. */
  font-family: "PDFPane Sans";
  src: url("assets/NotoSans-Regular.ttf") format("truetype");
  font-display: block;
}

:root {
  --bg: #eef0f3;
  --bar: #ffffff;
  --bar-border: #e3e6ea;
  --text: #111827;
  --muted: #6b7280;
  --soft: #f4f5f7;
  --line: #e5e7eb;
  --accent: #2456d6;
  --accent-hover: #1d47b4;
  --accent-soft: #eaf0fd;
  --accent-text: #ffffff;
  --good: #047857;
  --good-soft: #e7f6ef;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --field: rgba(36, 86, 214, 0.1);
  --field-border: rgba(36, 86, 214, 0.38);
  --field-focus: rgba(36, 86, 214, 0.05);
  --ink: #0d0d26;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.08);
  --page-shadow: 0 1px 3px rgba(16, 24, 40, 0.12), 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1016;
    --bar: #151a22;
    --bar-border: #232a35;
    --text: #e6e9ef;
    --muted: #97a0ae;
    --soft: #1c222c;
    --line: #2a313d;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1b2744;
    --accent-text: #0b1020;
    --good: #34d399;
    --good-soft: #10281f;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #2d1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
    --page-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  /* minmax(0, …): a grid column is otherwise at least as wide as its widest content, and the
     bar then grows past the window instead of letting the file name give way. */
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bar);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
button:hover:not(:disabled) { background: var(--soft); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
a.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  text-decoration: none;
}
.primary.big, button.big { height: 44px; padding: 0 20px; font-size: 15px; border-radius: 10px; }

.icon-button {
  width: 34px;
  padding: 0;
  justify-content: center;
  border-color: transparent;
  background: transparent;
}

.link-button { border: 0; background: none; color: var(--accent); height: auto; padding: 0; }
.link-button:hover:not(:disabled) { background: none; text-decoration: underline; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }

/* -- bar ----------------------------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 58px;
  padding: 0 14px;
  background: var(--bar);
  border-bottom: 1px solid var(--bar-border);
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.file {
  display: flex;
  align-items: center;
  gap: 6px;
  /* The one thing in the bar that gives way: everything else keeps its size. */
  flex: 0 1 260px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
}
.brand, .tools, .bar-right { flex: none; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lock-badge { display: inline-flex; color: var(--warn); }

.tools {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 auto;
  min-width: 0;
  padding: 3px;
  background: var(--soft);
  border-radius: 10px;
}
.tool {
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-weight: 500;
}
.tool:hover:not(:disabled) { background: var(--bar); color: var(--text); }
.tool[aria-pressed="true"] { background: var(--bar); color: var(--accent); box-shadow: var(--shadow); }
.tools-divider { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }

.bar-right { display: flex; align-items: center; gap: 8px; }

.offline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--good-soft);
  color: var(--good);
  font-size: 12px;
  font-weight: 600;
}

.zoom { display: flex; align-items: center; }
.zoom-label { min-width: 44px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

.plan-chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--soft);
  border-color: transparent;
}
.plan-chip.out { color: var(--warn); background: var(--warn-soft); }
.plan-chip.pro { color: var(--good); background: var(--good-soft); }

.no-document .tools, .no-document .zoom, .no-document [aria-label="Undo"], .no-document .download { visibility: hidden; }

/* Space runs out in this order: the zoom buttons (Ctrl+wheel still zooms), the word "Offline"
   (the shield stays), then the tool labels (titles still name them). The plan and Download
   never go. */
@media (max-width: 1400px) {
  .zoom { display: none; }
  .offline { font-size: 0; gap: 0; padding: 5px; }
}
@media (max-width: 1240px) {
  .tool span { display: none; }
  .tool { padding: 0 9px; }
}
@media (max-width: 860px) {
  .file, .offline, .tools-divider, .brand span { display: none; }
  .bar { gap: 8px; padding: 0 10px; }
}

.hint {
  min-height: 36px;
  padding: 8px 16px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  border-bottom: 1px solid var(--bar-border);
  text-align: center;
}
 .hint:empty { display: none; }
.signin-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bar);
  border-bottom: 1px solid var(--bar-border);
  font-size: 13.5px;
}
.signin-banner > svg { color: var(--good); flex: none; }
.signin-banner .icon-button { color: var(--muted); }
.signin-banner .primary { height: 30px; padding: 0 14px; }
.signin-banner .icon-button { width: 28px; height: 28px; }
.hint.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.has-uncovered { outline: 2px solid #d97706 !important; outline-offset: 0; }

/* -- pages --------------------------------------------------------------------------------- */

.workspace { position: relative; min-height: 0; }

.viewer {
  position: absolute;
  inset: 0;
  overflow: auto;
  outline: none;
}
.column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px 24px 80px;
  width: max-content;
  min-width: 100%;
}

.page {
  position: relative;
  background: #fff;
  box-shadow: var(--page-shadow);
  flex: none;
}
.page-canvas { position: absolute; inset: 0; display: block; }
.page-layer { position: absolute; inset: 0; }

.workspace[data-tool="type"] .page-layer { cursor: text; }
.workspace[data-tool="check"] .page-layer,
.workspace[data-tool="cross"] .page-layer,
.workspace[data-tool="dot"] .page-layer,
.workspace[data-tool="date"] .page-layer,
.workspace[data-tool="sign"] .page-layer { cursor: crosshair; }

/* -- form fields ---------------------------------------------------------------------------- */

.field {
  position: absolute;
  margin: 0;
  padding: 0 3px;
  border: 1px solid var(--field-border);
  border-radius: 2px;
  background: var(--field);
  color: var(--ink);
  font-family: Helvetica, Arial, "PDFPane Sans", sans-serif;
  line-height: 1.15;
  outline: none;
  cursor: text;
  height: auto;
}
.field:hover:not(:disabled) { border-color: var(--accent); }
.field:focus, .field:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  background: var(--field-focus);
  z-index: 2;
}
.field:disabled { background: transparent; border-color: transparent; cursor: default; }
.field-required { box-shadow: inset 2px 0 0 #dc2626; }
textarea.field { resize: none; padding-top: 2px; overflow: auto; }
select.field { padding: 0 2px; cursor: pointer; }

.field-checkbox, .field-radio {
  padding: 0;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
}
.field-radio { border-radius: 50%; }
.field-checkbox[aria-checked="true"]::after {
  content: "";
  width: 70%;
  height: 70%;
  background: var(--ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 12.5l5 5L20 6.5' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 12.5l5 5L20 6.5' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.field-radio[aria-checked="true"]::after {
  content: "";
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: var(--ink);
}
.field-signature {
  justify-content: center;
  gap: 6px;
  border-style: dashed;
  color: var(--accent);
  font: 600 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}

/* -- stamps ----------------------------------------------------------------------------------- */

.stamp {
  position: absolute;
  z-index: 3;
  outline: none;
  color: var(--ink);
  touch-action: none;
}
.stamp-image, .stamp-mark { cursor: move; }
.stamp-image img { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.stamp-mark svg { display: block; width: 100%; height: 100%; stroke-width: 2.6; }

.stamp-text { display: flex; }
.stamp-input {
  display: block;
  field-sizing: content;
  min-width: 1.5ch;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-family: "PDFPane Sans", sans-serif;
  line-height: inherit;
  resize: none;
  overflow: hidden;
  white-space: pre;
  outline: none;
}

.stamp:hover, .stamp.selected, .stamp:focus-within { box-shadow: 0 0 0 1px var(--field-border); }
.stamp.selected, .stamp:focus-within { box-shadow: 0 0 0 1.5px var(--accent); }

.stamp-grip {
  position: absolute;
  left: -14px;
  top: 0;
  bottom: 0;
  width: 12px;
  min-height: 14px;
  border-radius: 3px;
  background:
    radial-gradient(circle, var(--muted) 1.2px, transparent 1.5px) 0 0 / 6px 6px;
  opacity: 0;
  cursor: move;
}
.stamp:hover .stamp-grip, .stamp:focus-within .stamp-grip { opacity: 0.7; }

.stamp-tools {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  display: none;
  gap: 2px;
  padding: 3px;
  background: var(--bar);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font: 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.stamp-tools button { height: 26px; padding: 0 7px; border: 0; font-weight: 600; }
.stamp:focus-within .stamp-tools { display: flex; }

/* Both controls sit outside the stamp: over it, they covered most of a 12pt tick, so grabbing the
   tick to move it grabbed the remove button instead. */
.stamp-handle {
  position: absolute;
  right: -13px;
  bottom: -13px;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  background: #fff;
  cursor: nwse-resize;
  display: none;
}
.stamp-remove {
  position: absolute;
  top: -24px;
  right: -24px;
  width: 20px;
  height: 20px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  /* It sits on the page, which is white in either theme, so it keeps light colours: in the
     dark theme it was a black dot with an invisible cross. */
  background: #fff;
  color: #111827;
  border: 1px solid #d1d5db;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  display: none;
}
.stamp.selected .stamp-handle, .stamp:focus .stamp-handle,
.stamp.selected .stamp-remove, .stamp:focus .stamp-remove { display: flex; }

/* -- empty state ------------------------------------------------------------------------------ */

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.drop {
  width: min(560px, 100%);
  padding: 44px 36px 30px;
  text-align: center;
  background: var(--bar);
  border: 2px dashed var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, background 0.15s;
}
body.dragging .drop { border-color: var(--accent); background: var(--accent-soft); }
.drop h1 { margin: 12px 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.drop .muted { margin: 0 0 14px; }
.drop-art {
  display: inline-grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
}
.privacy {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: center;
  margin: 22px auto 0;
  max-width: 400px;
  color: var(--good);
  font-size: 13px;
  text-align: left;
}
.privacy svg { flex: none; margin-top: 2px; }
.price-line { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }

/* -- dialogs ---------------------------------------------------------------------------------- */

dialog {
  border: 0;
  border-radius: 16px;
  padding: 22px;
  background: var(--bar);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 32px);
}
dialog::backdrop { background: rgba(15, 20, 30, 0.45); backdrop-filter: blur(2px); }
dialog h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 18px; }
.small-dialog { width: 460px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-foot .dialog-actions { margin-top: 0; }
.text-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bar);
}
.text-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check-label input { width: 16px; height: 16px; accent-color: var(--accent); }

.plan-now { font-weight: 600; }
.plan-list { margin: 10px 0 18px; padding-left: 20px; color: var(--muted); }
.plan-list li { margin: 4px 0; }
.plan-dialog a.primary { width: 100%; }
.key-message { margin: 8px 0 0; font-size: 13px; }
.key-message.good { color: var(--good); }
.key-message.bad { color: var(--bad); }

/* signature */
.sign-dialog { width: 680px; }
.sign-tabs { display: flex; align-items: center; gap: 4px; margin: 6px 0 12px; }
.sign-tab { border: 0; background: transparent; color: var(--muted); font-weight: 500; }
.sign-tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.sign-inks { margin-left: auto; display: flex; gap: 8px; }
.ink {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--bar);
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--line);
}
.ink[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.sign-panel { position: relative; }
.sign-pad {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
}
.sign-line {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.sign-typed-input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bar); }
.sign-styles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; max-height: 330px; overflow-y: auto; padding: 2px; }
.sign-style {
  position: relative; display: grid; place-items: center; height: 96px; padding: 8px 12px 18px; overflow: hidden;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.sign-style:hover { border-color: var(--accent); }
.sign-style[aria-checked="true"] { border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sign-style-sample { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.7; padding: 0 .35em; color: #111827; }
.sign-style-label { position: absolute; left: 10px; bottom: 5px; font-size: 11px; color: #6b7280; }
.sign-style[aria-checked="true"] .sign-style-label { color: var(--accent); font-weight: 600; }
.sign-drop {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}
.sign-drop:hover { border-color: var(--accent); color: var(--accent); }
.sign-upload-preview { display: block; max-width: 100%; max-height: 180px; margin: 10px auto 0; background: #fff; border-radius: 8px; }
.sign-saved { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.sign-saved-label { width: 100%; color: var(--muted); font-size: 12.5px; }
.sign-saved-wrap { position: relative; }
.sign-saved-item { height: 56px; padding: 6px 10px; background: #fff; }
.sign-saved-item img { max-height: 42px; max-width: 160px; }
.sign-saved-forget {
  position: absolute; top: -8px; right: -8px;
  width: 20px; height: 20px; padding: 0; justify-content: center; border-radius: 50%;
}

/* -- organiser -------------------------------------------------------------------------------- */

.organizer { position: absolute; inset: 0; overflow: auto; }
.organizer[aria-busy="true"] .grid { pointer-events: none; opacity: 0.6; transition: opacity 0.15s 0.1s; }
.organizer-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
}
.organizer-spacer { flex: 1; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 18px;
  padding: 8px 20px 60px;
}
.thumb {
  padding: 10px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--bar);
  box-shadow: var(--shadow);
  cursor: grab;
}
.thumb.chosen { border-color: var(--accent); }
.thumb.dragging-card { opacity: 0.4; }
.thumb.drop-before { box-shadow: -4px 0 0 var(--accent), var(--shadow); }
.thumb.drop-after { box-shadow: 4px 0 0 var(--accent), var(--shadow); }
.thumb-frame {
  display: grid;
  place-items: center;
  width: 100%;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}
.thumb-canvas { width: 100% !important; height: auto !important; display: block; }
.thumb-foot { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.thumb-foot .icon-button { width: 30px; height: 30px; }
.thumb-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.thumb-select { width: 16px; height: 16px; accent-color: var(--accent); }

/* -- toast ------------------------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(640px, calc(100vw - 32px));
  padding: 12px 10px 12px 16px;
  border-radius: 12px;
  background: #1f2937;
  color: #f9fafb;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  border-left: 4px solid #f87171;
}
.toast.info { border-left-color: #60a5fa; }
.toast .icon-button { width: 26px; height: 26px; color: inherit; flex: none; }
.toast[hidden] { display: none; }

a.brand { color: inherit; text-decoration: none; }
.plan-account { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
