/* ==========================================================================
   SignFlow – UI
   Keine externen Fonts/CDNs (DSGVO): System-Schriften, alles lokal.
   ========================================================================== */

:root {
  --accent: #2a4fd6;
  --accent-ink: #fff;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, #fff);
  --ink: #161a23;
  --ink-2: #4a5263;
  --ink-3: #8a91a1;
  --line: #e4e7ee;
  --line-2: #eef0f5;
  --bg: #f5f6f9;
  --card: #fff;
  --ok: #0c8a5b;
  --ok-soft: #e3f5ec;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --bad: #c92a3a;
  --bad-soft: #fde8ea;
  --info: #1764b0;
  --info-soft: #e6f0fb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 620; }
h3 { font-size: 1rem; font-weight: 620; }
p { margin: 0 0 1em; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 28px;
  height: 58px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 12px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 520;
}
.nav a:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: .9rem; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--line-2); color: var(--ink-2);
  display: grid; place-items: center; font-weight: 650; font-size: .8rem;
}

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }
.container.wide { max-width: none; padding: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2, .grid-main { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Karten ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 1rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: 550 .9rem/1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 1px; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: #f5c2c7; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 11px; font-size: .84rem; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 1rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }

/* ---------- Formulare ---------- */
label { display: block; font-weight: 560; font-size: .87rem; margin-bottom: 5px; color: var(--ink-2); }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid #d5d9e2; border-radius: var(--radius-sm);
  font: inherit; color: var(--ink); background: #fff; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.field { margin-bottom: 16px; }
.hint { font-size: .8rem; color: var(--ink-3); margin-top: 4px; }
.check { display: flex; align-items: flex-start; gap: 9px; font-weight: 450; color: var(--ink); cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.dropzone {
  display: grid; place-items: center; gap: 6px; text-align: center; padding: 34px 20px;
  border: 2px dashed #cdd3df; border-radius: var(--radius); background: #fafbfd; cursor: pointer; color: var(--ink-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 34px; height: 34px; color: var(--accent); }
.dropzone input { display: none; }
.dropzone .file-name { font-weight: 600; color: var(--ink); }

.rec-row { display: grid; grid-template-columns: 26px 1fr 1fr 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.rec-row.with-role { grid-template-columns: 26px 140px 1fr 1fr; }
.rec-num {
  width: 24px; height: 24px; border-radius: 50%; color: #fff; display: grid; place-items: center;
  font-size: .75rem; font-weight: 700;
}
.role-tag { font-weight: 600; font-size: .88rem; }

/* ---------- Meldungen ---------- */
.flash { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; font-weight: 500; }
.flash.success { background: var(--ok-soft); border-color: #b7e4cd; color: #0a5c3d; }
.flash.error { background: var(--bad-soft); border-color: #f5c2c7; color: #8c1d29; }
.flash.info { background: var(--info-soft); border-color: #bfd7f2; color: #0f4a85; }
.flash.warn { background: var(--warn-soft); border-color: #f2d8a7; color: #7a4a00; }

/* ---------- Tabellen ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: .75rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-3); padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fafbfc;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafbfe; }
.table .title { font-weight: 600; color: var(--ink); }

/* ---------- Status-Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: .78rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-completed, .badge.s-signed { background: var(--ok-soft); color: var(--ok); }
.badge.s-sent, .badge.s-viewed, .badge.s-sealing { background: var(--info-soft); color: var(--info); }
.badge.s-declined, .badge.s-voided { background: var(--bad-soft); color: var(--bad); }
.badge.s-expired { background: var(--warn-soft); color: var(--warn); }
.badge.s-draft, .badge.s-created { background: var(--line-2); color: var(--ink-2); }

.progress { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; width: 90px; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 99px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2); font-weight: 550; font-size: .86rem;
}
.chip:hover { text-decoration: none; border-color: #c9cfdb; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .n { font-size: .75rem; opacity: .7; }

.empty { text-align: center; padding: 56px 20px; color: var(--ink-2); }
.empty svg { width: 46px; height: 46px; color: #c3c9d6; margin-bottom: 10px; }

/* ---------- Timeline (Prüfprotokoll) ---------- */
.timeline { list-style: none; margin: 0; padding: 4px 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .t-title { font-weight: 580; }
.timeline .t-meta { font-size: .8rem; color: var(--ink-3); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: .9rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }

.recipient-list { list-style: none; margin: 0; padding: 0; }
.recipient-list li { display: flex; align-items: center; gap: 12px; padding: 13px 20px; border-bottom: 1px solid var(--line-2); }
.recipient-list li:last-child { border-bottom: 0; }
.recipient-list .who { flex: 1; min-width: 0; }
.recipient-list .who b { display: block; }
.recipient-list .who span { font-size: .85rem; color: var(--ink-3); }

.secret-box {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: #0f1422; color: #e6ebff;
  border-radius: var(--radius-sm); font-family: var(--mono); font-size: .85rem; word-break: break-all;
}

/* ---------- Öffentliche Seiten ---------- */
.public-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.public-top { height: 58px; display: flex; align-items: center; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line); }
.public-main { flex: 1; display: grid; place-items: center; padding: 40px 20px; }
.auth-card { width: 100%; max-width: 400px; }
.info-card { width: 100%; max-width: 520px; text-align: center; }
.info-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; }
.info-icon svg { width: 28px; height: 28px; }
.info-icon.ok { background: var(--ok-soft); color: var(--ok); }
.info-icon.warn { background: var(--warn-soft); color: var(--warn); }
.info-icon.wait { background: var(--info-soft); color: var(--info); }
.public-foot { text-align: center; padding: 18px; font-size: .8rem; color: var(--ink-3); }

/* ==========================================================================
   PDF-Seiten (Editor + Signieren)
   ========================================================================== */
.pages { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 28px 20px 80px; }
.page {
  position: relative; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 6px 20px rgba(16,24,40,.08);
  user-select: none;
}
.page canvas { display: block; width: 100%; height: 100%; }
.page .overlay { position: absolute; inset: 0; }
.page-label { position: absolute; top: -18px; right: 0; font-size: .72rem; color: var(--ink-3); }
.loading-pages { padding: 80px; text-align: center; color: var(--ink-3); }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 290px minmax(0, 1fr) 280px; height: calc(100vh - 58px); }
.editor-side { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 18px; }
.editor-side.side-right { border-right: 0; border-left: 1px solid var(--line); }
.editor-main { overflow-y: auto; background: #e9ebf1; }
.editor-side h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 18px 0 9px; }
.editor-side h3:first-child { margin-top: 0; }
.editor-toolbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 10px 16px; background: rgba(233,235,241,.92); backdrop-filter: blur(6px); border-bottom: 1px solid #dde0e8; }
.editor-toolbar .title { font-weight: 650; }

.rec-pick { display: flex; flex-direction: column; gap: 6px; }
.rec-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); cursor: pointer; background: #fff;
}
.rec-item.active { border-color: var(--rc); box-shadow: inset 3px 0 0 var(--rc); background: color-mix(in srgb, var(--rc) 7%, #fff); }
.rec-item .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rc); flex: none; }
.rec-item .meta { flex: 1; min-width: 0; }
.rec-item .meta b { display: block; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-item .meta span { display: block; font-size: .76rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-item .rm { opacity: 0; border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.rec-item:hover .rm { opacity: 1; }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.pal-item {
  display: flex; align-items: center; gap: 7px; padding: 9px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #fff; cursor: grab; font-size: .84rem; font-weight: 550;
  transition: border-color .12s, transform .12s;
}
.pal-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.pal-item svg { width: 16px; height: 16px; color: var(--ink-2); flex: none; }
.pal-item.wide { grid-column: span 2; }

.f-box {
  position: absolute; border: 1.5px solid var(--rc); background: color-mix(in srgb, var(--rc) 14%, transparent);
  border-radius: 3px; display: flex; align-items: center; justify-content: flex-start; padding: 0 5px;
  font-size: 11px; font-weight: 600; color: color-mix(in srgb, var(--rc) 80%, #000); overflow: hidden;
  cursor: move; touch-action: none; white-space: nowrap;
}
.f-box.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--rc); z-index: 3; }
.f-box .handle { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; background: var(--rc); cursor: nwse-resize; border-radius: 2px 0 2px 0; }
.f-box .req { color: var(--bad); margin-left: 2px; }
.drop-ghost { position: absolute; border: 2px dashed var(--accent); border-radius: 3px; pointer-events: none; background: var(--accent-soft); opacity: .8; }

.props .empty-props { color: var(--ink-3); font-size: .88rem; padding: 10px 0; }

/* ---------- Signieren ---------- */
.sign-bar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 16px;
  padding: 10px 22px; background: #fff; border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.sign-bar .doc { flex: 1; min-width: 0; }
.sign-bar .doc b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign-bar .doc span { font-size: .82rem; color: var(--ink-3); }
.sign-progress { font-size: .85rem; color: var(--ink-2); white-space: nowrap; }
.sign-wrap { background: #e9ebf1; min-height: calc(100vh - 62px); }
.sign-intro { max-width: 820px; margin: 22px auto 0; padding: 0 20px; }

.s-field {
  position: absolute; border: 2px solid var(--rc); background: color-mix(in srgb, var(--rc) 12%, #fff);
  border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: box-shadow .15s, background .15s;
}
.s-field.done { background: rgba(255,255,255,.55); border-style: dashed; border-color: color-mix(in srgb, var(--rc) 55%, #fff); }
.s-field.pulse { animation: pulse 1.2s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rc) 60%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
.s-field button.s-sign {
  all: unset; cursor: pointer; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px;
  color: color-mix(in srgb, var(--rc) 85%, #000); font-weight: 700; font-size: 12px; text-align: center;
}
.s-field img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }
.s-field input[type=text] { all: unset; width: 100%; height: 100%; padding: 0 5px; font: 13px var(--font); color: var(--ink); box-sizing: border-box; }
.s-field input[type=checkbox] { width: 70%; height: 70%; margin: 0; accent-color: var(--rc); }
.s-field .static { font-size: 13px; padding: 0 5px; width: 100%; white-space: nowrap; overflow: hidden; }
.s-field .req-dot { position: absolute; top: -7px; right: -7px; width: 14px; height: 14px; border-radius: 50%; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; font-weight: 800; }
.s-field.done .req-dot { display: none; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(15, 20, 34, .5); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 620px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { padding: 18px 22px 0; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 14px 22px; background: #fafbfc; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { all: unset; cursor: pointer; padding: 9px 14px; font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.sig-canvas-wrap { position: relative; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.sig-canvas-wrap::after { content: ""; position: absolute; left: 24px; right: 24px; bottom: 34%; border-bottom: 1px dashed #c3c9d6; pointer-events: none; }
.sig-canvas-wrap canvas { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.sig-type-preview { font: italic 44px "Segoe Script", "Brush Script MT", "Lucida Handwriting", "Apple Chancery", cursive; height: 120px; display: flex; align-items: center; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: 10px; overflow: hidden; white-space: nowrap; }
.consent-box { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, #fff); border-radius: var(--radius); padding: 16px 18px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 240px minmax(0, 1fr); }
  .editor-side.side-right { display: none; }
}
@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 14px; }
  .nav a { padding: 7px 8px; }
  .userbox span { display: none; }
  .editor { grid-template-columns: 1fr; height: auto; }
  .editor-side { border-right: 0; border-bottom: 1px solid var(--line); }
  .sign-bar { flex-wrap: wrap; }
}
