:root {
  --navy: #0B2A5C;
  --blue: #1B6AC9;
  --ice: #E8F1FB;
  --ink: #1C1C2E;
  --gray: #869791;
  --ok: #2E7D46;
  --ok-bg: #E9F6EC;
  --err: #B3261E;
  --err-bg: #FBEAEA;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Karla', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  color: var(--ink);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 6vw;
  border-bottom: 1px solid #eee;
}
header img { height: 56px; }
header .tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray);
}
header .hdr-nav { display: flex; align-items: center; gap: 20px; }
header .hdr-nav a {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
}
header .hdr-nav a:hover { text-decoration: underline; }

main { max-width: 1240px; margin: 0 auto; padding: 40px 6vw 90px; }
main.wide-tab { max-width: none; padding-left: 2vw; padding-right: 2vw; }
h1 { font-size: 26px; color: var(--navy); margin: 0 0 6px; }
.sub { color: #5b6b85; font-size: 14.5px; margin: 0 0 32px; }

/* password gate */
#gate { max-width: 560px; margin: 0 auto; }
.card {
  background: var(--ice);
  border: 1px solid #d7e5f6;
  border-radius: 4px;
  padding: 28px;
}
label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--navy);
  margin: 16px 0 6px;
}
label:first-child { margin-top: 0; }
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid #c3d5ec;
  border-radius: 3px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
button {
  margin-top: 22px;
  padding: 12px 22px;
  border: none;
  border-radius: 3px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  font-family: inherit;
}
button:hover { background: var(--navy); }
button:disabled { opacity: 0.6; cursor: default; }
button.secondary { background: #fff; color: var(--navy); border: 1.5px solid var(--navy); margin-left: 10px; }

.msg { margin-top: 16px; padding: 14px 16px; border-radius: 3px; font-size: 14px; display: none; }
.msg.show { display: block; }
.msg.ok { background: var(--ok-bg); border: 1.5px solid var(--ok); color: #163d22; }
.msg.err { background: var(--err-bg); border: 1.5px solid var(--err); color: #5c1712; }

[hidden] { display: none !important; }

/* tabs: "Nummer registrieren" vs. "Urkunde direkt erstellen" */
.tabs {
  display: flex;
  gap: 22px;
  margin-bottom: 26px;
  border-bottom: 2px solid #eee;
}
.tab-btn {
  margin: 0;
  padding: 0 2px 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--gray);
  font-weight: 700;
  font-size: 14.5px;
  font-family: inherit;
  cursor: pointer;
}
.tab-btn:hover { color: var(--navy); background: none; }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--blue); }

/* certificate preview / print area */
#result { margin-top: 36px; }
#result h2, #registerResult h2 { font-size: 16px; color: var(--navy); margin: 0 0 14px; }

/* Ehrenamtsurkunde — A4-Hochformat, layout aus assets/Vorlage_Ehrenamtsurkunde.docx.
   Die Urkunde hat feste physische Maße (210mm x 297mm) und wird über
   transform:scale() an die verfügbare Breite der Vorschau angepasst
   (siehe scaleCertificatePreview() im Script). Wichtig: font-size in %
   bezieht sich in CSS auf die Schriftgröße des Elternelements, NICHT auf
   die Breite des Containers — deshalb feste pt-Werte statt %, sonst
   stimmen die Größen beim Drucken/Exportieren nicht. */
