/* ==========================================================================
   ARTACE Certificate Generator
   ========================================================================== */

/* ---- Fonts ------------------------------------------------------------- */
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 300; font-display: swap; src: url('/fonts/CormorantGaramond-Light.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: italic; font-weight: 300; font-display: swap; src: url('/fonts/CormorantGaramond-LightItalic.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/CormorantGaramond-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/CormorantGaramond-Medium.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/CormorantGaramond-SemiBold.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/CormorantGaramond-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: italic; font-weight: 400; font-display: swap; src: url('/fonts/CormorantGaramond-Italic.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/Inter-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Lora'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/Lora-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/Inter-Medium.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/Inter-SemiBold.woff2') format('woff2'); }

/* ---- Tokens ------------------------------------------------------------ */
:root {
  --canvas: #ece7de;
  --panel: #ffffff;
  --ink: #1b1b1b;
  --soft: #4a4741;
  --muted: #8c8779;
  --faint: #b9b2a2;
  --gold: #e0b868;
  --gold-deep: #967d4c;
  --card: #f7efe7;
  --mat: #fbf8f2;
  --hair: #e6dfd2;
  --line: #dad3c4;
  --line-soft: #ece6da;
  --paper: #f6f3ef;
  --good: #2e7d5b;
  --bad: #b4443a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Lora', Georgia, serif;
  --shadow: 0 24px 60px -30px rgba(40, 32, 18, 0.45);
  --radius: 14px;
}

/* ---- Base -------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Applied by JS while the session check runs: no issuer UI flash for
   signed-out visitors (matters where pages are served statically). */
body.gated { visibility: hidden; }
body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-weight: 500; margin: 0; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 10px 20px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, border-color .18s ease, opacity .18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--soft); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn-small { padding: 7px 14px; font-size: 12px; }
.btn-tiny { padding: 5px 12px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Topbar ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  height: 40px; width: auto; border-radius: 8px; display: block;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 12px; letter-spacing: 0.22em; }
.brand-text em { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--muted); }

/* ---- Topnav ------------------------------------------------------------ */
.topnav { display: flex; gap: 2px; background: #f4f1ea; border: 1px solid var(--line-soft); border-radius: 999px; padding: 4px; flex: none; }
.topnav a { font-size: 13px; font-weight: 500; padding: 7px 18px; border-radius: 999px; color: var(--soft); white-space: nowrap; }
.topnav a.active { background: var(--ink); color: #fff; }
.topnav a:not(.active):hover { color: var(--ink); }

/* ---- Certificates page ------------------------------------------------- */
.shell.single { grid-template-columns: minmax(0, 1fr); }
.panel.wide { max-width: 1060px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--serif); font-size: 26px; font-weight: 500; }
.page-head .count { font-size: 12px; color: var(--muted); margin-left: 10px; font-family: var(--sans); }
.page-head-actions { display: flex; gap: 10px; }
.search-input {
  font-family: var(--sans); font-size: 13px; color: var(--ink);
  background: #fbfaf7; border: 1px solid var(--line-soft); border-radius: 999px;
  padding: 7px 14px; width: 220px;
}
.search-input:focus { outline: none; border-color: var(--gold); background: #fff; }
.rc-revoked {
  font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--bad); background: rgba(180,68,58,.1); border-radius: 999px;
  padding: 3px 10px; flex: none;
}
li.revoked .rc-title { text-decoration: line-through; color: var(--muted); }
#bulkCsv { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
#bulkResults { margin-top: 14px; }
#certList li { flex-wrap: wrap; row-gap: 10px; }
.rc-issued { font-size: 11px; color: var(--muted); width: 110px; flex: none; }
.edit-panel { margin-top: 24px; border-top: 1px solid var(--line-soft); padding-top: 20px; }
.edit-panel h3 { font-family: var(--serif); font-size: 21px; font-weight: 500; margin: 0 0 4px; }
.edit-panel .form-note { margin-bottom: 14px; }
.thumb-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.thumb-row img { width: 66px; height: 66px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line-soft); }
.thumb-row .hint { color: var(--faint); font-size: 11px; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--line); }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }

