/* ============================================================
   Servecta Sign — CD-basiertes Stylesheet
   Referenz: /Users/lucakohls/Desktop/Servecta/CD/cd.html
   ============================================================ */
:root {
  --brand:       #1A56DB;
  --brand-dark:  #1545B0;
  --brand-deep:  #0F3385;
  --brand-light: #4A7AED;
  --brand-pale:  #EBF0FF;
  --black:       #0A0A0A;
  --gray-950:    #0F0F10;
  --gray-900:    #171717;
  --gray-800:    #262626;
  --gray-700:    #3B3B3B;
  --gray-600:    #525252;
  --gray-500:    #6B6B6B;
  --gray-400:    #9A9A9A;
  --gray-300:    #BFBFBF;
  --gray-200:    #E2E2E2;
  --gray-100:    #EBEBEB;
  --gray-75:     #F2F2F1;
  --gray-50:     #F7F7F5;
  --white:       #FFFFFF;
  --success:     #16864E;
  --warning:     #B47818;
  --error:       #B83232;
  --info:        #0E7490;
  --success-bg:  #E2F5EC;
  --warning-bg:  #FDF0DB;
  --error-bg:    #FCE4E4;
  --info-bg:     #E0F4F7;
  --shadow-xs:   0 1px 2px rgba(10,10,10,0.03);
  --shadow-sm:   0 1px 3px rgba(10,10,10,0.05), 0 1px 2px rgba(10,10,10,0.03);
  --shadow-md:   0 4px 12px rgba(10,10,10,0.06), 0 2px 4px rgba(10,10,10,0.04);
  --shadow-lg:   0 12px 32px rgba(10,10,10,0.10), 0 4px 8px rgba(10,10,10,0.05);
  --radius-btn:  10px;
  --radius-card: 14px;
  --radius-xl:   16px;
  --sidebar-width: 232px;
  --sidebar-width-collapsed: 64px;
  --sidebar-bg:  #0A0A0A;
  --content-bg:  #F7F7F5;
}
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body { height: 100%; }

/* Fix: das hidden-Attribut muss immer display:none erzwingen, auch gegen spezifischere Regeln */
[hidden] { display: none !important; }
body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #F5F5F3;
  color: var(--black);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
img, svg { display: block; max-width: 100%; }

/* Konsistente Focus-Rings in Servecta-Blau */
:focus-visible {
  outline: 3px solid rgba(26, 86, 219, 0.35);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, .btn:focus-visible { outline-offset: 2px; }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { outline: none; }

/* Custom Scrollbars (dezent) */
* { scrollbar-width: thin; scrollbar-color: var(--gray-300) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--gray-500); background-clip: padding-box; }

/* ============== App-Shell / Header ============== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--black);
  color: var(--white);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
}
.topbar .brand .wordmark {
  font-weight: 800;
  letter-spacing: -0.5px;
  font-size: 18px;
}
.topbar .brand .sub {
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--brand-light);
  font-weight: 700;
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid rgba(255,255,255,0.15);
}
.topbar-nav { display: flex; gap: 24px; }
.topbar-nav a {
  font-size: 14px; font-weight: 600;
  color: rgba(255,255,255,0.55);
  transition: color .15s;
}
.topbar-nav a.active, .topbar-nav a:hover { color: var(--white); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user {
  font-size: 13px; color: rgba(255,255,255,0.7);
  display: flex; align-items: center; gap: 10px;
}
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}

/* ============== Pages ============== */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 32px 80px;
  width: 100%;
  flex: 1;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 32px; flex-wrap: wrap;
}
.page-title {
  font-size: 40px; font-weight: 800; letter-spacing: -1.5px; line-height: 1.1;
}
.page-label {
  font-size: 11px; font-weight: 700; letter-spacing: 3px;
  text-transform: uppercase; color: var(--brand);
  margin-bottom: 8px;
}
.page-desc {
  font-size: 15px; color: var(--gray-500); line-height: 1.7;
  max-width: 560px; margin-top: 8px;
}

/* ============== Buttons ============== */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  font-weight: 600; font-size: 15px;
  padding: 12px 22px;
  border-radius: var(--radius-btn);
  letter-spacing: -0.1px;
  transition: transform .08s, background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--black); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--gray-900); }
.btn-brand { background: var(--brand); color: var(--white); }
.btn-brand:hover:not(:disabled) { background: var(--brand-dark); }
.btn-outline {
  background: transparent; color: var(--black);
  border: 1.5px solid var(--gray-300);
  padding: 10.5px 20.5px;
}
.btn-outline:hover { border-color: var(--black); }
.btn-ghost { background: var(--gray-100); color: var(--black); }
.btn-ghost:hover { background: var(--gray-300); }
.btn-danger { background: var(--error-bg); color: var(--error); }
.btn-danger:hover { background: #f8c9c9; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  display: grid; place-items: center;
}

/* ============== Cards ============== */
.card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
}
.card-pad { padding: 28px; }
.card h3 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.card-title {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--gray-300); margin-bottom: 14px;
}

/* ============== Inputs ============== */
.field { margin-bottom: 16px; }
.label {
  display: block;
  font-size: 12px; font-weight: 600; color: var(--black);
  margin-bottom: 6px;
}
.input, .textarea, .select {
  width: 100%;
  font-size: 14px; font-weight: 500;
  padding: 11px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-btn);
  background: var(--white); color: var(--black);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.12);
}
.input.error, .textarea.error { border-color: var(--error); }
.hint { font-size: 12px; color: var(--gray-500); margin-top: 6px; line-height: 1.5; }
.hint.error { color: var(--error); }
.textarea { resize: vertical; min-height: 88px; }