.cert-scale-wrap { position: relative; width: 100%; overflow: hidden; }
.certificate {
  position: absolute;
  top: 0; left: 0;
  width: 210mm;
  height: 297mm;
  transform-origin: top left;
  background: #fff;
  border: 1px solid #ddd;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.cert-inner {
  position: absolute;
  inset: 0;
  padding: 6% 9% 16%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.cert-logo { height: 8%; margin-bottom: 5%; }
.cert-line { font-size: 11pt; line-height: 1.5; color: var(--ink); margin-bottom: 8pt; }
.cert-title { font-size: 28pt; font-weight: 800; letter-spacing: 0.01em; text-transform: uppercase; color: var(--navy); margin: 0 0 5%; }
.cert-bracket-role { font-size: 16pt; font-weight: 800; color: var(--ink); margin-bottom: 8pt; }
.cert-name { font-size: 30pt; font-weight: 800; color: var(--ink); line-height: 1.15; margin: 2% 0 2%; }
.cert-amtsjahr-label { font-size: 9.5pt; font-weight: 700; color: var(--ink); margin-top: 2%; margin-bottom: 3pt; }
.cert-amtsjahr-value { font-size: 13pt; font-weight: 800; color: var(--ink); margin-bottom: 5%; }
.cert-body { align-self: stretch; font-size: 10pt; line-height: 1.55; color: #222; text-align: justify; margin-bottom: 4%; }
.cert-body p { margin: 0 0 0.9em; }
.cert-body p:last-child { margin-bottom: 0; }
.cert-date { align-self: stretch; text-align: left; font-size: 10pt; font-weight: 800; color: var(--ink); }
.cert-signatures { align-self: stretch; display: flex; justify-content: space-between; gap: 6%; margin-top: 8%; }
.cert-signature { flex: 1; font-size: 10pt; line-height: 1.5; }
.cert-signature .name { font-weight: 800; margin-bottom: 2px; }
.cert-footer-row {
  position: absolute;
  left: 9%; right: 9%; bottom: 3.5%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}
.cert-footer-legal { flex: 1; font-size: 7pt; line-height: 1.5; color: #666; text-align: left; }
.cert-qr-corner { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cert-qr-corner .qr { background: #fff; line-height: 0; }
.cert-qr-corner .nr { font-size: 6pt; color: #888; letter-spacing: 0.02em; white-space: nowrap; }

/* result card for the "nur Nummer registrieren" flow */
.number-card { text-align: center; }
.number-card .number-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 8px;
}
.number-card .number-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: 0.02em;
  margin-bottom: 18px;
}
.number-card .qr-box {
  display: inline-flex;
  background: #fff;
  padding: 6px;
  border: 1px solid #d7e5f6;
  border-radius: 3px;
  margin-bottom: 6px;
}

.actions { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 10px; }

/* Formularfeld-Paare nebeneinander (z. B. Amtsjahr von/bis, Aussteller 1/2) */
.field-row { display: flex; gap: 14px; }
.field-row > div { flex: 1; min-width: 0; }

.char-hint { margin-top: 6px; font-size: 12px; color: var(--gray); text-align: right; }
.char-hint.over { color: var(--err); font-weight: 700; }

/* dynamische Aussteller-Liste ("+ Aussteller hinzufügen") */
.aussteller-row { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.aussteller-row input, .aussteller-row select { flex: 1; min-width: 140px; }
.aussteller-row .remove-btn {
  flex-shrink: 0;
  margin-top: 0;
  padding: 0 12px;
  background: #fff;
  color: var(--err);
  border: 1.5px solid #e3b9b6;
  font-size: 18px;
  line-height: 1;
}
.aussteller-row .remove-btn:hover { background: var(--err-bg); }
.add-btn { margin-top: 4px; background: #fff; color: var(--navy); border: 1.5px dashed #c3d5ec; padding: 9px 16px; font-size: 13.5px; }
.add-btn:hover { background: var(--ice); }

/* Aussteller-Spalten nebeneinander (Tab "Urkunde direkt erstellen"), 1-3 Stück */
.aussteller-col { position: relative; }
.aussteller-col .col-remove {
  position: absolute;
  top: -9px; right: -9px;
  width: 22px; height: 22px;
  margin: 0; padding: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--err);
  border: 1.5px solid #e3b9b6;
  font-size: 14px;
  line-height: 1;
}
.aussteller-col .col-remove:hover { background: var(--err-bg); }
.aussteller-col .col-remove[hidden] { display: none; }

.file-hint { margin-top: 6px; font-size: 12.5px; color: var(--gray); }
.file-hint a { color: var(--blue); }
.file-hint a:hover { color: var(--navy); }

a.secondary {
  display: inline-block;
  margin-top: 22px;
  padding: 12px 22px;
  border-radius: 3px;
  background: #fff;
  color: var(--navy);
  border: 1.5px solid var(--navy);
  font-weight: 700;
  font-size: 14.5px;
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
}
a.secondary:hover { background: var(--ice); }

/* Urkunden-Übersicht (Tab "Urkunden verwalten") */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid #eee; text-align: left; }
.data-table th {
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.data-table td:first-child { font-weight: 700; white-space: nowrap; }
.data-table .row-delete-btn {
  margin-top: 0;
  padding: 6px 12px;
  font-size: 12.5px;
  background: #fff;
  color: var(--err);
  border: 1.5px solid #e3b9b6;
}
.data-table .row-delete-btn:hover { background: var(--err-bg); }

/* Tab "Urkunde direkt erstellen": Hauptspalte + Entwürfe-Sidebar rechts */
.tab-create-layout { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.tab-create-main { flex: 1 1 420px; min-width: 0; }
.tab-create-drafts { flex: 0 0 240px; }
.tab-create-drafts h2 { font-size: 15px; color: var(--navy); margin: 0 0 12px; }
.draft-item {
  position: relative;
  background: var(--ice);
  border: 1px solid #d7e5f6;
  border-radius: 3px;
  padding: 10px 26px 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.draft-item:hover { border-color: var(--blue); }
.draft-item .draft-label { font-weight: 700; font-size: 13.5px; color: var(--navy); word-break: break-word; }
.draft-item .draft-date { font-size: 11px; color: var(--gray); margin-top: 2px; }
.draft-item .draft-remove {
  position: absolute;
  top: 6px; right: 6px;
  margin: 0;
  padding: 0 6px;
  background: none;
  border: none;
  color: var(--err);
  font-size: 16px;
  line-height: 1.4;
  cursor: pointer;
}
.draft-item .draft-remove:hover { color: #7a1a15; }

/* Unterschriftsart (Checkboxen), E-Mail-Felder, Unterschriftsbereich auf der PDF */
input[type=checkbox] { width: auto; padding: 0; margin: 0; accent-color: var(--blue); }
.sign-mode { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 0; text-transform: none; letter-spacing: 0; font-size: 14.5px; font-weight: 700; cursor: pointer; }
.aussteller-row .area-btn { flex: 0 0 auto; margin-top: 0; padding: 0 12px; background: #fff; color: var(--navy); border: 1.5px solid var(--navy); font-size: 13px; }
.aussteller-row .area-btn.set { background: var(--ok-bg); border-color: var(--ok); color: #163d22; }
.aussteller-row .area-btn:hover { background: var(--ice); }
.area-picker { margin-top: 18px; padding: 16px; background: #fff; border: 1.5px solid #c3d5ec; border-radius: 3px; }
.area-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 13.5px; font-weight: 700; color: var(--navy); }
.area-nav button { margin: 0; padding: 4px 12px; background: #fff; color: var(--navy); border: 1.5px solid var(--navy); }
.area-canvas-wrap { position: relative; display: block; width: 100%; max-width: 640px; border: 1px solid #ddd; touch-action: none; user-select: none; }
.area-canvas-wrap canvas { display: block; width: 100%; height: auto; }
.area-overlay { position: absolute; inset: 0; cursor: crosshair; }
.area-box { position: absolute; border: 2px solid var(--blue); background: rgba(27,106,201,0.16); font-size: 11px; font-weight: 800; color: var(--navy); padding: 1px 4px; overflow: hidden; pointer-events: none; }
.area-box.active { border-color: var(--err); background: rgba(179,38,30,0.14); }
.area-box.draft { border-style: dashed; }

/* Unterschriftslinks nach dem Anlegen */
.sig-links { margin-top: 22px; }
.sig-links h2 { font-size: 16px; color: var(--navy); margin: 0 0 10px; }
.sig-link-item { background: var(--ice); border: 1px solid #d7e5f6; border-radius: 3px; padding: 10px 12px; margin-bottom: 8px; font-size: 13.5px; }
.sig-link-item .sig-head { font-weight: 800; color: var(--navy); }
.sig-link-item .sig-url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; margin: 4px 0; }
.sig-link-item button { margin: 0; padding: 5px 12px; font-size: 12.5px; }

/* Unterschriftsfeld in der Vorschau (digitale Unterschrift) */
.cert-signatures.digital { margin-top: 8pt; }
.cert-sigbox {
  height: 50pt; max-width: 165pt; margin: 0 auto 4pt;
  border: 0.6pt solid #c3d5ec; border-left: 2.5pt solid var(--navy);
  display: flex; align-items: center; justify-content: space-between; gap: 6pt;
  padding: 3pt 4pt; text-align: left; overflow: hidden;
}
.cert-sigbox.draft { border-style: dashed; border-color: #9db8dc; justify-content: center; color: #869791; font-size: 6pt; text-align: center; }
.cert-sigbox .sb-text { min-width: 0; font-size: 5.5pt; color: #666; line-height: 1.25; }
.cert-sigbox .sb-name { font-size: 9pt; font-weight: 800; color: var(--navy); margin: 1pt 0; }
.sig-qr { position: relative; flex-shrink: 0; line-height: 0; }
.sig-qr::after { content: '✓'; position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -7px 0 0 -7px; border: 2px solid #fff; border-radius: 50%; background: #1B6AC9; color: #fff; font-size: 8px; line-height: 10px; text-align: center; }

/* Urkunden verwalten: Unterschriften, Status, Aktionen */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.pill.done { background: var(--ok-bg); color: #163d22; border: 1px solid var(--ok); }
.pill.wait { background: #FFF4DB; color: #7a5200; border: 1px solid #e2b64a; }
.pill.hand { background: var(--ice); color: var(--navy); border: 1px solid #c3d5ec; }
.sig-line { font-size: 12px; margin-top: 5px; line-height: 1.4; font-weight: 400; }
.sig-line .sig-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: #5b6b85; }
.row-btn { margin: 4px 4px 0 0; padding: 4px 10px; font-size: 12px; background: #fff; color: var(--navy); border: 1.5px solid var(--navy); }
.row-btn:hover { background: var(--ice); }
.row-btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.row-btn.primary:hover { background: var(--navy); }
.data-table td.actions-cell { white-space: normal; font-weight: 400; min-width: 150px; }
.data-table td.sig-cell { white-space: normal; font-weight: 400; min-width: 200px; }
.wait-note { font-size: 12px; color: #7a5200; margin-top: 4px; }

dialog#mailDialog { width: min(640px, 94vw); border: 1px solid #c3d5ec; border-radius: 4px; padding: 26px; font-family: inherit; color: var(--ink); }
dialog#mailDialog::backdrop { background: rgba(11,42,92,0.45); }
dialog#mailDialog h2 { margin: 0 0 4px; font-size: 18px; color: var(--navy); }
dialog#mailDialog textarea { min-height: 260px; font-size: 13.5px; line-height: 1.5; }

@media print {
  header, .sub, .tabs, #tabRegister, #registerForm, #createForm, .actions,
  h1, #result h2, #draftMsg, #registerMsg2, #createSigLinks { display: none !important; }
  body { margin: 0; }
  main { max-width: none; padding: 0; }
  .cert-scale-wrap { width: auto; height: auto !important; overflow: visible; }
  .certificate { position: static !important; transform: none !important; box-shadow: none; border: none; width: 210mm; height: 297mm; }
  @page { size: A4 portrait; margin: 0; }
}

/* Anmeldung (wie im Passwortmanager) */
#gate .eyebrow { font-weight: 800; font-size: 20px; color: var(--navy); letter-spacing: 0.02em; margin: 0 0 26px; }
#gate .eyebrow .bracket { color: var(--blue); }
#gate .field { margin-bottom: 18px; }
#gate .hint { font-size: 12.5px; color: #5b6b85; margin-top: 10px; line-height: 1.5; }
.link-btn { background: none; border: none; padding: 0; color: var(--blue); font-weight: 700; font-size: 14px; cursor: pointer; font-family: inherit; }
.link-btn:hover { background: none; color: var(--navy); text-decoration: underline; }
button.ghost { background: #fff; color: var(--navy); border: 1.5px solid #c3d5ec; }
button.ghost:hover { background: var(--ice); }
.modes { display: flex; gap: 0; margin: 0 0 22px; border: 1.5px solid #c3d5ec; border-radius: 3px; overflow: hidden; background: #fff; }
.modes button { flex: 1; background: #fff; color: #5b6b85; border-radius: 0; padding: 11px 10px; }
.modes button.active { background: var(--navy); color: #fff; }
.modes button:not(.active):hover { background: var(--ice); color: var(--navy); }
.codebox { display: flex; gap: 10px; justify-content: space-between; }
.codebox input { width: 100%; min-width: 0; height: 58px; padding: 0; text-align: center; font-size: 26px; font-weight: 800; font-family: inherit; color: var(--navy); border: 1.5px solid #c3d5ec; border-radius: 3px; background: #fff; caret-color: var(--blue); }
.codebox input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(27,106,201,0.18); }
.codebox input.filled { border-color: var(--navy); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.sent { font-size: 14px; color: var(--ink); margin: 0 0 18px; line-height: 1.5; }

/* Urkunden verwalten: breite Tabelle, Zellen oben ausgerichtet und umbrechend */
.data-table { table-layout: auto; font-size: 13px; }
.data-table th, .data-table td { padding: 9px 8px; vertical-align: top; }
.data-table td.sig-cell { min-width: 260px; }
.data-table td.actions-cell { min-width: 190px; }
.data-table td.status-cell { min-width: 120px; }

/* Zugänge (Amtsjahr) */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.badge.off { background: #eee; color: #666; }
.badge.soon { background: #fff8e6; color: #7a5b00; }
.badge.lock { background: var(--err-bg); color: var(--err); }
.person { background: var(--ice); border: 1px solid #d7e5f6; border-radius: 4px; padding: 16px 18px; margin-top: 14px; }
.grant { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid #d7e5f6; font-size: 14px; margin-top: 8px; }
.grant.grant-head { border-top: 0; margin: 0; padding: 0; }
#mineList .grant { border-top: 0; }
.grant .l { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grant .who { font-weight: 800; color: var(--navy); }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
button.small { padding: 7px 12px; font-size: 12.5px; }
button.danger { background: #fff; color: var(--err); border: 1.5px solid #e3b6b3; }
button.danger:hover { background: var(--err-bg); }
.year-row { display: flex; gap: 10px; align-items: center; }
.year-row input[type=text] { max-width: 150px; text-align: center; font-weight: 800; color: var(--navy); }
.year-row #gYearLabel { font-size: 14px; font-weight: 700; color: var(--navy); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 3px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
.toast.show { opacity: 1; }

/* Ausstehende Unterschrift: Dummy-QR ohne Häkchen-Siegel, gelber Streifen */
.sig-qr.dummy::after { display: none; }
.cert-sigbox:has(.sig-qr.dummy) { border-color: #f1d98a; border-left-color: #f5b800; }
.cert-sigbox:has(.sig-qr.dummy) .sb-text > div:first-child { color: #9a6700; font-weight: 800; }

/* Batch-Unterschrift: Warteschlange, Status-Badges */
.msg.warn { background: #FFF8E1; border: 1.5px solid #E2B64A; color: #5c4400; }
.mail-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; margin-left: 4px; }
.mail-badge.ok { background: var(--ok-bg); color: #163d22; border: 1px solid var(--ok); }
.mail-badge.err { background: var(--err-bg); color: #5c1712; border: 1px solid var(--err); }
.mail-badge.wait { background: #FFF4DB; color: #7a5200; border: 1px solid #e2b64a; }
.batch-item { display: flex; gap: 10px; align-items: flex-start; background: var(--ice); border: 1px solid #d7e5f6; border-radius: 3px; padding: 10px 12px; margin: 0 0 8px; cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 400; }
.batch-item:hover { border-color: var(--blue); }
.batch-item input { margin-top: 3px; }
