:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --blue-light: #eff4ff;
  --green: #15803d;
  --green-light: #ecfdf3;
  --amber: #b45309;
  --amber-light: #fffaeb;
  --red: #b91c1c;
  --red-light: #fef2f2;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--gray-900);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 20px 0;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}
.brand span { font-weight: 400; color: var(--gray-400); }
.brand-logo { max-width: 140px; max-height: 40px; margin-bottom: 8px; display: block; }
.brand-company { font-size: 16px; font-weight: 700; color: #fff; line-height: 1.25; }
.brand-product { font-size: 11px; font-weight: 400; color: var(--gray-400); margin-top: 1px; }

.sidebar-search { padding: 0 20px 14px; position: relative; }
.sidebar-search input {
  width: 100%; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  color: #fff; padding: 7px 34px 7px 10px; border-radius: 6px; font-size: 13px;
}
.sidebar-search input::placeholder { color: #64748b; }
.sidebar-search input:focus { outline: none; border-color: var(--blue); background: rgba(255,255,255,0.12); }
.cmdk-hint-btn {
  position: absolute; right: 21px; top: 4px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14);
  color: #94a3b8; font-size: 10.5px; font-weight: 700; border-radius: 5px; padding: 4px 6px; cursor: pointer; line-height: 1;
}
.cmdk-hint-btn:hover { background: rgba(255,255,255,0.16); color: #fff; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0 10px; overflow-y: auto; }
.sidebar nav a {
  color: #cbd5e1;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.nav-with-badge { display: flex; align-items: center; justify-content: space-between; }
.nav-badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px; display: inline-flex;
  align-items: center; justify-content: center; padding: 0 5px;
}
.nav-group-label {
  color: #64748b; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 12px 12px 4px;
  background: none; border: none; width: 100%; text-align: left; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; font-family: inherit;
}
.nav-group-label:hover { color: #94a3b8; }
.nav-group-caret { transition: transform 0.15s ease; font-size: 9px; }
.nav-group-label[aria-expanded="false"] .nav-group-caret { transform: rotate(-90deg); }
.nav-group { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.nav-group.collapsed { display: none; }

/* Command palette (Ctrl/Cmd+K): quick-jump to any visible sidebar destination. */
.cmdk-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 70;
}
.cmdk {
  position: fixed; top: 12vh; left: 50%; transform: translateX(-50%); width: min(480px, calc(100vw - 32px));
  background: #fff; border-radius: 10px; box-shadow: 0 20px 50px rgba(15,23,42,0.3); z-index: 71;
  display: flex; flex-direction: column; max-height: 70vh; overflow: hidden;
}
.cmdk[hidden], .cmdk-backdrop[hidden] { display: none; }
.cmdk input {
  border: none; border-bottom: 1px solid var(--gray-200); padding: 16px 18px; font-size: 15px; color: var(--gray-900);
}
.cmdk input:focus { outline: none; }
.cmdk-list { overflow-y: auto; padding: 6px; }
.cmdk-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 6px; font-size: 13.5px;
  color: var(--gray-800); cursor: pointer;
}
.cmdk-item.selected { background: var(--blue); color: #fff; }
.cmdk-item-group { color: var(--gray-400); font-size: 11.5px; margin-left: auto; }
.cmdk-item.selected .cmdk-item-group { color: rgba(255,255,255,0.75); }
.cmdk-empty { padding: 16px; color: var(--gray-600); font-size: 13.5px; text-align: center; }
.cmdk-hint { border-top: 1px solid var(--gray-200); padding: 8px 14px; color: var(--gray-400); font-size: 11px; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 14px 20px 0;
  margin-top: 12px;
}
.user-link { display: flex; flex-direction: column; gap: 4px; color: #fff; font-weight: 600; margin-bottom: 10px; }
.role-badge {
  display: inline-block; width: fit-content;
  background: rgba(255,255,255,0.12); color: #cbd5e1;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px;
}
.link-btn {
  background: none; border: none; color: #94a3b8; font-size: 13px; cursor: pointer; padding: 0;
}
.link-btn:hover { color: #fff; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 28px 36px; max-width: 1200px; } /* min-width:0 lets wide tables scroll inside their card instead of stretching the page */
.content.full {
  max-width: none; display: flex; align-items: center; justify-content: center; min-height: 100vh;
  padding: 20px;
}

h1 { font-size: 22px; margin: 0 0 4px; color: var(--gray-900); }
h2 { font-size: 17px; margin: 0 0 12px; color: var(--gray-900); }
h3 { font-size: 14px; margin: 0 0 8px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.subtitle { color: var(--gray-600); font-size: 13.5px; margin: 0; }

.card {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
  overflow-x: auto; /* contains wide tables so the page body never scrolls sideways */
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-number { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-label { color: var(--gray-600); font-size: 13px; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gray-100); font-size: 13.5px; }
th { color: var(--gray-600); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
tr:hover td { background: var(--gray-50); }
table.plain tr:hover td { background: none; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-red { background: var(--red-light); color: var(--red); }

.signature-pad { border: 1px solid var(--gray-200); border-radius: 6px; background: #fff; touch-action: none; cursor: crosshair; max-width: 100%; }
.signature-thumb { max-height: 32px; max-width: 90px; border: 1px solid var(--gray-200); border-radius: 4px; background: #fff; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue); color: #fff; border: none;
  padding: 9px 16px; border-radius: 6px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--blue-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger { background: #fff; color: var(--red); border: 1px solid #fecaca; }
.btn-danger:hover { background: var(--red-light); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #14632f; }
.btn:disabled, .btn:disabled:hover { opacity: 0.6; cursor: wait; }

form.inline { display: inline; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-800); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--gray-200); border-radius: 6px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--gray-900);
}
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.checkbox-list { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; border: 1px solid var(--gray-200); border-radius: 6px; padding: 10px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; }
.checkbox-list input { width: auto; }

.alert { padding: 11px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 16px; }
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid #bbf7d0; }
.alert-warn { background: var(--amber-light); color: var(--amber); border: 1px solid #fde68a; }

.login-card { width: 380px; }
.login-card .brand { color: var(--gray-900); text-align: center; padding: 0 0 20px; border: none; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand-mark { width: 40px; height: 40px; border-radius: 9px; }
.hint { color: var(--gray-400); font-size: 12px; margin-top: 14px; text-align: center; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-600); }

.process-col { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.process-col-header { padding: 12px 16px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; }
.process-col.fuehrung .process-col-header { background: var(--blue-light); color: var(--blue); }
.process-col.kern .process-col-header { background: var(--green-light); color: var(--green); }
.process-col.unterstuetzung .process-col-header { background: var(--amber-light); color: var(--amber); }
.process-item { padding: 12px 16px; border-top: 1px solid var(--gray-100); }
.process-item a { font-weight: 600; color: var(--gray-900); }
.process-item .meta { color: var(--gray-600); font-size: 12.5px; margin-top: 3px; }

.timeline-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--gray-100); }
.timeline-item:first-child { border-top: none; }
.version-tag { font-weight: 700; color: var(--gray-900); min-width: 36px; }

.matrix-table { overflow-x: auto; }
.matrix-table table { min-width: 600px; }
.matrix-cell-ok { color: var(--green); font-weight: 700; }
.matrix-cell-warn { color: var(--amber); font-weight: 700; }
.matrix-cell-bad { color: var(--red); font-weight: 700; }
.matrix-cell-none { color: var(--gray-400); }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--blue-light); border: 1px solid var(--gray-200); border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; color: var(--gray-800); }
.bulk-bar[hidden] { display: none; }
.bulk-bar select { padding: 5px 8px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 13px; }

.flowchart-scroll { overflow-x: auto; padding-bottom: 4px; }
.flowchart-scroll svg a rect { transition: fill 0.15s; }
.flowchart-scroll svg a:hover rect { fill: var(--blue); }
.flowchart-scroll svg a:hover text { fill: #fff !important; }
.flowchart-scroll svg a { cursor: pointer; }

.handbook-category { margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--gray-200); break-after: avoid; }
.handbook-process { margin-bottom: 14px; }
.handbook-steps { margin: 6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.handbook-meta { color: var(--gray-600); font-size: 13px; }

.dist-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dist-title { font-size: 12px; font-weight: 700; color: var(--gray-600); margin-bottom: 6px; }
@media (max-width: 600px) { .dist-picker { grid-template-columns: 1fr; } }
.iso-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.iso-picker fieldset { border: 1px solid var(--gray-200); border-radius: 6px; padding: 8px 10px 6px; margin: 0; min-width: 0; }
.iso-picker legend { font-size: 12px; font-weight: 700; color: var(--gray-600); padding: 0 4px; }
.iso-option { display: flex; align-items: flex-start; gap: 7px; font-weight: 400; margin: 0 0 4px; font-size: 12.5px; line-height: 1.35; }
.iso-option input { width: auto; margin-top: 2px; flex-shrink: 0; }

.trend-scroll { overflow-x: auto; }
.trend-chart { width: 100%; min-width: 420px; height: auto; display: block; }

.onboarding-card { border-left: 4px solid var(--blue); }
.onboarding-progress { background: var(--gray-100); border-radius: 999px; height: 8px; overflow: hidden; margin-bottom: 14px; }
.onboarding-progress-bar { background: var(--blue); height: 100%; border-radius: 999px; transition: width 0.2s; }
.onboarding-list { display: flex; flex-direction: column; gap: 8px; }
.onboarding-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--gray-800); }
.onboarding-item:hover { background: var(--gray-50); }
.onboarding-check { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.onboarding-check-done { background: var(--green-light); color: var(--green); }
.onboarding-check-open { border: 2px solid var(--gray-200); color: transparent; }
.onboarding-item-done { color: var(--gray-400); text-decoration: line-through; }
.dismiss-btn { background: none; border: none; color: var(--gray-400); font-size: 12px; cursor: pointer; padding: 0; }
.dismiss-btn:hover { color: var(--gray-800); text-decoration: underline; }

.checklist-items { display: flex; flex-direction: column; gap: 4px; }
.checklist-item { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--gray-100); }
.checklist-item:last-child { border-bottom: none; }
.checklist-item-question { font-size: 14px; }
.checklist-item-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.checklist-item-form form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.checklist-item-form input[type="text"] { flex: 1 1 180px; min-width: 140px; }

.risk-matrix { display: grid; width: max-content; gap: 3px; }
.risk-matrix-cell {
  width: 56px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-weight: 700; font-size: 13px; color: #fff;
}
.risk-matrix-axis { font-size: 11px; color: var(--gray-600); text-align: center; }
.risk-cell-green { background: #16a34a; }
.risk-cell-amber { background: #d97706; }
.risk-cell-red { background: #dc2626; }
.risk-cell-empty { background: transparent; color: var(--gray-400) !important; }

.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .app-shell { display: block; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    background: var(--gray-900); color: #fff; padding: 12px 16px;
    position: sticky; top: 0; z-index: 30;
  }
  .mobile-menu-btn {
    background: none; border: none; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 6px;
  }
  .mobile-topbar-title { font-weight: 700; font-size: 15px; }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 50;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .content { padding: 20px 16px; max-width: none; }
  .content.full { min-height: calc(100vh - 0px); }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.print-header { display: none; }
.print-only, .print-watermark { display: none; }

@media print {
  .sidebar, .no-print, form:not(.print-keep), .btn { display: none !important; }
  .flowchart-scroll { overflow: visible !important; }
  .flowchart-scroll svg { max-width: 100%; height: auto; }
  .app-shell, .content { display: block !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  body { background: #fff !important; font-size: 11pt; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
  .print-only { display: block !important; border: 1px solid #999; padding: 6px 10px; margin-bottom: 12px; font-size: 10pt; }
  .print-watermark {
    display: block !important; position: fixed; top: 38%; left: 0; right: 0; text-align: center;
    font-size: 60pt; font-weight: 800; letter-spacing: 4px; color: rgba(0, 0, 0, 0.07); transform: rotate(-28deg); z-index: 0; pointer-events: none;
  }
  .print-header {
    display: block !important; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 16px;
  }
  .print-header .brand-line { font-size: 16pt; font-weight: 700; }
  .print-header .meta-line { font-size: 10pt; color: #555; margin-top: 4px; }
  a { color: #000 !important; text-decoration: none !important; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}

/* Form template builder */
.builder-row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; padding: 10px; margin-bottom: 8px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--gray-50); }
.builder-main { display: flex; gap: 8px; flex: 1 1 380px; flex-wrap: wrap; }
.builder-main input[type=text] { flex: 2 1 200px; min-width: 0; }
.builder-main select { flex: 1 1 120px; min-width: 0; }
.builder-extra { display: flex; gap: 8px; flex: 1 1 100%; flex-wrap: wrap; }
.builder-extra input[type=text] { flex: 1 1 200px; min-width: 0; }
.builder-actions { display: flex; gap: 4px; }
.decision-only { display: contents; }
.decision-only[hidden], .flow-next[hidden] { display: none; }

/* Language switch */
.lang-switch { display: flex; gap: 10px; font-size: 12px; padding: 4px 0 8px; }
.lang-switch a { color: #9aa3b2; text-decoration: none; }
.lang-switch a.active { color: #fff; font-weight: 700; text-decoration: underline; }
.lang-switch-top { position: absolute; top: 12px; right: 16px; }
.lang-switch-top a { color: var(--gray-600); }
.lang-switch-top a.active { color: var(--blue); }
@media print { .lang-switch { display: none !important; } }

/* Document folder browser */
.breadcrumb { font-size: 13px; }
.breadcrumb a { font-weight: 600; }
.folder-meta { color: var(--gray-600); font-size: 12px; margin-top: 2px; }