/* ============== Badges / Status ============== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 12px;
  border-radius: 100px;
  line-height: 1;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-bg); color: #0F5132; }
.badge-success .badge-dot { background: var(--success); }
.badge-warning { background: var(--warning-bg); color: #7A5A0B; }
.badge-warning .badge-dot { background: var(--warning); }
.badge-error { background: var(--error-bg); color: #7A1A1A; }
.badge-error .badge-dot { background: var(--error); }
.badge-info { background: var(--info-bg); color: #0E5260; }
.badge-info .badge-dot { background: var(--info); }
.badge-brand { background: var(--brand-pale); color: var(--brand-deep); }
.badge-brand .badge-dot { background: var(--brand); }
.badge-neutral { background: var(--gray-100); color: var(--gray-500); }

/* ============== Table / Document-Liste ============== */
.doc-grid {
  display: grid; gap: 12px;
}
.doc-row {
  display: grid;
  grid-template-columns: 1fr 200px 180px 130px 100px;
  align-items: center;
  gap: 20px;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  padding: 18px 24px;
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
.doc-row:hover { border-color: var(--gray-300); box-shadow: var(--shadow-md); }
.doc-row-main { min-width: 0; }
.doc-row-title {
  font-size: 15px; font-weight: 700; color: var(--black);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-row-sub { font-size: 12px; color: var(--gray-500); margin-top: 3px; }
.doc-row-meta { font-size: 13px; color: var(--gray-500); }
.doc-row-meta strong { color: var(--black); font-weight: 600; }

@media (max-width: 860px) {
  .doc-row { grid-template-columns: 1fr auto; grid-template-rows: auto auto; row-gap: 10px; }
  .doc-row > :nth-child(n+3) { grid-column: span 2; }
}

/* ============== Empty State ============== */
.empty {
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1.5px dashed var(--gray-300);
  padding: 64px 32px;
  text-align: center;
}
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  background: var(--brand-pale); color: var(--brand-deep);
  border-radius: 14px;
  display: grid; place-items: center; font-weight: 800; font-size: 22px;
}
.empty-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.empty-desc { font-size: 14px; color: var(--gray-500); max-width: 420px; margin: 0 auto 20px; line-height: 1.6; }

/* ============== Login ============== */
.auth-wrap {
  min-height: 100vh;
  background: var(--black);
  color: var(--white);
  display: grid; grid-template-columns: 1fr 1fr;
}
.auth-hero {
  padding: 64px;
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-hero::before {
  content: ''; position: absolute; top: -200px; right: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(26,86,219,0.18) 0%, transparent 70%);
}
.auth-hero::after {
  content: ''; position: absolute; bottom: -120px; left: -120px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(26,86,219,0.1) 0%, transparent 70%);
}
.auth-hero > * { position: relative; z-index: 1; }
.auth-label { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--brand-light); font-weight: 600; }
.auth-title { font-size: 72px; font-weight: 800; letter-spacing: -3px; line-height: 0.95; margin-top: 24px; }
.auth-title span { color: var(--brand-light); }
.auth-sub { color: var(--gray-500); margin-top: 24px; max-width: 460px; line-height: 1.7; font-size: 16px; }
.auth-version { font-size: 12px; color: var(--gray-700); font-weight: 500; padding-top: 32px; border-top: 1px solid rgba(255,255,255,0.08); }

.auth-form {
  background: var(--white); color: var(--black);
  padding: 64px; display: flex; align-items: center;
}
.auth-box { width: 100%; max-width: 400px; margin: 0 auto; }
.auth-box h2 { font-size: 28px; font-weight: 800; letter-spacing: -0.8px; margin-bottom: 8px; }
.auth-box .auth-lead { color: var(--gray-500); font-size: 14px; line-height: 1.6; margin-bottom: 32px; }

@media (max-width: 880px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { padding: 40px 24px; min-height: 280px; }
  .auth-title { font-size: 48px; letter-spacing: -1.5px; }
  .auth-form { padding: 40px 24px; }
}

/* ============== Upload / Editor ============== */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: flex-start;
}
@media (max-width: 1020px) { .editor-layout { grid-template-columns: 1fr; } }

.editor-canvas-wrap {
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1px solid var(--gray-100);
  padding: 0;
  overflow: hidden;
}
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
  flex-wrap: wrap;
}
.editor-toolbar .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 600;
  border-radius: 8px;
  background: var(--white);
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
  transition: all .15s;
}
.tool-btn:hover { border-color: var(--black); color: var(--black); }
.tool-btn.active {
  background: var(--brand-pale); border-color: var(--brand);
  color: var(--brand-deep);
}

.pdf-stage {
  max-height: 75vh; overflow: auto;
  padding: 24px;
  background: var(--gray-100);
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-md);
  user-select: none;
}
.pdf-page canvas { display: block; border-radius: 2px; }
.pdf-page .page-number {
  position: absolute;
  top: -18px; left: 0;
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--gray-500); text-transform: uppercase;
}

.field-box {
  position: absolute;
  border: 2px solid var(--brand);
  background: rgba(26,86,219,0.08);
  border-radius: 4px;
  cursor: move;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--brand-deep);
  letter-spacing: 0.5px; text-transform: uppercase;
}
.field-box.selected { box-shadow: 0 0 0 3px rgba(26,86,219,0.25); }
.field-box .field-handle {
  position: absolute; right: -6px; bottom: -6px;
  width: 12px; height: 12px;
  background: var(--brand); border: 2px solid white;
  border-radius: 50%; cursor: nwse-resize;
}
.field-box .field-remove {
  position: absolute; right: -10px; top: -10px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--error); color: white;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  cursor: pointer;
}
.field-box:hover .field-remove, .field-box.selected .field-remove { display: flex; }
.field-box .field-recipient-chip {
  position: absolute;
  top: -18px; left: 0;
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  padding: 2px 8px; border-radius: 100px;
  background: var(--brand); color: white;
  white-space: nowrap;
}

.editor-side { display: flex; flex-direction: column; gap: 16px; }
.side-card {
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1px solid var(--gray-100);
  padding: 20px;
}
.side-card h3 {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--gray-300);
  margin-bottom: 16px;
}
.recipient-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-100);
  border-radius: 10px;
  background: var(--white);
  margin-bottom: 8px;
  transition: border-color .15s;
}
.recipient-row.active { border-color: var(--brand); background: var(--brand-pale); }
.recipient-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.recipient-info { flex: 1; min-width: 0; }
.recipient-name { font-size: 13px; font-weight: 700; color: var(--black); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipient-email { font-size: 11px; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipient-del {
  width: 24px; height: 24px; border-radius: 6px;
  display: grid; place-items: center;
  color: var(--gray-500);
}
.recipient-del:hover { background: var(--error-bg); color: var(--error); }

.drop-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-card);
  padding: 80px 32px;
  text-align: center;
  background: var(--white);
  transition: all .15s;
  cursor: pointer;
}
.drop-zone.drag { border-color: var(--brand); background: var(--brand-pale); }
.drop-zone h3 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.drop-zone p { color: var(--gray-500); font-size: 14px; line-height: 1.6; max-width: 420px; margin: 0 auto 18px; }

