:root {
  --paper: #EEF1F5;
  --sheet: #FFFFFF;
  --ink: #16233A;
  --pen: #2446C8;
  --pen-soft: #E6EBFA;
  --line: #D9DEE5;
  --muted: #5F6B7C;
  --ok: #1F7A4D;
  --ok-soft: #E3F2EA;
  --warn: #A94A12;
  --warn-soft: #FBEADF;
  --bad: #B3261E;
  --r: 10px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
a { color: var(--pen); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 40px; }
.narrow { max-width: 760px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.stack > * + * { margin-top: 14px; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px)); margin-bottom: 20px;
}
.brand { font-weight: 600; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 26px; height: 26px; }

.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }

label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 12px 12px; font-size: 16px; min-height: 48px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--pen); outline: none; box-shadow: 0 0 0 3px var(--pen-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 8px; border: 1px solid transparent;
  background: var(--pen); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.link { background: none; color: var(--muted); padding: 0 6px; min-height: 40px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: .875rem; }

.msg { padding: 12px 14px; border-radius: 8px; font-size: .95rem; }
.msg.err { background: #FCE8E6; color: var(--bad); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.info { background: var(--pen-soft); color: var(--ink); }

/* ---------- Admin ---------- */
.grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid { grid-template-columns: 380px 1fr; align-items: start; } .grid > .card:first-child { position: sticky; top: 16px; } }
.drop {
  border: 1.5px dashed var(--line); border-radius: 8px; padding: 18px; text-align: center;
  cursor: pointer; background: #FAFBFC; transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--pen); background: var(--pen-soft); }
.drop input { display: none; }
.drop b { display: block; overflow-wrap: anywhere; }
.drop span { font-weight: 400; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; min-height: 36px;
  cursor: pointer; font-size: .875rem;
}
.chip[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { flex: 1 1 200px; max-width: 260px; min-height: 40px !important; padding: 8px 12px !important; }

.list { display: grid; gap: 10px; }
.row {
  display: grid; gap: 6px 16px; align-items: center;
  grid-template-columns: 1fr auto; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.row .t { font-weight: 600; overflow-wrap: anywhere; }
.row .who { font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.row .acts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.row .when { font-size: .8rem; color: var(--muted); grid-column: 1 / -1; }
.badge { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.gesendet { background: var(--pen-soft); color: var(--pen); }
.badge.geöffnet { background: #FFF4D6; color: #7A5A00; }
.badge.unterschrieben { background: var(--ok-soft); color: var(--ok); }
.badge.abgelehnt, .badge.fehler { background: var(--warn-soft); color: var(--warn); }
.badge.abgelaufen { background: #ECEEF1; color: var(--muted); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- Unterschrift ---------- */
.doc-head { margin-bottom: 18px; }
.doc-head .from { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.pages { display: grid; gap: 12px; }
.pages canvas { width: 100%; height: auto; background: #fff; border-radius: 4px; box-shadow: 0 1px 2px rgba(22,35,58,.08), 0 6px 18px rgba(22,35,58,.06); display: block; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.signbox { margin-top: 24px; }
.pad-wrap { position: relative; margin-top: 6px; }
.pad {
  display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair;
  background:
    linear-gradient(transparent 0 calc(100% - 46px), var(--ink) calc(100% - 46px) calc(100% - 45px), transparent calc(100% - 45px));
  background-color: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}
.pad-x { position: absolute; left: 16px; bottom: 50px; font-size: 1.4rem; color: var(--muted); pointer-events: none; }
.pad-hint { position: absolute; inset: 0 0 60px 0; display: flex; align-items: center; justify-content: center; color: #A3ACB9; pointer-events: none; font-size: .95rem; }
.pad-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; font-size: .95rem; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; margin-top: 1px; accent-color: var(--pen); }

.stickybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; justify-content: center;
}
.stickybar .btn { width: 100%; max-width: 728px; }
.spacer { height: 80px; }

.done { text-align: center; padding: 40px 20px; }
.done svg { width: 64px; height: 64px; margin-bottom: 14px; }
.done svg path { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw .6s .1s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .done svg path { animation: none; stroke-dashoffset: 0; } }

dialog { border: none; border-radius: var(--r); padding: 20px; max-width: 440px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(22,35,58,.4); }

/* ---------- Firmen-Branding (Unterschriftsseite) ---------- */
:root { --brand: #2446C8; --brand-dark: #16233A; }
.hero {
  background: radial-gradient(120% 140% at 100% 0%, var(--brand) 0%, var(--brand-dark) 70%);
  color: #fff; padding: calc(18px + env(safe-area-inset-top, 0px)) 0 84px;
}
.hero-in { padding-top: 0; padding-bottom: 0; }
.hero h1 { font-size: clamp(1.45rem, 5vw, 2rem); margin-top: 22px; overflow-wrap: anywhere; }
.hero p { color: rgba(255,255,255,.78); margin-top: 6px; font-size: .95rem; }
.brandchip {
  display: inline-flex; align-items: center; min-height: 52px; padding: 10px 16px;
  background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-weight: 600; color: var(--brand-dark);
}
.brandchip.dark { background: rgba(0,0,0,.28); box-shadow: none; color: #fff; }
.brandchip img { display: block; max-height: 44px; max-width: 200px; width: auto; }
.main-up { margin-top: -64px; position: relative; }
.msgcard { white-space: pre-wrap; margin-bottom: 14px; font-size: .95rem; border-left: 4px solid var(--brand); }
body.branded .btn:not(.ghost):not(.link) { background: var(--brand); }
body.branded .check input { accent-color: var(--brand); }
body.branded input:focus, body.branded textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
body.branded a:not(.btn) { color: var(--brand); }
.brandfoot { max-width: 760px; margin: 8px auto 0; padding: 22px 16px 34px; font-size: .875rem; color: var(--muted); line-height: 1.6; }
.brandfoot b { color: var(--ink); }
.brandfoot a { color: var(--muted) !important; }
.brandfoot .line { border-top: 3px solid var(--brand); width: 48px; margin-bottom: 12px; }