/* ---- Shell ------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: 440px minmax(0, 1fr);
  gap: 30px;
  padding: 30px;
  max-width: 1680px;
  margin: 0 auto;
  align-items: start;
}

/* ---- Form panel -------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: 0 18px 40px -34px rgba(40, 32, 18, .5);
  position: sticky;
  top: 92px;
  max-height: calc(100vh - 122px);
  overflow-y: auto;
}
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend {
  font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--gold); font-weight: 600; margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { font-size: 12px; font-weight: 500; color: var(--soft); letter-spacing: 0.01em; }
.req { color: var(--gold); font-weight: 400; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; margin-left: 4px; }
.hint { color: var(--faint); font-weight: 400; font-size: 11px; margin-left: 4px; }
input[type="text"], textarea {
  font-family: var(--sans); font-size: 14px; color: var(--ink);
  background: #fbfaf7;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 11px 13px;
  width: 100%;
  transition: border-color .16s ease, background .16s ease;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--gold); background: #fff; }
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #c3bcac; }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn-primary { flex: 1; }
.form-note { font-size: 12px; color: var(--muted); min-height: 16px; margin: 12px 0 0; }
.form-note.error { color: var(--bad); }
.form-note.ok { color: var(--good); }
.form-note.warn { color: #9a6b1f; }
.layout-warn {
  margin: 0 0 12px; padding: 9px 14px; border-radius: 10px;
  background: rgba(224, 184, 104, 0.14); border: 1px solid var(--gold);
  color: #7d5a17; font-size: 12.5px;
}

/* upload */
.upload { position: relative; }
.upload input[type="file"] { font-size: 12px; color: var(--muted); }
.upload input[type="file"]::file-selector-button {
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  border: 1px solid var(--line); background: #fff; color: var(--soft);
  border-radius: 999px; padding: 7px 14px; margin-right: 12px; cursor: pointer;
}
.upload-preview { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.upload-preview img { width: 66px; height: 66px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line-soft); }

/* ---- Stage ------------------------------------------------------------- */
.stage { min-width: 0; }
.stage-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.stage-head h2 { font-family: var(--serif); font-size: 26px; font-weight: 500; }
.stage-head-actions { display: flex; gap: 10px; }

.cert-wrap { position: relative; width: 100%; }

