/* Certificate Builder
   A light desk with white sheets on it. Lime is the working colour: it marks
   what you can press and where a value will land on the certificate. */

@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }

:root {
  --ink: #1b2414;
  --ink-soft: #55604b;
  --desk: #e7ebe0;
  --desk-deep: #d6dccb;
  --paper: #ffffff;
  --rule: #c9d1bd;
  --lime: #96cf28;
  --lime-press: #86bd1d;
  --lime-ink: #456d05;
  --lime-wash: #eef7d9;
  --date: #2456c9;
  --date-wash: #e3ebfb;
  --image: #a8530a;
  --image-wash: #fbecd9;
  --danger: #b3261e;
  --sheet-shadow: 0 0 0 1px #c3cbb6, 0 14px 28px -18px rgba(27, 36, 20, .55);
  --sans: "Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Plex Mono", ui-monospace, Consolas, monospace;
  --top: 52px;
  --foot: 44px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--desk); color: var(--ink);
  font: 400 15px/1.45 var(--sans);
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
a { color: var(--lime-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.muted { color: var(--ink-soft); }
.loading { padding: 48px 24px; color: var(--ink-soft); }

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

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-lg { font-size: 18px; margin-bottom: 22px; }
.brand-mark {
  width: 16px; height: 20px; background: var(--lime); border: 1.5px solid var(--ink); flex: none;
  clip-path: polygon(0 0, 62% 0, 100% 30%, 100% 100%, 0 100%);
}
.topbar-nav { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; color: var(--ink-soft); font-size: 14px; }
.topbar-nav a { color: var(--ink-soft); text-decoration: none; }
.topbar-nav a:hover { color: var(--ink); text-decoration: underline; }
.topbar-nav .here { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.topbar-nav .sep { color: var(--rule); }
.topbar-actions { display: flex; gap: 4px; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--lime); border-color: #6f9f12; }
.btn-primary:hover { background: var(--lime-press); border-color: var(--lime-ink); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-quiet:hover { border-color: transparent; background: var(--desk); color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.field .hint { display: block; font-size: 12.5px; font-weight: 400; color: var(--ink-soft); margin-top: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--paper);
}
textarea { min-height: 76px; resize: vertical; line-height: 1.4; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-soft); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--ink); }
input[type="color"] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--lime-ink); flex: none; }
.check .hint { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.is-missing input, .is-missing textarea, .is-missing select { border-color: var(--danger); }
.form-error { color: var(--danger); font-size: 14px; margin-bottom: 14px; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 12px; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- sign-in ---------- */

.gate { align-items: center; justify-content: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--paper); padding: 32px 30px 30px; box-shadow: var(--sheet-shadow); }
.gate-card h1 { font-size: 22px; margin-bottom: 10px; }
.gate-card p.muted { font-size: 14px; margin-bottom: 18px; }
.gate-card form { margin-top: 18px; }

.credit { height: var(--foot); padding: 0 20px; display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; color: var(--ink-soft); flex: none; }
.credit a { color: var(--ink); font-weight: 500; text-decoration-color: var(--lime); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.gate .credit { margin-top: 18px; }

/* ---------- templates ---------- */

.app { flex: 1; min-width: 0; }
.home { max-width: 1120px; margin: 0 auto; padding: 36px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--ink-soft); margin-top: 6px; max-width: 60ch; }

.drop {
  border: 1.5px dashed #a9b39a; border-radius: 8px; padding: 22px 20px; margin-bottom: 30px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: rgba(255, 255, 255, .45);
}
.drop.is-over { border-color: var(--lime-ink); background: var(--lime-wash); }
.drop.is-first { padding: 44px 28px; flex-direction: column; align-items: flex-start; }
.drop.is-first h2 { font-size: 20px; }
.drop p { color: var(--ink-soft); max-width: 62ch; }
.drop ol { margin: 14px 0 20px; padding-left: 20px; color: var(--ink-soft); max-width: 62ch; }
.drop ol li { margin-bottom: 4px; }

.shelf { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 34px 26px; }
.sheet {
  display: block; position: relative; aspect-ratio: 210 / 270; overflow: hidden;
  background: var(--paper); box-shadow: var(--sheet-shadow); text-decoration: none; color: var(--ink);
}
.sheet img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.sheet-text { padding: 16px 14px; font-size: 7.5px; line-height: 1.6; color: #6c7563; word-break: break-word; }
.sheet-kind {
  position: absolute; left: 0; bottom: 12px; padding: 2px 8px 2px 10px;
  background: var(--ink); color: #fff; font-size: 11.5px; font-weight: 500;
}
.sheet:hover { box-shadow: 0 0 0 1.5px var(--ink), 0 14px 28px -18px rgba(27, 36, 20, .55); }
.shelf h3 { font-size: 15px; font-weight: 600; margin-top: 12px; overflow-wrap: anywhere; }
.shelf .meta { font-size: 13px; color: var(--ink-soft); margin: 2px 0 8px; }
.shelf .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- workspace (mapping and filling) ---------- */

.work { display: grid; height: calc(100vh - var(--top) - var(--foot)); height: calc(100dvh - var(--top) - var(--foot)); min-height: 480px; border-bottom: 1px solid var(--rule); }
.work-map { grid-template-columns: 250px minmax(0, 1fr) 300px; grid-template-rows: auto minmax(0, 1fr); }
.work-fill { grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); }
.bar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px; background: var(--paper); border-bottom: 1px solid var(--rule);
}
.bar .name { flex: 1; min-width: 160px; max-width: 360px; font-weight: 600; }
.bar .gap { flex: 1; }
.bar .note { font-size: 13px; color: var(--ink-soft); }
.bar .note.is-dirty { color: var(--image); }