/* ============== Sign / Mobile ============== */
.sign-page { min-height: 100vh; background: #F5F5F3; padding-bottom: 120px; }
.sign-hero {
  background: var(--black); color: var(--white);
  padding: 24px 24px 32px;
  position: relative; overflow: hidden;
}
.sign-hero::before {
  content: ''; position: absolute; top: -120px; right: -80px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(26,86,219,0.22), transparent 70%);
}
.sign-hero-inner { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; }
.sign-hero h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.8px; line-height: 1.15; margin-top: 12px; }
.sign-hero .sign-from { color: var(--gray-500); font-size: 13px; margin-top: 6px; }
.sign-hero .sign-from strong { color: var(--white); font-weight: 600; }
.sign-progress {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px;
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--brand-light); font-weight: 700;
}
.sign-progress-bar {
  flex: 1; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden;
}
.sign-progress-bar > span {
  display: block; height: 100%; background: var(--brand); transition: width .3s ease;
}

.sign-doc { max-width: 760px; margin: 24px auto; padding: 0 16px; }
.sign-message {
  background: var(--brand-pale);
  color: var(--brand-deep);
  padding: 16px 20px;
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  font-size: 14px; line-height: 1.6;
}
.sign-pages {
  display: flex; flex-direction: column; gap: 16px;
}
.sign-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  padding: 16px 24px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 -8px 24px rgba(10,10,10,0.06);
  z-index: 20;
}
.sign-footer-info { flex: 1; font-size: 13px; color: var(--gray-500); }
.sign-footer-info strong { color: var(--black); font-weight: 700; }

.field-click {
  position: absolute;
  border: 2px dashed var(--brand);
  background: rgba(26,86,219,0.08);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--brand-deep);
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all .15s;
}
.field-click:hover { background: rgba(26,86,219,0.18); }
.field-click.filled {
  border-style: solid;
  background: rgba(22,134,78,0.1);
  border-color: var(--success);
  color: #0F5132;
}
.field-click .field-preview {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 4px;
}
.field-click .field-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.field-click .field-preview span { font-weight: 700; color: var(--brand-deep); font-size: 14px; }

/* ============== Modal / Signature Pad ============== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.56);
  backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 620px;
  max-height: calc(100vh - 48px);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}
.modal-head {
  padding: 20px 28px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-head h3 { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; }
.modal-head .close {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--gray-500);
}
.modal-head .close:hover { background: var(--gray-100); color: var(--black); }
.modal-body {
  padding: 28px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.modal-foot {
  padding: 16px 28px;
  border-top: 1px solid var(--gray-100);
  display: flex; justify-content: flex-end; gap: 10px;
  background: var(--gray-50);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.sig-tabs {
  display: flex; gap: 4px;
  background: var(--gray-100); border-radius: 10px;
  padding: 4px; margin-bottom: 20px;
}
.sig-tab {
  flex: 1; padding: 8px 12px;
  font-size: 13px; font-weight: 600;
  border-radius: 7px;
  color: var(--gray-500);
  transition: all .15s;
}
.sig-tab.active { background: var(--white); color: var(--black); box-shadow: var(--shadow-sm); }
.sig-canvas-wrap {
  position: relative;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-300);
  border-radius: 10px;
  overflow: hidden;
}
.sig-canvas {
  display: block;
  width: 100%; height: 220px;
  cursor: crosshair;
  touch-action: none;
  background: linear-gradient(to bottom, transparent 0%, transparent 85%, rgba(10,10,10,0.04) 85%, rgba(10,10,10,0.04) 86%, transparent 86%);
}
.sig-canvas-hint {
  position: absolute; bottom: 10px; left: 16px;
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--gray-300); font-weight: 600;
}
.sig-type-input {
  width: 100%; font-family: 'Caveat', 'Homemade Apple', cursive;
  font-size: 48px; padding: 24px; text-align: center;
  border: 1.5px solid var(--gray-300); border-radius: 10px;
  outline: none; background: var(--gray-50);
}
.sig-type-input:focus { border-color: var(--brand); }

/* ============== Misc ============== */
.flash {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px; font-weight: 500;
  margin-bottom: 16px;
  border: 1px solid transparent;
  line-height: 1.5;
}
.flash-error { background: var(--error-bg); color: #7A1A1A; border-color: #f8c9c9; }
.flash-success { background: var(--success-bg); color: #0F5132; border-color: #c4e8d4; }
.flash-info { background: var(--info-bg); color: #0E5260; border-color: #bfe1e8; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grow { flex: 1; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.flex { display: flex; } .flex-col { flex-direction: column; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.muted { color: var(--gray-500); font-size: 13px; line-height: 1.6; }
.mono { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }

/* ============== Editor — erweitert ============== */
.editor-layout-v2 {
  display: grid;
  grid-template-columns: 72px 1fr 320px;
  gap: 16px;
  align-items: flex-start;
}
@media (max-width: 1100px) { .editor-layout-v2 { grid-template-columns: 64px 1fr 300px; } }
@media (max-width: 900px)  { .editor-layout-v2 { grid-template-columns: 1fr; } }

.pagelist {
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1px solid var(--gray-100);
  padding: 8px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
@media (max-width: 900px) {
  .pagelist { position: static; display: flex; overflow-x: auto; gap: 8px; max-height: none; }
}
.pagelist-thumb {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 6px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background .12s;
  width: 100%;
}
.pagelist-thumb:hover { background: var(--gray-50); }
.pagelist-thumb.active { background: var(--brand-pale); border-color: var(--brand); }
.pagelist-thumb-num {
  font-size: 10px; font-weight: 700; color: var(--gray-500);
  min-width: 14px;
}
.pagelist-thumb-mini {
  flex: 1;
  aspect-ratio: 3/4;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  position: relative;
  min-height: 36px;
}
.pagelist-thumb-dot {
  position: absolute; top: 2px; right: 2px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand);
}

/* Tool-Buttons als draggable */
.tool-btn[draggable="true"] { cursor: grab; user-select: none; }
.tool-btn[draggable="true"]:active { cursor: grabbing; }
.tool-btn.dragging { opacity: 0.5; }

.pdf-page.drop-target {
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
  background: var(--brand-pale);
}

/* Kontextmenü für Felder */
.ctx-menu {
  position: absolute;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  min-width: 200px;
  animation: ctx-in .1s ease-out;
}
@keyframes ctx-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ctx-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--black);
}
.ctx-menu button:hover { background: var(--gray-100); }
.ctx-menu button.danger { color: var(--error); }
.ctx-menu button.danger:hover { background: var(--error-bg); }
.ctx-menu hr { border: none; height: 1px; background: var(--gray-100); margin: 4px 2px; }
.ctx-menu .kbd {
  margin-left: auto; font-size: 11px; font-weight: 600;
  color: var(--gray-500); font-family: monospace;
  background: var(--gray-100); padding: 2px 6px; border-radius: 3px;
}

/* Undo/Redo-Toolbar */
.hist-bar { display: flex; gap: 4px; margin-left: 8px; padding-left: 8px; border-left: 1px solid var(--gray-100); }

/* Feld-Snap-Hilfslinien */
.snap-line {
  position: absolute;
  background: var(--brand);
  pointer-events: none;
  opacity: 0.8;
}
.snap-line.vertical   { width: 1px; top: 0; bottom: 0; }
.snap-line.horizontal { height: 1px; left: 0; right: 0; }

/* ============== Signing — erweitert ============== */

/* Pulsieren der aktiven Pflicht-Felder */
@keyframes field-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(26,86,219,0.45); }
  50%      { box-shadow: 0 0 0 10px rgba(26,86,219,0);   }
}
.field-click.active-hint {
  animation: field-pulse 1.6s ease-in-out infinite;
}
.field-click.required-missing {
  border-style: solid;
  border-color: var(--error);
  background: rgba(184,50,50,0.08);
  color: #7A1A1A;
}