/* ---- The certificate (mirrors the PDF: 841.89 × 595.28 pt) ------------- */
.cert {
  position: absolute; top: 0; left: 0;
  width: 841.89px; height: 595.28px;
  background: #ffffff;
  transform-origin: top left;
  transform: scale(var(--scale, 0.6));
  box-shadow: var(--shadow);
  border-radius: 2px;
  overflow: hidden;
  color: #1b1b1b;
  font-family: 'Lora', Georgia, serif;
}
.cert .frame-outer { position: absolute; left: 34px; top: 34px; width: 773.89px; height: 527.28px; border: 0.8px solid #dad3c4; }
.cert .frame-inner { position: absolute; left: 43px; top: 43px; width: 755.89px; height: 509.28px; border: 0.4px solid #a9853f; }

/* masthead */
.pv-studio {
  position: absolute; left: 2.3px; top: 69.65px; width: 841.89px; margin: 0;
  text-align: center; font-size: 9.5px; letter-spacing: 4.6px; color: #b9b2a2;
  line-height: 1; white-space: nowrap;
}
.pv-mast {
  position: absolute; left: 0; top: 92.51px; width: 841.89px; margin: 0;
  text-align: center; font-family: var(--serif); font-weight: 300;
  font-size: 11.5px; letter-spacing: normal; color: #8c8779;
  line-height: 1; white-space: nowrap;
}

/* title lines + ornament + statement + facts are positioned from JS */
.pv-title-line {
  position: absolute; left: 0; width: 841.89px; margin: 0;
  text-align: center; font-family: var(--serif); font-weight: 300; color: #1b1b1b;
  line-height: 1; white-space: nowrap;
}
.pv-orn-dash { position: absolute; height: 0; border-top: 0.8px solid #d8c4a0; }
.pv-orn-dot { position: absolute; width: 3.8px; height: 3.8px; border-radius: 50%; background: #a9853f; }
.pv-stmt-line {
  position: absolute; margin: 0; font-size: 10.5px; color: #4a4741; line-height: 1;
  white-space: nowrap;
}
.pv-fact-lab {
  position: absolute; margin: 0; font-size: 7.6px; letter-spacing: 1.6px;
  color: #b9b2a2; line-height: 1; white-space: nowrap;
}
.pv-fact-val {
  position: absolute; margin: 0; font-family: var(--serif); font-weight: 300;
  font-size: 14px; color: #1b1b1b; line-height: 1; white-space: nowrap;
}

/* artwork branch */
.pv-art { position: absolute; left: 108px; top: 270.288px; width: 112.99px; height: 112.99px; margin: 0; background: #fbfaf7; border: 0.7px solid #d8c4a0; }
.pv-art img { position: absolute; left: 7px; top: 7px; width: 98.99px; height: 98.99px; object-fit: contain; }
.pv-art #pvArtPending {
  position: absolute; left: 7px; top: 7px; width: 98.99px; height: 98.99px;
  display: grid; place-items: center; text-align: center;
  font-size: 8px; letter-spacing: 0.08em; color: #8c8779; line-height: 1.5;
}
.pv-art figcaption {
  position: absolute; left: 25.55px; top: 121.69px; margin: 0;
  font-size: 8px; letter-spacing: 2.4px; color: #b9b2a2; line-height: 1; white-space: nowrap;
}

/* signature block (fixed) */
.pv-signame {
  position: absolute; left: 84px; top: 427.28px; margin: 0;
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 25px; color: #1b1b1b; line-height: 1; white-space: nowrap;
}
.pv-sigrule { position: absolute; left: 84px; top: 467.28px; width: 250px; height: 0; border-top: 0.7px solid #dad3c4; }
.pv-sigcaps {
  position: absolute; left: 84.8px; top: 474.96px; margin: 0;
  font-size: 8.5px; letter-spacing: 1.6px; color: #4a4741; line-height: 1; white-space: nowrap;
}
.pv-sigrole {
  position: absolute; left: 84px; top: 487.96px; margin: 0;
  font-size: 8.5px; color: #8c8779; line-height: 1; white-space: nowrap;
}

/* QR card (fixed) */
.pv-qrcard { position: absolute; left: 669.89px; top: 419.28px; width: 94px; height: 94px; border: 0.6px solid #dad3c4; }
.pv-qrcard img { position: absolute; left: 6px; top: 6px; width: 82px; height: 82px; }
.pv-qrcap {
  position: absolute; left: 669.89px; top: 518.96px; width: 94px; margin: 0;
  text-align: center; font-size: 8.5px; color: #8c8779; line-height: 1.3;
}
.pv-qrid {
  position: absolute; left: 670.59px; top: 531.98px; width: 94px; margin: 0;
  text-align: center; font-size: 8px; letter-spacing: 1.4px; color: #b9b2a2; line-height: 1;
}

/* ---- Result ------------------------------------------------------------ */
.result {
  margin-top: 22px; background: #fff; border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 20px 22px;
}
.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.result-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(46,125,91,.14); }
.result-head strong { font-size: 14px; font-weight: 600; }
.result-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.result-key { width: 130px; flex: none; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.result-row code { font-family: var(--sans); font-size: 13px; color: var(--soft); background: #fbfaf7; border: 1px solid var(--line-soft); border-radius: 8px; padding: 5px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---- Recent ------------------------------------------------------------ */
.recent { margin-top: 26px; }
.recent-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.recent-head h3 { font-family: var(--serif); font-size: 20px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent-list li {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px 16px;
}
.recent-list .rc-id { font-size: 11px; font-weight: 600; letter-spacing: .08em; color: var(--gold); width: 130px; flex: none; }
.recent-list .rc-title { font-family: var(--serif); font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list .rc-artist { font-size: 12px; color: var(--muted); width: 140px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list .rc-actions { display: flex; gap: 8px; flex: none; }
.recent-empty { color: var(--muted); font-size: 13px; padding: 14px 0; }

/* ---- Verify page ------------------------------------------------------- */
.verify-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 20px; }
.verify-card {
  width: 100%; max-width: 620px; background: #fff; border: 1px solid var(--line-soft);
  border-radius: 18px; padding: 36px; box-shadow: var(--shadow);
}
.verify-card.wide { max-width: 1020px; padding: 32px; max-height: calc(100vh - 48px); overflow: auto; }
.verify-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 32px; align-items: start; }
.verify-layout.no-media { grid-template-columns: 1fr; }
.verify-media { min-width: 0; }
.verify-media img {
  width: 100%; height: auto; max-height: calc(100vh - 140px); object-fit: contain;
  border-radius: 12px; border: 1px solid var(--line-soft); background: #fbfaf7;
  display: block;
}
.verify-info { min-width: 0; }
.verify-thumbs { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.verify-thumbs img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line-soft); cursor: pointer; background: #fbfaf7;
}
.verify-thumbs img.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.verify-check { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.verify-check h2 { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 0 0 6px; }
.verify-check p { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; line-height: 1.6; }
.verify-check input { font-size: 12px; color: var(--muted); max-width: 100%; }
.verify-check .ok { color: var(--good); font-weight: 600; }
.verify-check .bad { color: var(--bad); font-weight: 600; }
.verify-badge { display: inline-flex; align-items: center; gap: 10px; padding: 7px 15px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.verify-badge.valid { background: rgba(46,125,91,.1); color: var(--good); }
.verify-badge.invalid { background: rgba(180,68,58,.1); color: var(--bad); }
.verify-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.verify-title { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 16px 0 4px; line-height: 1.15; }
.verify-artist { font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.verify-artist em { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--soft); }
.verify-statement { font-size: 13.5px; line-height: 1.65; color: var(--soft); margin: 0 0 16px; }
.verify-grid { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0 0 16px; }
.verify-grid > div {
  display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 4px 12px; align-items: baseline;
  border-top: 1px solid var(--line-soft); padding: 7px 0;
}
.verify-grid dt { font-size: 10px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }
.verify-grid dd { margin: 0; font-family: var(--serif); font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.verify-note { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line-soft); padding-top: 14px; line-height: 1.6; }
.verify-lookup { margin-top: 24px; display: flex; gap: 10px; }
.verify-lookup input { flex: 1; min-width: 0; font-family: var(--sans); font-size: 14px; padding: 11px 13px; border: 1px solid var(--line-soft); border-radius: 10px; background: #fbfaf7; }
.verify-lookup input:focus { outline: none; border-color: var(--gold); background: #fff; }
.verify-muted { color: var(--muted); font-size: 14px; }
.spinner { width: 26px; height: 26px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive -------------------------------------------------------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .shell { padding: 18px; gap: 20px; }
  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar-actions { display: flex; gap: 8px; }
  .topbar-actions .btn { padding: 7px 12px; font-size: 12px; }
  .brand-text { display: none; }
  .topnav a { padding: 6px 12px; font-size: 12px; }
  .page-head-actions { width: 100%; }
  .search-input { flex: 1; width: auto; }
  .verify-shell { padding: 14px 10px; }
  .verify-card { padding: 24px 20px; border-radius: 14px; }
  .verify-card.wide { padding: 22px 18px; max-height: none; }
  .verify-layout { grid-template-columns: 1fr; gap: 18px; }
  .verify-media img { max-height: 34vh; }
  .verify-title { font-size: 25px; margin-top: 12px; }
  .verify-grid > div { grid-template-columns: 104px minmax(0, 1fr); }
  .verify-grid dd { font-size: 15px; }
  .verify-lookup { flex-direction: column; }
  .verify-lookup .btn { width: 100%; }
}