.side { background: var(--paper); overflow-y: auto; min-height: 0; }
.side-left { border-right: 1px solid var(--rule); }
.side-right { border-left: 1px solid var(--rule); padding: 16px; }
.side h2 { font-size: 14px; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 14px 8px; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.side-head .count { font-size: 13px; color: var(--ink-soft); }

.review { margin: 0 10px 10px; padding: 10px 12px; background: var(--lime-wash); border-left: 3px solid var(--lime); font-size: 13px; }
.review .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.flist { list-style: none; margin: 0; padding: 0 6px 16px; }
.flist button {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 7px 8px; border: 0; border-radius: 5px; background: none; cursor: pointer; font-size: 14px;
}
.flist button:hover { background: var(--desk); }
.flist button[aria-current="true"] { background: var(--ink); color: #fff; }
.flist .lab { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flist .tag { font-size: 11.5px; color: var(--ink-soft); flex: none; }
.flist button[aria-current="true"] .tag { color: #c9d1bd; }
.dot { width: 9px; height: 9px; flex: none; background: var(--lime); border: 1px solid var(--lime-ink); }
.dot.t-date { background: var(--date); border-color: var(--date); border-radius: 50%; }
.dot.t-image { background: var(--image); border-color: var(--image); transform: rotate(45deg) scale(.85); }
.dot.is-new { background: transparent; border-style: dashed; }
.flist-empty { padding: 6px 14px 16px; font-size: 13.5px; color: var(--ink-soft); }

.props h2 { margin-bottom: 14px; }
.props .key { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); margin: -8px 0 14px; overflow-wrap: anywhere; }
.props fieldset { border: 0; border-top: 1px solid var(--rule); margin: 16px 0 0; padding: 14px 0 0; }
.props legend { padding: 0; font-size: 13px; font-weight: 600; float: left; width: 100%; margin-bottom: 10px; }
.props legend + * { clear: both; }
.props fieldset > small.hint { display: block; margin: -2px 0 12px; font-size: 12.5px; color: var(--ink-soft); }
.props .acts { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.pill-keys { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.pill-keys button { border: 1px solid var(--rule); background: var(--paper); border-radius: 4px; padding: 2px 7px; font-size: 12.5px; cursor: pointer; }
.pill-keys button:hover { border-color: var(--ink); }

.stage { overflow: auto; min-height: 0; padding: 28px 28px 60px; position: relative; }
.stage.is-adding, .stage.is-adding .layer { cursor: crosshair; }
.stage.is-adding .docx-wrapper p { cursor: text; }
.stage-msg { max-width: 56ch; margin: 40px auto; text-align: center; color: var(--ink-soft); }

/* PDF pages and field boxes */
.pg { position: relative; margin: 0 auto 26px; background: var(--paper); box-shadow: var(--sheet-shadow); width: fit-content; }
.pg canvas { display: block; }
.pg .layer { position: absolute; inset: 0; touch-action: none; }
.fbox {
  position: absolute; display: flex; overflow: hidden; cursor: move; user-select: none;
  background: rgba(150, 207, 40, .26); outline: 1.5px solid #5f8f0c; outline-offset: -1px;
  color: #2b4203; line-height: 1.15; white-space: nowrap;
}
.fbox span { pointer-events: none; padding: 0 1px; overflow: hidden; text-overflow: clip; width: 100%; }
.fbox.t-date { background: rgba(36, 86, 201, .16); outline-color: var(--date); color: #173a8c; }
.fbox.t-image { background: rgba(168, 83, 10, .14); outline-color: var(--image); color: #6f3604; }
.fbox.is-new { outline-style: dashed; }
.fbox.is-selected { outline: 2px solid var(--ink); z-index: 3; overflow: visible; }
.fbox.is-selected span { overflow: hidden; }
.fbox .h { position: absolute; width: 10px; height: 10px; background: var(--paper); border: 2px solid var(--ink); display: none; }
.fbox.is-selected .h { display: block; }
.h.nw { left: -6px; top: -6px; cursor: nwse-resize; } .h.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.h.sw { left: -6px; bottom: -6px; cursor: nesw-resize; } .h.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.h.e { right: -6px; top: calc(50% - 5px); cursor: ew-resize; } .h.w { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.draw-box { position: absolute; outline: 1.5px dashed var(--ink); background: rgba(150, 207, 40, .2); pointer-events: none; }

/* Word pages and field chips */
.docx-host { width: fit-content; margin: 0 auto; }
.docx-host .docx-wrapper { background: transparent; padding: 0; display: block; }
.docx-host .docx-wrapper > section.docx { box-shadow: var(--sheet-shadow); margin: 0 auto 26px; }
.cb-chip {
  display: inline-block; padding: 0 5px; margin: 0 1px; border-radius: 3px; cursor: pointer;
  background: rgba(150, 207, 40, .32); outline: 1.5px solid #5f8f0c; outline-offset: -1px; color: #2b4203;
  font-style: normal; text-decoration: none; text-indent: 0; white-space: nowrap; line-height: 1.25;
}
.cb-chip.cb-type-date { background: rgba(36, 86, 201, .16); outline-color: var(--date); color: #173a8c; }
.cb-chip.cb-type-image { background: rgba(168, 83, 10, .14); outline-color: var(--image); color: #6f3604; }
.cb-chip.is-suggested { outline-style: dashed; }
.cb-chip.is-selected { outline: 2px solid var(--ink); background: var(--ink); color: #fff; }
.sel-btn { position: fixed; z-index: 40; box-shadow: 0 6px 18px -8px rgba(27, 36, 20, .6); }

/* Fill form and preview */
.fill-form { padding: 20px 20px 28px; }
.fill-form h1 { font-size: 20px; margin-bottom: 4px; }
.fill-form .lede { color: var(--ink-soft); font-size: 14px; margin-bottom: 20px; }
.fill-form .field > span em { font-style: normal; color: var(--danger); }
.fill-form .auto { font-size: 12.5px; color: var(--date); margin-top: 4px; display: block; }
.fill-foot { border-top: 1px solid var(--rule); margin-top: 20px; padding-top: 18px; }
.img-pick { display: flex; align-items: center; gap: 10px; }
.img-pick img { max-width: 90px; max-height: 44px; border: 1px solid var(--rule); background: #fff; }
.history { margin-top: 22px; font-size: 14px; }
.history summary { cursor: pointer; font-weight: 500; }
.history ul { list-style: none; padding: 0; margin: 10px 0 0; }
.history li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--rule); }
.history li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history li small { color: var(--ink-soft); flex: none; }

/* ---------- dialogs and toasts ---------- */

.dialog { border: 0; padding: 24px; width: min(440px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); box-shadow: 0 30px 60px -20px rgba(27, 36, 20, .6); }
.dialog::backdrop { background: rgba(27, 36, 20, .45); }
.dialog-title { font-size: 18px; margin-bottom: 14px; }
.dialog-body p { color: var(--ink-soft); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 14px; max-width: min(520px, calc(100vw - 32px)); transition: opacity .2s; }
.toast-error { background: var(--danger); }
.toast-out { opacity: 0; }

/* ---------- smaller screens ---------- */

@media (max-width: 1080px) {
  .work-map { grid-template-columns: 210px minmax(0, 1fr) 270px; }
}
@media (max-width: 860px) {
  .work { height: auto; display: block; }
  .side-left, .side-right { border: 0; border-bottom: 1px solid var(--rule); max-height: 44vh; }
  .stage { padding: 16px 12px 40px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar-nav { display: none; }
  .topbar-actions { margin-left: auto; }
  .home { padding: 24px 16px 40px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 26px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