/* Inline-Text/Datum direkt im Feld bearbeitbar */
.field-click.editing {
  padding: 0;
  cursor: text;
}
.field-click input.inline-edit {
  width: 100%; height: 100%;
  border: none; background: transparent;
  font-family: inherit; font-weight: 600;
  color: var(--brand-deep);
  text-align: center;
  outline: none; padding: 4px;
}

/* Sticky Step-Indicator für Signing */
.sign-stepper {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 12px; z-index: 5;
  margin-bottom: 16px;
}
.sign-stepper-count {
  font-size: 13px; font-weight: 700;
  color: var(--black);
  white-space: nowrap;
}
.sign-stepper-count em { color: var(--brand); font-style: normal; }
.sign-stepper-bar {
  flex: 1; height: 6px; background: var(--gray-100); border-radius: 3px; overflow: hidden;
}
.sign-stepper-bar > span {
  display: block; height: 100%; background: var(--brand);
  transition: width .25s cubic-bezier(.4,0,.2,1);
}
.sign-stepper-next {
  font-size: 13px; font-weight: 700;
  background: var(--brand); color: var(--white);
  padding: 8px 16px; border-radius: var(--radius-btn);
  white-space: nowrap;
  transition: background .15s;
}
.sign-stepper-next:hover:not(:disabled) { background: var(--brand-dark); }
.sign-stepper-next:disabled { background: var(--gray-300); cursor: not-allowed; }

/* Signatur-Modal: auf Mobile Vollbild */
.sig-modal-mobile .modal {
  max-width: none; width: 100%; height: 100%;
  border-radius: 0;
  display: flex; flex-direction: column;
}
.sig-modal-mobile .modal-body { flex: 1; display: flex; flex-direction: column; }
.sig-modal-mobile .sig-canvas-wrap { flex: 1; }
.sig-modal-mobile .sig-canvas { height: 100%; }

/* Feld-Menü (wenn angeklickt bei Typ=Text) */
.field-menu {
  position: absolute;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 10;
  min-width: 180px;
}
.field-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 8px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--black);
}
.field-menu button:hover { background: var(--gray-100); }

/* Toast */
.toast-stack {
  position: fixed; top: 16px; right: 16px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--black); color: var(--white);
  padding: 12px 16px 12px 14px;
  border-radius: var(--radius-card);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 360px;
  animation: toast-in .2s ease-out;
  border-left: 3px solid var(--brand);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--error); }
.toast.info    { border-left-color: var(--info); }
.toast .toast-close {
  opacity: 0.55; font-size: 16px; line-height: 1;
  padding-left: 4px;
}
.toast .toast-close:hover { opacity: 1; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Skeleton */
.skel {
  background: linear-gradient(90deg, var(--gray-100) 0%, #E6E6E6 50%, var(--gray-100) 100%);
  background-size: 200% 100%;
  animation: skel-move 1.4s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes skel-move {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.skel-row { height: 14px; margin-bottom: 8px; }

/* ============== Mobile Signing — Portrait ============== */
@media (max-width: 720px) {
  .sign-hero { padding: 18px 16px 20px; }
  .sign-hero h1 { font-size: 19px; line-height: 1.25; margin-top: 10px; }
  .sign-from { font-size: 12px; }
  .sign-doc { padding: 0 8px 140px; }
  .sign-footer { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); gap: 8px; }
  .sign-footer-info { display: none; }
  .sign-footer .btn { flex: 1; min-height: 48px; font-size: 14px; }
  .sign-stepper { flex-wrap: wrap; padding: 10px 14px; top: 8px; }
  .sign-stepper-count { flex: 1 0 100%; order: -1; }
  .sign-stepper-next { width: 100%; order: 2; min-height: 44px; }
  .modal-backdrop { padding: 0; }
  .modal-head { padding: 14px 18px; }
  .modal-body { padding: 18px; }
  .modal-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .consent-card { padding: 16px 18px; margin: 16px 0; }
  .consent-card p { font-size: 13px; }
  .consent-check { font-size: 13px; padding: 6px 0; }
  .consent-check input[type="checkbox"] { width: 22px; height: 22px; min-width: 22px; }

  /* Felder müssen auch bei kleinen Größen tappable sein */
  .field-click {
    min-width: 32px;
    min-height: 32px;
  }
  .field-click::after {
    /* unsichtbarer Tap-Expander 44x44 um kleine Felder (Checkbox/Datum) */
    content: '';
    position: absolute;
    inset: -10px;
    display: block;
  }
}

/* ============== Landscape-Modus: Signatur-Leinwand = Vollbild ============== */
@media (orientation: landscape) and (max-height: 500px) {
  .sign-hero { padding: 10px 16px; }
  .sign-hero h1 { font-size: 16px; margin-top: 4px; }
  .sign-from { display: none; }
  .sign-stepper { top: 4px; }
}

/* Vollbild-Signatur-Modus: aktiviert, wenn JS body.landscape-sign-mode setzt */
body.landscape-sign-mode {
  overflow: hidden;
}
/* NICHT mehr die Seite hart verstecken — das Overlay legt sich ohnehin mit z-index: 150 drüber.
   Das Verstecken führte zu Flash-Verhalten, wenn das Overlay geschlossen wurde. */
.landscape-sign {
  position: fixed; inset: 0;
  z-index: 150;
  background: var(--white);
  display: flex;
  flex-direction: column;
  color: var(--black);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* hidden-Attribut hat sonst nicht genug Spezifität gegen display: flex oben */
.landscape-sign[hidden] { display: none !important; }
.landscape-sign-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--gray-100);
  background: var(--gray-50);
}
.landscape-sign-head .close {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--gray-100); color: var(--black);
  font-size: 18px; font-weight: 700;
}
.landscape-sign-head .close:hover { background: var(--gray-300); }
.landscape-sign-head .info {
  flex: 1; min-width: 0;
}
.landscape-sign-head .info .label {
  font-size: 10px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--brand);
}
.landscape-sign-head .info .title {
  font-size: 14px; font-weight: 700; color: var(--black);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.landscape-sign-tabs {
  display: flex; gap: 4px;
  background: var(--gray-100); border-radius: 10px;
  padding: 3px;
}
.landscape-sign-tabs .tab {
  padding: 6px 14px; font-size: 12px; font-weight: 700;
  color: var(--gray-500); border-radius: 7px;
}
.landscape-sign-tabs .tab.active { background: var(--white); color: var(--black); }

.landscape-sign-canvas-wrap {
  flex: 1; position: relative;
  background: var(--white);
  overflow: hidden;
}
.landscape-sign-canvas {
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: linear-gradient(to bottom, transparent 0%, transparent 82%, rgba(10,10,10,0.05) 82%, rgba(10,10,10,0.05) 83%, transparent 83%);
}
.landscape-sign-hint {
  position: absolute; bottom: 16px; left: 20px;
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--gray-300); font-weight: 600;
  pointer-events: none;
}
.landscape-sign-type {
  display: none;
  flex: 1;
  padding: 24px;
  align-items: center; justify-content: center;
}
.landscape-sign-type.active { display: flex; }
.landscape-sign-type input {
  width: 100%; max-width: 600px;
  font-family: 'Caveat', 'Homemade Apple', cursive;
  font-size: 64px; padding: 28px 32px;
  text-align: center;
  border: 2px solid var(--gray-300); border-radius: 14px;
  outline: none; background: var(--white); color: var(--black);
}
.landscape-sign-type input:focus { border-color: var(--brand); }

