/* ============================================================================
   Abweichungsbericht / Deviation Report — UI
   Refined "lab-grade" design system. Brand red beibehalten.
   (Der gedruckte Bericht in report.js bleibt Arial/unverändert.)
   ============================================================================ */

:root {
  --red: #c8102e;
  --red-dark: #a30c24;
  --red-050: #fdf2f3;
  --red-100: #f7d7dc;

  --ink: #15181d;
  --ink-2: #3b424c;
  --muted: #6b7280;
  --muted-2: #9aa2ad;

  --line: #e5e8ed;
  --line-2: #eef1f4;
  --bg: #f4f5f7;
  --surface: #ffffff;

  --radius: 14px;
  --radius-sm: 9px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.05);
  --shadow-md: 0 6px 18px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.04);
  --shadow-lg: 0 18px 44px rgba(16,24,40,.18);
  --ring: 0 0 0 3px rgba(200,16,46,.16);

  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, rgba(16,24,40,.045) 1px, transparent 0);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Brand-Akzentlinie ganz oben */
body::before {
  content: ''; position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60;
  background: linear-gradient(90deg, var(--red), #e23a4d);
}

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 24px;
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 16px; color: var(--ink); }
.brand .mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--red); color: #fff; font-family: var(--font-mono); font-weight: 600; font-size: 13px;
  box-shadow: 0 4px 12px rgba(200,16,46,.32); letter-spacing: .5px;
}
.brand span { color: var(--muted); font-weight: 400; font-size: 13.5px; }
.adminlink {
  font-size: 13px; color: var(--muted); text-decoration: none; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 9px; transition: all .15s ease; background: #fff;
}
.adminlink:hover { color: var(--red); border-color: var(--red-100); background: var(--red-050); }

/* ---------- Layout ---------- */
main { max-width: 1040px; margin: 0 auto; padding: 26px 22px 24px; }
.intro {
  color: var(--muted); margin: 2px 0 22px; max-width: 70ch;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}

/* ---------- Sections (Cards) ---------- */
.section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 24px 24px; margin: 0 0 18px; box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, border-color .2s ease;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.section:hover { box-shadow: var(--shadow-md); }
.section-head {
  display: flex; align-items: center; gap: 11px; margin-bottom: 18px;
  padding-bottom: 13px; border-bottom: 1px solid var(--line-2);
}
.sec-num {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--red);
  background: var(--red-050); border: 1px solid var(--red-100); border-radius: 7px; padding: 3px 8px;
}
.sec-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: .1px; }

/* ---------- Felder ---------- */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; align-items: stretch; }
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fg-full { grid-column: 1 / -1; }
/* Unterabschnitt-Überschrift aus der Vorlage (6.a., 6.b., 7.a. …) */
.sub-head {
  grid-column: 1 / -1;
  font-family: var(--font-sans);
  font-size: 12.5px; font-weight: 700; letter-spacing: .005em;
  color: var(--red-dark);
  margin: 4px 0 -4px; padding-bottom: 7px;
  border-bottom: 1px solid var(--line-2);
}
/* Gleiche Höhen: einzeilige Steuerelemente in 2-Spalten-Zellen unten bündig ausrichten */
.fields > .form-group:not(.fg-full) > input,
.fields > .form-group:not(.fg-full) > select { margin-top: auto; }

.lbl {
  font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .2px;
  display: inline-flex; align-items: center; gap: 7px;
}
.req { color: var(--red); }

input[type="text"], input[type="date"], input[type="password"], textarea, .pair-row select, .note-row textarea {
  width: 100%; padding: 10px 12px; min-height: 42px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; background: var(--surface); color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--red); box-shadow: var(--ring); }
input:hover:not(:focus), textarea:hover:not(:focus), select:hover:not(:focus) { border-color: var(--muted-2); }
textarea { min-height: 78px; resize: vertical; line-height: 1.55; }

/* ---------- Radios als Auswahl-Pills ---------- */
.radios { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0; }
.radio {
  display: inline-flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 13px; color: var(--ink-2);
  transition: border-color .15s, background .15s, color .15s;
}
.radio:hover { border-color: var(--muted-2); }
.radio input { accent-color: var(--red); margin: 0; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--red); background: var(--red-050); color: var(--ink); font-weight: 600; }

/* ---------- KI-Badge ---------- */
.ai-badge {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600; letter-spacing: .6px;
  text-transform: uppercase; background: var(--red); color: #fff; border-radius: 5px;
  padding: 2px 6px; line-height: 1.4;
}

