/* ================================================================
   Audit-Cockpit — ISO 9001:2015 Rezertifizierungs-Vorbereitung
   Design-Tokens (siehe dataviz-Referenzpalette) + Komponenten
   ================================================================ */

:root {
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ed;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  --series-blue: #2a78d6;
  --series-orange: #eb6834;
  --series-aqua: #1baf7a;
  --series-yellow: #eda100;
  --series-magenta: #e87ba4;
  --series-green: #008300;
  --series-violet: #4a3aa7;
  --series-red: #e34948;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --success-text: #006300;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(11,11,11,0.04), 0 8px 24px -12px rgba(11,11,11,0.12);
  --shadow-modal: 0 20px 60px -12px rgba(11,11,11,0.35);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255,255,255,0.10);
  --gridline: #2c2c2a;
  --baseline: #383835;

  --series-blue: #3987e5;
  --series-orange: #d95926;
  --series-aqua: #199e70;
  --series-yellow: #c98500;
  --series-magenta: #d55181;
  --series-green: #008300;
  --series-violet: #9085e9;
  --series-red: #e66767;

  --success-text: #0ca30c;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.6);
  --shadow-modal: 0 20px 60px -12px rgba(0,0,0,0.7);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
}
.brand-mark { color: var(--series-blue); display: inline-flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { color: var(--text-muted); transition: color .15s ease; }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.is-active { background: var(--series-blue); color: #fff; }
.nav-item.is-active svg { color: #fff; }
.nav-badge {
  margin-left: auto;
  background: var(--status-critical);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}
.nav-item.is-active .nav-badge { background: rgba(255,255,255,0.28); }
.nav-badge[data-zero="true"] { display: none; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

/* ---------------- Topbar ---------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--page);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title h1 { font-size: 20px; }
.topbar-title p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.only-mobile { display: none; }

.countdown-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.countdown-chip svg { width: 15px; height: 15px; color: var(--series-blue); }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--series-blue); color: #fff; }
.btn-primary:hover { background: #2166ba; }
.btn-ghost { background: var(--surface-1); border-color: var(--border); color: var(--text-primary); }
.btn-ghost:hover { background: var(--surface-2); }

/* ---------------- Content ---------------- */
.content { padding: 24px 28px 60px; max-width: 1320px; width: 100%; margin: 0 auto; }
.view[hidden] { display: none; }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.stat-tile-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-tile-head span { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.stat-icon svg { width: 16px; height: 16px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: proportional-nums; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow-card);
}
.card-center { display: flex; flex-direction: column; }
.card-head { margin-bottom: 14px; }
.card-head h2 { font-size: 15px; }
.card-head p { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.card-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.link-btn {
  background: none; border: none; color: var(--series-blue);
  font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; padding: 2px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------- Chapter bars ---------------- */
.chapter-bars { display: flex; flex-direction: column; gap: 12px; }
.chapter-bar-row { display: grid; grid-template-columns: 140px 1fr 42px; align-items: center; gap: 10px; }
.chapter-bar-row .label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-bar-row .pct { font-size: 12.5px; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--gridline); border-radius: 999px; overflow: hidden; }
.bar-sm { height: 8px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--series-blue); transition: width .4s ease; }

/* ---------------- Donut ---------------- */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; flex: 1; justify-content: center; }
.donut-figure { position: relative; width: 190px; height: 190px; }
.donut-figure svg { width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center .val { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.donut-center .lbl { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.donut-legend { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.donut-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.donut-legend-dot { width: 9px; height: 9px; border-radius: 3px; }

/* ---------------- Mini list ---------------- */
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-list-tall { max-height: 420px; overflow-y: auto; }
.mini-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.mini-row-main { flex: 1; min-width: 0; }
.mini-row-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.mini-row-time { font-size: 12.5px; font-weight: 700; color: var(--series-blue); min-width: 44px; }
.empty-hint { color: var(--text-muted); font-size: 13px; padding: 14px; text-align: center; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-good { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.badge-warning { color: #9a6c00; background: color-mix(in srgb, var(--status-warning) 24%, transparent); }
:root[data-theme="dark"] .badge-warning { color: var(--status-warning); }
.badge-serious { color: #b0431f; background: color-mix(in srgb, var(--status-serious) 22%, transparent); }
:root[data-theme="dark"] .badge-serious { color: var(--status-serious); }
.badge-critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }
.badge-neutral { color: var(--series-blue); background: color-mix(in srgb, var(--series-blue) 14%, transparent); }
.badge-muted { color: var(--text-secondary); background: var(--surface-2); border-color: var(--border); }
.badge-muted::before { display: none; }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-width: 240px;
  flex: 1;
  max-width: 360px;
}
.search-box svg { width: 15px; height: 15px; color: var(--text-muted); }
.search-box input { border: none; outline: none; background: none; color: var(--text-primary); font-size: 13.5px; width: 100%; }
.select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 500;
}
.toolbar-add { margin-left: auto; }
.toolbar-progress { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.toolbar-progress .bar { width: 160px; }
.toolbar-progress span { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; font-weight: 600; }
.meta-line { font-size: 14px; color: var(--text-secondary); }
.meta-line strong { color: var(--text-primary); }

/* ---------------- Accordion (Checkliste) ---------------- */
.accordion { display: flex; flex-direction: column; gap: 10px; }
.acc-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.acc-header {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
}
.acc-header .num {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--series-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.acc-header .title { font-weight: 650; font-size: 14.5px; flex: 1; }
.acc-header .bar { width: 130px; }
.acc-header .pct { font-size: 12.5px; color: var(--text-muted); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.acc-header .chev { transition: transform .2s ease; color: var(--text-muted); }
.acc-section.is-open .acc-header .chev { transform: rotate(180deg); }
.acc-body { border-top: 1px solid var(--border); }
.acc-section:not(.is-open) .acc-body { display: none; }

.check-item { padding: 14px 18px; border-bottom: 1px solid var(--gridline); display: flex; gap: 14px; }
.check-item:last-child { border-bottom: none; }
.check-item-main { flex: 1; min-width: 0; }
.check-item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.check-item-ref { font-size: 11.5px; font-weight: 700; color: var(--series-blue); }
.check-item-title { font-size: 13.5px; font-weight: 650; margin-top: 1px; }
.check-item-question { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }
.check-item-controls { display: grid; grid-template-columns: 180px 160px 1fr; gap: 10px; margin-top: 10px; }
@media (max-width: 760px) { .check-item-controls { grid-template-columns: 1fr; } }
.check-item-controls select, .check-item-controls input, .check-item-controls textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 12.5px;
  font-family: inherit;
  resize: none;
}
.check-item-controls textarea { min-height: 34px; }

/* ---------------- Table ---------------- */
.table-wrap { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-card); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.2px; }
.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-muted); font-weight: 700;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--gridline); vertical-align: middle; color: var(--text-secondary); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.strong { color: var(--text-primary); font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.row-actions button svg { width: 14px; height: 14px; }
.row-actions button:hover { color: var(--text-primary); background: var(--surface-2); }
.row-actions button.danger:hover { color: var(--status-critical); }
.overdue { color: var(--status-critical); font-weight: 700; }

/* ---------------- Risk matrix ---------------- */
.risk-matrix { display: grid; grid-template-columns: 30px 1fr; gap: 8px; }
.risk-matrix-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 46px);
  gap: 4px;
  position: relative;
}
.risk-matrix-axis-y {
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: 11px; color: var(--text-muted); text-align: right; padding-bottom: 22px; padding-top: 2px;
}
.risk-matrix-axis-y span, .risk-matrix-cell-label { font-variant-numeric: tabular-nums; }
.risk-cell {
  border-radius: 6px;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 3px;
  overflow: visible;
}
.risk-matrix-wrap { grid-column: 2; }
.risk-matrix-x-labels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 6px; }
.risk-matrix-x-labels span { text-align: center; font-size: 11px; color: var(--text-muted); }
.risk-axis-title { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 4px; }
.risk-dot {
  position: absolute; width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--surface-1);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 10px; font-weight: 700;
  cursor: pointer;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

/* ---------------- Timeline (Auditplan) ---------------- */
.timeline { display: flex; flex-direction: column; }
.timeline-item { display: flex; gap: 18px; position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-rail { display: flex; flex-direction: column; align-items: center; width: 14px; flex-shrink: 0; }
.timeline-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--series-blue); flex-shrink: 0; margin-top: 6px; }
.timeline-line { flex: 1; width: 2px; background: var(--gridline); margin-top: 4px; }
.timeline-card {
  flex: 1;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  box-shadow: var(--shadow-card);
}
.timeline-time { font-weight: 700; color: var(--series-blue); font-size: 13px; min-width: 48px; }
.timeline-body { flex: 1; }
.timeline-topic { font-weight: 650; font-size: 14px; }
.timeline-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface-1); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field span { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
}
.field input[type="range"] { padding: 0; accent-color: var(--series-blue); }
.field output { font-size: 12.5px; font-weight: 700; color: var(--series-blue); }
.field textarea { resize: vertical; }
.field-row { display: flex; gap: 12px; }
@media (max-width: 520px) { .field-row { flex-direction: column; } }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-actions-split { justify-content: space-between; }

/* ---------------- Popover (risk matrix detail) ---------------- */
.popover {
  position: fixed;
  z-index: 200;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: 14px 16px;
  max-width: 260px;
  font-size: 12.5px;
}
.popover[hidden] { display: none; }
.popover h4 { font-size: 13.5px; margin-bottom: 6px; }
.popover p { color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }
.popover .popover-close { position: absolute; top: 8px; right: 8px; cursor: pointer; color: var(--text-muted); background: none; border: none; }

/* ---------------- Toasts ---------------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: var(--text-primary);
  color: var(--page);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-modal);
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .2s ease;
}
:root[data-theme="dark"] .toast { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Scrollbar polish ---------------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 999px; border: 2px solid var(--page); }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -280px; top: 0; z-index: 90; transition: left .2s ease; box-shadow: var(--shadow-modal); }
  .sidebar.is-open { left: 0; }
  .only-mobile { display: inline-flex; }
  .topbar { padding: 14px 16px; }
  .content { padding: 16px 14px 50px; }
  .topbar-actions .btn span, .btn { font-size: 12.5px; }
}
@media (max-width: 560px) {
  .topbar-actions .btn { padding: 8px 10px; }
  #exportBtn span, #printReportBtn span {}
}

/* ---------------- Print ---------------- */
@media print {
  .sidebar, .topbar, .toolbar, .toast-stack, .modal-overlay, .row-actions { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: 100%; }
  .card, .table-wrap, .stat-tile { box-shadow: none; break-inside: avoid; }
  .view[hidden] { display: none !important; }
}