.landscape-sign-foot {
  display: flex; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}
.landscape-sign-foot .btn { min-height: 48px; flex: 1; font-size: 14px; }

/* Rotation-Hint-Overlay (nur beim ersten Mal, wenn Mobile + Portrait + offene Signatur-Felder) */
.rotate-hint {
  position: fixed;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 40;
  background: var(--black);
  color: var(--white);
  padding: 12px 16px 12px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px;
  max-width: 340px;
  animation: rotate-in .24s ease-out;
  border-left: 3px solid var(--brand-light);
}
.rotate-hint-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--brand-light);
}
.rotate-hint-text {
  font-size: 13px; line-height: 1.4;
  flex: 1;
}
.rotate-hint-text strong { font-weight: 700; }
.rotate-hint-close {
  color: rgba(255,255,255,0.5);
  font-size: 18px; padding: 4px;
}
.rotate-hint-close:hover { color: white; }
@keyframes rotate-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Zoom-Kontrolle für Portrait */
.pdf-zoom-bar {
  position: fixed;
  right: 12px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 20;
  display: none;
  flex-direction: column;
  gap: 4px;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow-md);
}
@media (max-width: 720px) { .pdf-zoom-bar { display: flex; } }
.pdf-zoom-bar button {
  width: 40px; height: 40px;
  font-size: 20px; font-weight: 700;
  color: var(--black);
  border-radius: 8px;
}
.pdf-zoom-bar button:hover { background: var(--gray-100); }
.pdf-zoom-bar button:active { background: var(--gray-300); }

.pdf-page-inner { transform-origin: 0 0; transition: transform .15s ease-out; }

/* Sign-Side Thumbnail-Strip */
.sign-thumbs {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 0 16px 12px;
  scrollbar-width: thin;
}
.sign-thumbs::-webkit-scrollbar { height: 6px; }
.sign-thumbs::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
.sign-thumb {
  flex: 0 0 auto;
  position: relative;
  width: 64px; height: 90px;
  background: var(--white);
  border: 2px solid var(--gray-100);
  border-radius: 6px;
  cursor: pointer;
  display: grid; place-items: end center;
  padding: 3px;
  font-size: 10px; font-weight: 700; color: var(--gray-500);
}
.sign-thumb.active { border-color: var(--brand); }
.sign-thumb .dot-open {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand);
}
.sign-thumb.done .dot-open { background: var(--success); }

/* ============== Einwilligung ============== */
.consent-card {
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  padding: 20px 24px;
  margin-top: 16px;
}
.consent-card h3 {
  font-size: 13px; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 10px;
}
.consent-card p {
  font-size: 13px; color: var(--gray-700);
  line-height: 1.65;
}
.consent-check {
  display: flex; align-items: flex-start; gap: 10px;
  margin-top: 14px;
  font-size: 13px; font-weight: 500;
  color: var(--black);
  cursor: pointer;
  line-height: 1.55;
}
.consent-check input[type="checkbox"] {
  width: 18px; height: 18px; min-width: 18px;
  accent-color: var(--brand);
  margin-top: 2px;
}
.legal-links {
  margin-top: 14px;
  font-size: 11px;
  color: var(--gray-500);
}
.legal-links a {
  color: var(--brand);
  font-weight: 600;
  margin-right: 16px;
}
.legal-links a:hover { text-decoration: underline; }

/* ============== Wizard ============== */
.wizard-shell {
  max-width: 900px;
  margin: 0 auto;
}
.wizard-stepper {
  display: flex; align-items: center; gap: 0;
  margin: 24px 0 32px;
  padding: 0;
}
.wizard-step {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  font-size: 13px; font-weight: 600;
  color: var(--gray-500);
  border-radius: 100px;
  transition: all .15s;
  white-space: nowrap;
}
.wizard-step.active {
  background: var(--black); color: var(--white);
}
.wizard-step.done {
  color: var(--success);
}
.wizard-step-num {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 11px; font-weight: 800;
  background: var(--gray-100); color: var(--gray-500);
}
.wizard-step.active .wizard-step-num { background: var(--brand); color: white; }
.wizard-step.done .wizard-step-num { background: var(--success); color: white; }
.wizard-step-sep {
  flex: 1; height: 1px;
  background: var(--gray-100);
  margin: 0 8px;
}
.wizard-section {
  background: var(--white);
  border-radius: var(--radius-xl);
  border: 1px solid var(--gray-100);
  padding: 40px;
  box-shadow: var(--shadow-sm);
}
.wizard-section h2 {
  font-size: 24px; font-weight: 800; letter-spacing: -0.8px;
  margin-bottom: 8px;
}
.wizard-section .section-desc {
  color: var(--gray-500); font-size: 15px; line-height: 1.6;
  margin-bottom: 24px; max-width: 540px;
}
.wizard-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--gray-100);
}