/* ---------- Wiederholbare Zeilen (Soll/Ist, Ursachen, CAPA) ---------- */
.pair-group { margin: 4px 0; }
.pair-row {
  border: 1px solid var(--line); border-left: 3px solid var(--red-100); border-radius: var(--radius-sm);
  padding: 14px 16px; margin-bottom: 10px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.pair-row:hover { border-color: var(--line); border-left-color: var(--red); box-shadow: var(--shadow-sm); }
.pair-row .form-group { margin-bottom: 12px; }
.pair-row .form-group:last-of-type { margin-bottom: 0; }
.pair-row-tools { display: flex; justify-content: flex-end; margin-top: 10px; }

.pair-row-inline { display: flex; gap: 12px; align-items: flex-end; }
.pair-row-inline .form-group { margin-bottom: 0; }
.fg-select { flex: 0 0 210px; }
.fg-grow { flex: 1 1 auto; min-width: 0; }
.fg-date { flex: 0 0 180px; }

.btn-remove-pair {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; transition: all .15s ease;
}
.btn-remove-pair:hover { border-color: var(--red); color: var(--red); background: var(--red-050); }
.btn-remove-inline { flex: 0 0 auto; height: 42px; width: 42px; padding: 0; font-size: 18px; line-height: 1; }
.btn-add-pair { margin-top: 4px; }

/* ---------- Ergänzungen unter Radio-Gruppen (dezent, erst nach „+" sichtbar) ---------- */
.note-group { margin: 10px 0 2px; }
.note-label {
  display: none; font-size: 11.5px; font-weight: 600; color: var(--muted);
  margin-bottom: 8px; align-items: center; gap: 7px;
}
.note-group:has(.note-row) .note-label { display: inline-flex; }
.note-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.note-row textarea { flex: 1 1 auto; min-height: 42px; resize: vertical; background: #fff; }
.btn-remove-note {
  flex: 0 0 auto; height: 36px; width: 36px; padding: 0; font-size: 16px; line-height: 1;
  background: #fff; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; cursor: pointer; transition: all .15s ease;
}
.btn-remove-note:hover { border-color: var(--red); color: var(--red); }
.btn-add-note, .btn-add-pair {
  background: transparent; border: 1px dashed var(--line); color: var(--muted); font-weight: 500;
  border-radius: 8px; padding: 5px 12px; font-size: 12px; cursor: pointer; transition: all .15s ease;
}
.btn-add-note:hover, .btn-add-pair:hover { border-color: var(--red); color: var(--red); background: var(--red-050); }

/* ---------- Grafiken (Copy-Paste) ---------- */
.img-zone { margin-top: 14px; }
.img-hint {
  font-size: 12.5px; color: var(--muted); background: var(--bg);
  border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
}
.img-hint b { color: var(--ink-2); }
.img-thumbs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.thumb {
  position: relative; width: 148px; height: 104px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden; background: #fff; box-shadow: var(--shadow-sm);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border: none; border-radius: 50%;
  background: rgba(16,18,22,.66); color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: background .15s ease;
}
.thumb-x:hover { background: var(--red); }

/* ---------- Buttons + Sticky Action Bar ---------- */
.actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 30px 0 48px; padding-top: 20px; border-top: 1px solid var(--line);
}
#btn-clear { margin-left: auto; }
.btn {
  font-family: var(--font-sans); border: 1px solid transparent; border-radius: 11px;
  padding: 11px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .6; cursor: default; box-shadow: none; transform: none; }
.btn-ai { background: var(--red); color: #fff; box-shadow: 0 8px 18px rgba(200,16,46,.30); }
.btn-ai:hover:not(:disabled) { background: var(--red-dark); transform: translateY(-1px); box-shadow: 0 10px 24px rgba(200,16,46,.36); }
.btn-report { background: #1b1f24; color: #fff; }
.btn-report:hover { background: #0e1115; transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { border-color: var(--muted-2); color: var(--ink-2); }
.btn-cancel { background: #eef1f4; color: var(--ink-2); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(16,18,22,.5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 40;
  animation: fade .2s ease both;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 16px; padding: 24px 26px; max-width: 400px; width: 90%;
  box-shadow: var(--shadow-lg); animation: pop .22s cubic-bezier(.2,.8,.2,1) both;
}
.modal-box h3 { margin: 0 0 6px; font-size: 17px; }
.modal-box p { margin: 0 0 18px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  padding: 13px 20px; border-radius: 11px; color: #fff; font-weight: 600; z-index: 50;
  box-shadow: var(--shadow-lg); max-width: 90%; animation: rise .25s ease both;
}
.toast.hidden { display: none; }
.toast.info { background: #1f2937; }
.toast.success { background: #15803d; }
.toast.error { background: var(--red); }

/* ---------- Admin ---------- */
.admin-wrap { max-width: 840px; margin: 0 auto; padding: 26px 22px; }
.admin-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.admin-card h2 {
  margin: 0 0 16px; font-size: 14px; color: var(--ink); font-weight: 600;
  display: flex; align-items: center; gap: 9px; padding-bottom: 12px; border-bottom: 1px solid var(--line-2);
}
.admin-card h2::before { content: ''; width: 6px; height: 16px; border-radius: 3px; background: var(--red); }
.admin-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.admin-row label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.admin-row .hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.admin-row textarea { min-height: 130px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; }
.admin-row code { font-family: var(--font-mono); font-size: 11.5px; background: var(--red-050); color: var(--red-dark); padding: 1px 5px; border-radius: 4px; }
.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 12px; }
.login-box { max-width: 380px; margin: 64px auto; }

/* ---------- Motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.section:nth-child(1) { animation-delay: .02s; }
.section:nth-child(2) { animation-delay: .06s; }
.section:nth-child(3) { animation-delay: .10s; }
.section:nth-child(4) { animation-delay: .14s; }
.section:nth-child(5) { animation-delay: .18s; }
.section:nth-child(6) { animation-delay: .22s; }
.section:nth-child(n+7) { animation-delay: .26s; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .fields { grid-template-columns: 1fr; }
  .pair-row-inline { flex-wrap: wrap; }
  .fg-select, .fg-date { flex-basis: 100%; }
  main { padding: 18px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
