/* ===================================================================
   Certificate Generator — styles
   Two parts:  (A) the app/control-panel UI   (B) the certificate itself
   The certificate uses CSS variables so themes can swap colours live.
   =================================================================== */

:root {
  --ink: #1d1f23;
  --muted: #6b7280;
  --line: #e3e7ec;
  --panel: #ffffff;
  --bg: #eef1f5;
  --accent: #4c64c6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: 100vh;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 28px 26px 40px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.brand {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 0 4px;
}
.brand h1 { font-size: 19px; letter-spacing: -.01em; margin: 0; }
.brand span { font-size: 12px; color: var(--muted); }
.subtitle { color: var(--muted); font-size: 13px; margin: 0 0 26px; }

.field { margin-bottom: 20px; }
.field > label {
  display: block; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin-bottom: 7px;
}

input[type="text"], input[type="date"], select {
  width: 100%; padding: 11px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* new-award inline input */
.new-award { display: none; margin-top: 9px; }
.new-award.show { display: block; }

/* theme swatches */
.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  border: 2px solid transparent; position: relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.swatch.active { border-color: var(--ink); }
.swatch::after {
  content: attr(data-label); position: absolute; bottom: -20px; left: 50%;
  transform: translateX(-50%); white-space: nowrap; font-size: 10px;
  color: var(--muted); opacity: 0; transition: opacity .15s; pointer-events: none;
}
.swatch:hover::after { opacity: 1; }

/* the "custom" swatch shows a multi-colour gradient */
.swatch.custom-swatch {
  background: conic-gradient(#e0364f, #e8a13a, #2fa36b, #3b6fe0, #7d4ec6, #e0364f);
}

/* custom-colour panel (hidden until the custom swatch is chosen) */
.custom-theme { display: none; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.custom-theme.show { display: block; }
.custom-row { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.custom-label { width: 78px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.custom-row input[type="color"] {
  width: 36px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; cursor: pointer; flex-shrink: 0;
}
.hex-input {
  width: 92px; padding: 7px 9px; font-size: 13px; font-family: ui-monospace, monospace;
  border: 1px solid var(--line); border-radius: 8px; text-transform: lowercase;
}
.hex-input:focus { outline: none; border-color: var(--accent); }

/* logo upload */
.logo-row { display: flex; align-items: center; gap: 12px; }
.logo-thumb {
  width: 84px; height: 46px; border: 1px solid var(--line); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; background: #fff;
  overflow: hidden;
}
.logo-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.btn-sub {
  font-size: 13px; padding: 9px 13px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; cursor: pointer; font-family: inherit;
}
.btn-sub:hover { border-color: var(--accent); color: var(--accent); }

.actions { margin-top: 28px; display: flex; flex-direction: column; gap: 10px; }
.btn-primary {
  width: 100%; padding: 13px; font-size: 14.5px; font-weight: 600;
  border: none; border-radius: 11px; cursor: pointer; color: #fff;
  background: var(--ink); font-family: inherit; transition: transform .05s, opacity .15s;
}
.btn-primary:hover { opacity: .92; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .5; cursor: progress; }

/* ---------- Preview stage ---------- */
.stage {
  padding: 40px; display: flex; align-items: flex-start; justify-content: center;
}
.stage-inner { width: 100%; max-width: 1000px; }
.stage-tip { text-align: center; color: var(--muted); font-size: 12.5px; margin: 14px 0 0; }

/* The certificate is rendered at a FIXED pixel size (A4 landscape ratio)
   then scaled to fit the screen. Fixed size keeps PDF export pixel-accurate. */
.cert-scale { transform-origin: top center; }

.cert {
  --c-primary: #4c64c6;
  --c-primary-dk: #2b3d8c;
  --c-charcoal: #29292b;
  --c-gray: #73767d;
  --c-lgray: #e2e5e9;
  --c-lgray2: #f2f4f6;
  --c-dot: #d1d6dd;

  width: 1123px; height: 794px;     /* A4 landscape @ ~96dpi */
  background: var(--c-lgray2);
  position: relative;
  font-family: "Inter", Arial, sans-serif;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cert .sheet { position: absolute; inset: 24px; background: #fff; }

/* corner diagonal accents (SVG polygons — render reliably in html2canvas) */
.cert .corner { position: absolute; width: 320px; height: 210px; }
.cert .corner svg { width: 100%; height: 100%; display: block; }
.cert .tl { top: 0; left: 0; }
.cert .br { bottom: 0; right: 0; transform: rotate(180deg); }
.cert .l1   { fill: var(--c-charcoal); }
.cert .l2   { fill: var(--c-primary); }
.cert .l3   { fill: var(--c-primary-dk); }
.cert .soft { fill: var(--c-lgray); opacity: .35; }

/* frame */
.cert .frame1 { position:absolute; inset:40px; border:1px solid var(--c-lgray); }
.cert .frame2 { position:absolute; inset:46px; border:1.6px solid var(--c-primary); }

/* dotted patterns */
.cert .dots { position: absolute; width: 64px; height: 46px;
  background-image: radial-gradient(var(--c-dot) 1.1px, transparent 1.1px);
  background-size: 9px 9px; }
.cert .dots.tl { left: 64px; bottom: 78px; }
.cert .dots.br { right: 64px; top: 78px; }

/* logo */
.cert .logo { position: absolute; top: 56px; right: 64px; height: 64px; }
.cert .logo img { height: 100%; object-fit: contain; }

/* text content */
.cert .content { position: absolute; inset: 0; text-align: center; }
.cert .h-main {
  position:absolute; top:118px; left:0; right:0;
  font-weight: 800; font-size: 64px; letter-spacing: .02em; color: var(--c-charcoal);
}
.cert .h-sub {
  position:absolute; top:200px; left:0; right:0;
  font-weight: 700; font-size: 22px; letter-spacing: .42em; color: var(--c-primary);
}
.cert .rule-c {
  position:absolute; top:240px; left:50%; transform:translateX(-50%);
  width: 190px; height: 0; border-top: 1.6px solid var(--c-primary);
}
.cert .presented {
  position:absolute; top:280px; left:0; right:0;
  font-size: 15px; letter-spacing: .28em; color: var(--c-gray);
}
.cert .name {
  position:absolute; top:320px; left:0; right:0;
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-size: 56px; color: var(--c-charcoal); line-height: 1.05;
}
.cert .rule-name {
  position:absolute; top:412px; left:50%; transform:translateX(-50%);
  width: 440px; border-top: 1px solid var(--c-lgray);
}
.cert .award {
  position:absolute; top:430px; left:0; right:0;
  font-weight: 700; font-size: 22px; color: var(--c-primary);
}
.cert .body {
  position:absolute; top:480px; left:50%; transform:translateX(-50%);
  width: 720px; font-size: 15px; line-height: 1.55; color: var(--c-gray);
}
/* signature block */
.cert .sig { position:absolute; bottom: 70px; left:0; right:0; }
.cert .sig .rule-top { width: 60px; border-top: 1px solid var(--c-primary); margin: 0 auto 6px; }
.cert .sig .script {
  font-family: "Allura", "Brush Script MT", cursive; font-size: 46px;
  color: var(--c-charcoal); line-height: .8;
}
.cert .sig .rule { width: 230px; border-top: 1px solid var(--c-charcoal); margin: 4px auto 8px; }
.cert .sig .sname { font-weight: 700; font-size: 15px; color: var(--c-charcoal); }
.cert .sig .desig { font-size: 13px; color: var(--c-gray); margin-top: 2px; }
.cert .sig .date  { font-size: 13px; color: var(--c-gray); margin-top: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .panel { height: auto; position: relative; border-right: none; border-bottom: 1px solid var(--line); }
  .stage { padding: 20px; }
}