/* Vorlagen-Kacheln */
.tpl-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.tpl-card {
  background: var(--white);
  border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-card);
  padding: 20px;
  cursor: pointer;
  transition: all .15s;
  position: relative;
}
.tpl-card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.tpl-card.selected {
  border-color: var(--brand);
  background: var(--brand-pale);
}
.tpl-card-title {
  font-size: 16px; font-weight: 700; letter-spacing: -0.2px;
  color: var(--black);
  margin-bottom: 6px;
}
.tpl-card-desc {
  font-size: 12px; color: var(--gray-500);
  line-height: 1.5; margin-bottom: 12px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tpl-card-meta {
  display: flex; gap: 8px; flex-wrap: wrap;
  font-size: 11px; color: var(--gray-500);
}
.tpl-card-meta .badge {
  font-size: 10px; padding: 2px 8px;
}

/* Upload-Karte im Wizard */
.upload-tile {
  background: var(--white);
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-card);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
}
.upload-tile:hover, .upload-tile.drag {
  border-color: var(--brand);
  background: var(--brand-pale);
}
.upload-tile-icon {
  width: 48px; height: 48px;
  margin: 0 auto 12px;
  background: var(--brand-pale);
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--brand);
}
.upload-tile h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.upload-tile p { font-size: 12px; color: var(--gray-500); }

/* Stats-Kacheln */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  padding: 20px 24px;
}
.stat-card-label {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--gray-500);
}
.stat-card-value {
  font-size: 32px; font-weight: 800; letter-spacing: -1px;
  color: var(--black);
  margin-top: 8px;
  line-height: 1;
}
.stat-card-sub {
  font-size: 12px; color: var(--gray-500);
  margin-top: 6px;
}
.stat-card.highlight { background: var(--black); color: var(--white); }
.stat-card.highlight .stat-card-label { color: var(--brand-light); }
.stat-card.highlight .stat-card-value { color: var(--white); }
.stat-card.highlight .stat-card-sub { color: rgba(255,255,255,0.5); }
.stat-card.warning .stat-card-value { color: var(--error); }

/* ============== Content-Template-Editor ============== */
.content-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  align-items: flex-start;
}
@media (max-width: 1000px) { .content-layout { grid-template-columns: 1fr; } }

.md-editor {
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1px solid var(--gray-100);
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 600px;
}
.md-toolbar {
  display: flex; gap: 6px; padding: 10px 14px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
  flex-wrap: wrap;
}
.md-toolbar button {
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  border-radius: 6px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.md-toolbar button:hover { border-color: var(--black); color: var(--black); }
.md-toolbar .sep { width: 1px; background: var(--gray-100); align-self: stretch; margin: 4px 2px; }
.md-textarea {
  flex: 1; min-height: 480px;
  padding: 20px 24px;
  border: none; outline: none;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', 'Monaco', monospace;
  font-size: 13.5px;
  line-height: 1.65;
  resize: none;
  color: var(--black);
  background: var(--white);
  tab-size: 2;
  width: 100%;
}
.md-textarea:focus { background: #fafafa; }

.md-split {
  display: grid; grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 560px;
}
.md-split.view-editor { grid-template-columns: 1fr 0fr; }
.md-split.view-preview { grid-template-columns: 0fr 1fr; }
.md-split.view-preview .md-textarea { display: none; }
.md-split.view-editor .md-preview { display: none; }

.md-preview {
  overflow: auto;
  border-left: 1px solid var(--gray-100);
  padding: 24px 32px;
  background: var(--gray-50);
}
.md-preview-body {
  background: var(--white);
  padding: 32px 40px;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  color: var(--black);
  line-height: 1.7;
  font-size: 14px;
  min-height: 100%;
}
.md-preview-body h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.8px; margin: 20px 0 12px; }
.md-preview-body h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.4px; margin: 18px 0 10px; }
.md-preview-body h3 { font-size: 15px; font-weight: 700; margin: 16px 0 8px; }
.md-preview-body p  { margin: 0 0 12px; }
.md-preview-body ul, .md-preview-body ol { padding-left: 22px; margin: 0 0 12px; }
.md-preview-body li { margin-bottom: 4px; }
.md-preview-body hr { border: none; border-top: 1px solid var(--gray-300); margin: 18px 0; }
.md-preview-body code {
  background: var(--gray-100); padding: 1px 6px; border-radius: 4px;
  font-size: 12px; color: var(--brand-deep);
}
.md-preview-body blockquote {
  border-left: 3px solid var(--gray-300);
  padding: 4px 14px; margin: 10px 0;
  color: var(--gray-500); font-style: italic;
}
.md-preview-body table {
  width: 100%; border-collapse: collapse; margin: 10px 0;
}
.md-preview-body th, .md-preview-body td {
  padding: 6px 10px; border-bottom: 1px solid var(--gray-100);
  text-align: left;
}
.md-preview-body th { font-weight: 700; background: var(--gray-50); }
.md-preview-body img {
  max-width: 100%; height: auto;
  display: block; margin: 12px auto;
  border-radius: 4px;
}

/* Autocomplete-Popup */
.ac-popup {
  position: fixed;
  z-index: 200;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  min-width: 240px;
  max-width: 420px;
  max-height: 260px;
  overflow-y: auto;
}
.ac-popup-head {
  padding: 6px 12px;
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
}
.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.ac-item:hover, .ac-item.active {
  background: var(--brand-pale);
}
.ac-item-key {
  font-family: 'SF Mono', monospace; font-size: 12px;
  color: var(--brand-deep); font-weight: 600;
}
.ac-item-label {
  color: var(--gray-500); font-size: 12px;
}
.ac-item-hint {
  margin-left: auto;
  font-size: 10px; color: var(--gray-300);
  font-family: monospace;
}

