:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --ink-4: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --gold: #b38a43;
  --gold-2: #d4af6a;
  --gold-soft: #fbf6ec;
  --green: #15803d;
  --green-soft: #f0fdf4;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --blue: #1e40af;
  --blue-soft: #eff6ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 2px 6px rgba(15, 23, 42, 0.06), 0 20px 48px rgba(15, 23, 42, 0.08);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Inter, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Layout
   ============================================================ */

.page {
  min-height: 100vh;
  padding: 24px 16px 64px;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
}

.wrap-sm { max-width: 440px; margin: 48px auto 0; }
.wrap-lg { max-width: 1240px; margin: 0 auto; }

/* ============================================================
   Public header (customer form)
   ============================================================ */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--ink-3);
  font-size: 13px;
}
.brand-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
}
.brand-name { color: var(--ink); font-weight: 600; }

/* ============================================================
   Card
   ============================================================ */

.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
}
.card-head h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-head .sub { color: var(--ink-3); font-size: 14px; }

.card-body { padding: 28px 32px; }

/* ============================================================
   Creditor box (Zahlungsempfänger)
   ============================================================ */

.creditor {
  background: var(--gold-soft);
  border: 1px solid #f3e4c1;
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 24px;
}
.creditor .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--gold);
  margin-bottom: 6px;
}
.creditor .name {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.creditor .meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px 20px;
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 6px;
}
.creditor .meta span strong {
  color: var(--ink-3);
  font-weight: 500;
  margin-right: 4px;
}

/* ============================================================
   Section
   ============================================================ */

.section {
  margin-bottom: 24px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-3);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ============================================================
   Form
   ============================================================ */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 14px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}
label .req { color: var(--red); }
label .opt { color: var(--ink-4); font-weight: 400; }

.field { margin-bottom: 14px; }

input[type="text"], input[type="email"], input[type="tel"], textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="email"]:focus, input[type="tel"]:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 106, 0.18);
}
input.mono, input.iban {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.6px;
}

.help {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 6px;
  transition: color .15s;
}
.help-ok { color: var(--green); font-weight: 600; }
.help-err { color: var(--red); font-weight: 600; }

/* ============================================================
   Mandate text
   ============================================================ */

.mandate-text {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-2);
}
.mandate-text p { margin: 0 0 10px; }
.mandate-text p:last-child { margin: 0; }
.mandate-text strong { color: var(--ink); }

/* ============================================================
   Signature
   ============================================================ */

.sig-wrap {
  position: relative;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 4px;
  touch-action: none;
}
.sig-wrap.has-data { border-color: var(--gold); border-style: solid; }
.sig-wrap canvas {
  display: block;
  width: 100%;
  height: 160px;
  border-radius: calc(var(--radius-sm) - 4px);
  cursor: crosshair;
}
.sig-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}
.sig-hint {
  font-size: 12px;
  color: var(--ink-3);
}
.btn-sig-clear {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--ink-3);
  cursor: pointer;
}
.btn-sig-clear:hover { background: var(--bg); color: var(--ink); }

/* ============================================================
   Checkbox
   ============================================================ */

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  margin-top: 14px;
  cursor: pointer;
}
.check input[type="checkbox"] {
  margin-top: 2px;
  width: 18px; height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
}
.check span {
  font-size: 13.5px;
  color: var(--ink-2);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .05s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover { background: #1e293b; }
.btn-primary:disabled {
  background: var(--line-2);
  color: #fff;
  cursor: not-allowed;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(179, 138, 67, 0.28);
}
.btn-gold:hover { filter: brightness(1.04); }
.btn-gold:disabled { background: var(--line-2); box-shadow: none; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--line);
}
.btn-ghost:hover { background: var(--bg); }

.btn-danger {
  background: #fff;
  color: var(--red);
  border-color: #fecaca;
}
.btn-danger:hover { background: var(--red-soft); }

.btn-block { width: 100%; padding: 14px 20px; font-size: 15px; }

.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ============================================================
   Messages
   ============================================================ */

.msg {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-top: 14px;
}
.msg.err  { background: var(--red-soft);   color: var(--red);   border: 1px solid #fecaca; }
.msg.ok   { background: var(--green-soft); color: var(--green); border: 1px solid #bbf7d0; }
.msg.info { background: var(--blue-soft);  color: var(--blue);  border: 1px solid #bfdbfe; }

/* ============================================================
   Success state
   ============================================================ */

.success-card {
  text-align: center;
  padding: 64px 32px;
}
.success-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 700;
}
.success-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.success-card p { color: var(--ink-3); margin: 4px 0; }
.success-number {
  display: inline-block;
  margin-top: 20px;
  padding: 10px 18px;
  background: var(--gold-soft);
  color: var(--gold);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 15px;
  border-radius: 8px;
  letter-spacing: 0.5px;
}

/* ============================================================
   Footer
   ============================================================ */

.footer-note {
  max-width: 780px;
  margin: 24px auto 0;
  font-size: 12px;
  color: var(--ink-4);
  text-align: center;
  line-height: 1.6;
}
.footer-note a { color: var(--ink-3); }

/* ============================================================
   Admin layout
   ============================================================ */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .title {
  display: flex; align-items: center; gap: 12px;
  font-weight: 700;
  color: var(--ink);
}
.topbar .user {
  display: flex; align-items: center; gap: 12px;
  color: var(--ink-3);
  font-size: 13px;
}
.topbar .user strong { color: var(--ink); }

.admin-page {
  padding: 24px;
  background: var(--bg);
  min-height: calc(100vh - 60px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search {
  flex: 1;
  max-width: 380px;
  position: relative;
}
.search input {
  padding-left: 38px;
}
.search::before {
  content: '';
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.table-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  white-space: nowrap;
}
tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }

.num {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  color: var(--gold);
  font-size: 13.5px;
  white-space: nowrap;
}
.iban-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
}
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell .btn { margin-left: 6px; }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-3);
}
.empty .emoji { font-size: 32px; display: block; margin-bottom: 8px; opacity: 0.4; }

/* Dialog / Drawer */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: none;
}
.backdrop.open { display: block; }

.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  z-index: 101;
  transform: translateX(100%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-body { padding: 22px 24px; overflow-y: auto; flex: 1; }
.drawer-foot {
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.close-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--ink-3);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.close-btn:hover { background: var(--bg); color: var(--ink); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; margin-bottom: 16px; }
.kv dt { color: var(--ink-3); font-size: 13px; font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); font-size: 14px; word-break: break-word; }
.kv dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  background: var(--green-soft);
  color: var(--green);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

/* Audit log */
.audit {
  font-size: 13px;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.audit-row {
  display: grid;
  grid-template-columns: 140px 100px 110px 1fr;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.audit-row:last-child { border-bottom: none; }
.audit-row .ts { color: var(--ink-3); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.audit-row .ac { font-weight: 600; color: var(--ink); }

/* ============================================================
   Mobile
   ============================================================ */

@media (max-width: 640px) {
  .page { padding: 16px 12px 48px; }
  .card-head { padding: 22px 20px 16px; }
  .card-body { padding: 20px; }
  .card-head h1 { font-size: 19px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .creditor .meta { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .admin-page { padding: 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { font-size: 12px; margin-top: 8px; }
  thead { display: none; }
  tbody td { display: block; padding: 6px 16px; border: none; }
  tbody tr { display: block; border-bottom: 1px solid var(--line); padding: 12px 0; }
  tbody tr:last-child { border-bottom: none; }
  .actions-cell { text-align: left; padding-top: 10px; }
  .actions-cell .btn { margin-left: 0; margin-right: 6px; }
}