/* Platzhalter-Highlights in der Live-Preview */
.md-preview-body .ph-var {
  background: var(--brand-pale); color: var(--brand-deep);
  padding: 1px 6px; border-radius: 4px;
  font-weight: 600; font-size: 13px;
}
.md-preview-body .ph-sig {
  display: inline-block;
  padding: 4px 14px; border: 1.5px dashed var(--brand);
  border-radius: 4px; background: rgba(26,86,219,0.05);
  color: var(--brand-deep); font-size: 11px;
  font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
}
.md-preview-body .ph-block-missing {
  color: var(--error); font-style: italic;
}

@media (max-width: 1100px) {
  .md-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .md-split.view-editor { grid-template-rows: 1fr 0fr; }
  .md-split.view-preview { grid-template-rows: 0fr 1fr; }
}

.var-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.var-table th, .var-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}
.var-table th {
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gray-500);
  background: var(--gray-50);
}
.var-table input, .var-table select {
  width: 100%;
  padding: 6px 10px; font-size: 13px;
  border: 1.5px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
}
.var-table input:focus, .var-table select:focus {
  border-color: var(--brand); background: var(--white);
  outline: none;
}
.var-key {
  font-family: monospace; font-size: 12px;
  color: var(--brand-deep); font-weight: 700;
  background: var(--brand-pale);
  padding: 2px 8px; border-radius: 4px;
  display: inline-block;
}
.var-unused {
  opacity: 0.5;
}
.var-missing {
  color: var(--error); font-size: 11px; font-weight: 600;
}

.block-list {
  display: grid; gap: 10px;
  max-height: 400px; overflow-y: auto;
}
.block-item {
  padding: 10px 12px;
  border: 1px solid var(--gray-100);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  transition: border-color .15s;
}
.block-item:hover { border-color: var(--brand); }
.block-item-title {
  font-size: 13px; font-weight: 700; color: var(--black);
}
.block-item-meta {
  font-size: 11px; color: var(--gray-500); margin-top: 2px;
}

.preview-frame {
  width: 100%;
  border: 1px solid var(--gray-100);
  border-radius: 6px;
  background: var(--gray-100);
}

/* ============== Completed / Success ============== */
.success-hero {
  text-align: center; padding: 80px 24px 60px;
  background: var(--white);
  border-radius: var(--radius-xl);
  margin-top: 32px;
}
.success-hero .check {
  width: 72px; height: 72px; margin: 0 auto 20px;
  background: var(--success); color: white;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 32px;
}
.success-hero h1 { font-size: 32px; font-weight: 800; letter-spacing: -1px; margin-bottom: 8px; }
.success-hero p { color: var(--gray-500); max-width: 460px; margin: 0 auto 24px; line-height: 1.7; }


/* ============================================================
   ENTERPRISE-LAYOUT — Sidebar + Content-Area
   ============================================================ */

body.has-sidebar {
  background: var(--content-bg);
}

.app-shell, #app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  transition: grid-template-columns .22s cubic-bezier(.4,0,.2,1);
}
body.sidebar-collapsed .app-shell,
body.sidebar-collapsed #app-shell {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

.sidebar {
  background: var(--sidebar-bg);
  color: rgba(255,255,255,0.86);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: relative;
  min-height: 62px;
}
.sidebar-brand .wordmark {
  font-size: 17px; font-weight: 800; letter-spacing: -0.5px; color: #fff;
  transition: opacity .12s;
}
.sidebar-brand .sub {
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--brand-light); font-weight: 700;
  padding-left: 10px; margin-left: 6px;
  border-left: 1px solid rgba(255,255,255,0.14);
  transition: opacity .12s;
}

.sidebar-toggle {
  position: absolute;
  right: -13px; top: 19px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  z-index: 5;
  transition: all .1s;
}
.sidebar-toggle:hover {
  background: var(--brand);
  color: var(--white);
  border-color: var(--brand);
  transform: scale(1.08);
}
.sidebar-toggle svg { transition: transform .2s; }
body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* Collapsed-Zustand: nur Icons, Labels ausblenden */
body.sidebar-collapsed .sidebar-brand .wordmark,
body.sidebar-collapsed .sidebar-brand .sub {
  opacity: 0; pointer-events: none; width: 0; overflow: hidden; margin: 0; padding: 0; border: 0;
}
body.sidebar-collapsed .sidebar-section {
  padding: 12px 6px 4px;
  text-align: center;
  font-size: 8px;
  letter-spacing: 1px;
}
body.sidebar-collapsed .sidebar-nav a {
  justify-content: center;
  padding: 10px 8px;
  position: relative;
}
body.sidebar-collapsed .sidebar-nav a > span {
  display: none;
}
body.sidebar-collapsed .sidebar-nav a.active::before {
  left: 0;
}
/* Tooltip auf Hover (im collapsed-Modus) */
body.sidebar-collapsed .sidebar-nav a:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--black);
  color: var(--white);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px; font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  z-index: 100;
  pointer-events: none;
}
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .sidebar-user-logout span {
  display: none;
}
body.sidebar-collapsed .sidebar-user {
  padding: 10px;
}
body.sidebar-collapsed .sidebar-user-row {
  justify-content: center;
}
body.sidebar-collapsed .sidebar-user-logout {
  margin-top: 8px;
  padding: 7px;
}

.sidebar-section {
  padding: 14px 14px 4px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: rgba(255,255,255,0.30);
}
.sidebar-section:first-of-type { padding-top: 18px; }

.sidebar-nav {
  display: flex; flex-direction: column;
  padding: 4px 10px 4px;
  gap: 1px;
}
.sidebar-spacer { flex: 1; min-height: 12px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  font-size: 13.5px; font-weight: 500;
  color: rgba(255,255,255,0.68);
  border-radius: 8px;
  transition: background .1s, color .1s;
  position: relative;
}
.sidebar-nav a svg {
  flex-shrink: 0;
  stroke: currentColor; stroke-width: 1.6;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.sidebar-nav a:hover {
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.96);
}
.sidebar-nav a.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 600;
}
.sidebar-nav a.active::before {
  content: ''; position: absolute;
  left: -10px; top: 8px; bottom: 8px;
  width: 3px; background: var(--brand-light); border-radius: 0 2px 2px 0;
}

.sidebar-user {
  padding: 14px 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
}
.sidebar-user-row {
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: 11px; color: rgba(255,255,255,0.42);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-logout {
  margin-top: 10px; width: 100%;
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.68);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px; font-weight: 500;
  transition: all .1s;
}
.sidebar-user-logout:hover {
  background: rgba(255,255,255,0.10);
  color: #fff;
}

/* Content-Area */
.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--content-bg);
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px;
  background: var(--content-bg);
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
  background: rgba(247,247,245,0.85);
}
.app-header-title {
  display: flex; align-items: center; gap: 10px;
}
.app-header-title h1 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.3px;
}
.app-header-breadcrumb {
  font-size: 12px; color: var(--gray-500); font-weight: 500;
}
.app-header-breadcrumb a { color: var(--gray-500); }
.app-header-breadcrumb a:hover { color: var(--black); }

.app-content {
  flex: 1;
  padding: 32px 40px 64px;
  width: 100%;
}
/* Bei sehr breiten Screens etwas gefasst, aber fluide bis ~1600px */
@media (min-width: 1700px) {
  .app-content { padding: 32px 64px 64px; }
}

/* Überschriebene Page-Head-Varianten für neue Struktur */
.page-hero {
  margin-bottom: 28px;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 24px; flex-wrap: wrap;
}
.page-hero h1 {
  font-size: 32px; font-weight: 800; letter-spacing: -1.2px;
  line-height: 1.15;
}
.page-hero .lead {
  color: var(--gray-500); font-size: 14px;
  line-height: 1.6; margin-top: 6px; max-width: 540px;
}
.page-hero-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
}

/* Enterprise-Tabellen (für Dokumenten-Liste etc.) */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}
.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.table tbody tr { transition: background .08s; }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table .cell-title {
  font-weight: 600; color: var(--black);
}
.table .cell-sub {
  font-size: 12px; color: var(--gray-500);
  margin-top: 2px;
}
.table .cell-meta {
  font-size: 12.5px; color: var(--gray-600);
}

/* Feinere Stat-Cards */
.stat-card {
  padding: 18px 22px;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-xs);
}
.stat-card .stat-card-label {
  font-size: 10.5px; letter-spacing: 1.2px;
  color: var(--gray-500);
}
.stat-card .stat-card-value {
  font-size: 28px; font-weight: 800; letter-spacing: -0.8px;
  line-height: 1.1;
  margin-top: 6px;
}
.stat-card .stat-card-sub {
  font-size: 11.5px; margin-top: 4px;
}
.stat-card.highlight {
  background: linear-gradient(140deg, var(--black) 0%, #1a1a1d 100%);
}

/* Moderne Toolbar (Filter + Suche inline) */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--white);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.toolbar .input {
  flex: 1; min-width: 220px;
  padding: 8px 12px; font-size: 13px;
  border-color: var(--gray-200);
}
.toolbar .toolbar-tabs {
  display: inline-flex; gap: 2px;
  background: var(--gray-75);
  padding: 3px;
  border-radius: 8px;
}
.toolbar .toolbar-tab {
  padding: 6px 12px;
  font-size: 12.5px; font-weight: 600;
  border-radius: 6px;
  color: var(--gray-500);
  transition: all .1s;
}
.toolbar .toolbar-tab:hover { color: var(--black); }
.toolbar .toolbar-tab.active {
  background: var(--white);
  color: var(--black);
  box-shadow: var(--shadow-xs);
}

/* Mobile: Sidebar wird zum unteren Rand */
@media (max-width: 860px) {
  .app-shell, #app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    position: sticky; top: 0;
    height: auto; max-height: none;
    flex-direction: row;
    align-items: center;
    padding: 0 12px;
    overflow-x: auto; overflow-y: hidden;
  }
  .sidebar-brand {
    padding: 14px 12px; border-bottom: none;
    border-right: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
  }
  .sidebar-section, .sidebar-user { display: none; }
  .sidebar-nav {
    flex-direction: row;
    padding: 8px 4px;
    overflow-x: auto;
    gap: 2px;
    flex-wrap: nowrap;
  }
  .sidebar-nav a {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12.5px;
  }
  .sidebar-nav a.active::before { display: none; }
  .app-header { padding: 14px 16px; }
  .app-content { padding: 20px 16px 48px; }
}

/* Refined buttons */
.btn-brand {
  box-shadow: var(--shadow-xs);
}
.btn-brand:hover:not(:disabled) {
  box-shadow: 0 2px 8px rgba(26, 86, 219, 0.3);
}

/* =========================================================
   Mobile-Layout (Servecta Sign)
   ========================================================= */

/* Hamburger-Button — nur mobil sichtbar */
.sig-mobile-toggle {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--gray-200);
  border-radius: 10px;
  cursor: pointer; color: var(--gray-900);
  flex-shrink: 0;
}
.sig-mobile-toggle:hover { background: var(--gray-75); }

/* Sidebar-Overlay (nur mobil) */
.sig-sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, 0.45);
  z-index: 40; opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
body.sidebar-open .sig-sidebar-overlay,
.app-shell.sidebar-open .sig-sidebar-overlay {
  opacity: 1; pointer-events: auto;
}

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app-shell,
  #app-shell {
    grid-template-columns: 1fr !important;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 50;
    width: 84%; max-width: 300px;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  body.sidebar-open .sidebar,
  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sig-mobile-toggle { display: inline-flex; }

  .app-header { padding: 12px 14px; gap: 10px; }
  .app-header-title h1 { font-size: 16px; }
  .app-header-breadcrumb { display: none; }

  .app-content { padding: 16px 14px 80px; }

  /* Topbar (öffentliche Seiten) */
  .topbar { padding: 0 14px; }
  .topbar-nav { display: none; }
  .topbar .brand .sub { display: none; }
  .topbar-user span { display: none; }

  .page { padding: 24px 14px 80px; }
  .page-head { margin-bottom: 20px; }
  .page-title { font-size: 24px !important; }

  /* Tabellen mobil scrollen */
  .table-wrap, .doc-row-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modals vollflächig */
  .modal-backdrop { padding: 0 !important; }
  .modal { max-width: 100% !important; width: 100% !important; height: 100%; max-height: 100% !important; border-radius: 0 !important; }

  /* Touch-Zielgrößen */
  .btn { min-height: 40px; }
  .btn-brand, .btn-secondary, .btn-danger, .btn-ghost { min-height: 40px; }

  /* Document-Row auf Mobile: kompakter */
  .doc-row { grid-template-columns: 1fr; row-gap: 6px; }

  /* Login-Grid: stackt */
  .auth-wrap { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
  .page-title { font-size: 20px !important; }
  .app-content { padding: 12px 10px 80px; }
  .page { padding: 16px 10px 80px; }
}
