:root {
  --ink: #373736; --ink-70: #6B6B6A; --ink-45: #9A9A99;
  --signal: #0092D5; --signal-dark: #0076AC; --signal-wash: #E6F4FC;
  --paper: #FFFFFF; --surface: #F7F8F8; --surface-2: #F2F3F4; --line: #DFE1E3;

  --gelb: #F0B429; --gelb-wash: #FCF3DC;
  --orange: #DD6B20; --orange-wash: #FBE7D8;
  --rot: #C0392B; --rot-wash: #FBE4E1;
  --gruen: #2E8B57; --gruen-wash: #E3F2E9;
  --niedrig-wash: #EEEFEF;

  --r: 10px; --r-lg: 14px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(55,55,54,.06), 0 1px 1px rgba(55,55,54,.04);
  --shadow-lg: 0 8px 24px rgba(55,55,54,.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans); background: var(--surface); color: var(--ink);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--signal-dark); }
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; } h4 { font-size: 14px; }
p { margin: 0 0 8px; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-45); }
.muted { color: var(--ink-70); }
.hidden { display: none !important; }
::selection { background: var(--signal-wash); }

/* ---------------------------------------------------------------- Layout: App-Shell */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex: none; background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sidebar .brand img { width: 30px; height: 30px; border-radius: 7px; object-fit: contain; background: var(--surface-2); }
.sidebar .brand-name { font-weight: 800; font-size: 15px; }
.sidebar .brand-sub { font-size: 11px; color: var(--ink-45); }
.nav-group { margin-bottom: 14px; }
.nav-group .eyebrow { padding: 6px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--ink-70); text-decoration: none; font-size: 14px; font-weight: 600; border: none; background: none; width: 100%; text-align: left;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--signal-wash); color: var(--signal-dark); }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--rot); margin-left: auto; }
.sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--signal); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none;
}
.user-chip .name { font-weight: 700; font-size: 13px; }
.user-chip .role { font-size: 11px; color: var(--ink-45); }
.logout-btn { font-size: 12px; color: var(--ink-45); background: none; border: none; padding: 4px 0; }

main.content { flex: 1; min-width: 0; padding: 22px 28px 90px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.topbar { display: none; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--paper); font-weight: 700; font-size: 13.5px; color: var(--ink);
}
.btn:hover { border-color: var(--ink-45); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-dark); border-color: var(--signal-dark); }
.btn-danger { background: var(--rot); border-color: var(--rot); color: #fff; }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }
.fab {
  position: fixed; right: 24px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--signal); color: #fff; border: none; font-size: 26px; box-shadow: var(--shadow-lg);
  display: none; align-items: center; justify-content: center; z-index: 40;
}

/* ---------------------------------------------------------------- Cards / Tiles */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .val { font-size: 30px; font-weight: 800; line-height: 1.1; }
.kpi .label { font-size: 12.5px; color: var(--ink-70); font-weight: 600; margin-top: 4px; }
.kpi.warn .val { color: var(--orange); }
.kpi.crit .val { color: var(--rot); }

/* ---------------------------------------------------------------- Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-niedrig { background: var(--niedrig-wash); color: var(--ink-70); }
.badge-mittel { background: var(--gelb-wash); color: #8a6412; }
.badge-hoch { background: var(--orange-wash); color: var(--orange); }
.badge-kritisch { background: var(--rot-wash); color: var(--rot); }
.badge-status { background: var(--surface-2); color: var(--ink-70); }
.badge-status.st-abgeschlossen { background: var(--gruen-wash); color: var(--gruen); }
.badge-status.st-warten_auf_freigabe { background: var(--signal-wash); color: var(--signal-dark); }
.badge-status.st-wieder_geoeffnet, .badge-status.st-massnahme_erforderlich { background: var(--rot-wash); color: var(--rot); }
.badge-overdue { background: var(--rot); color: #fff; }

/* ---------------------------------------------------------------- Case list */
.case-list { display: flex; flex-direction: column; gap: 8px; }
.case-row {
  display: grid; grid-template-columns: 108px 1fr auto auto auto; align-items: center; gap: 14px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; text-decoration: none; color: inherit;
}
.case-row:hover { border-color: var(--signal); }
.case-row .num { font-weight: 700; font-size: 12.5px; color: var(--ink-70); }
.case-row .main .title { font-weight: 700; font-size: 14px; }
.case-row .main .sub { font-size: 12px; color: var(--ink-45); margin-top: 2px; }
.case-row .meta { text-align: right; font-size: 12px; color: var(--ink-45); }
.priority-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.priority-dot.niedrig { background: var(--ink-45); }
.priority-dot.mittel { background: var(--gelb); }
.priority-dot.hoch { background: var(--orange); }
.priority-dot.kritisch { background: var(--rot); }

/* ---------------------------------------------------------------- Filters */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar select, .filter-bar input[type=text], .filter-bar input[type=search] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-size: 13px;
}
.filter-chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); font-size: 12.5px; font-weight: 600; color: var(--ink-70); }
.filter-chip.active { background: var(--signal); border-color: var(--signal); color: #fff; }
.search-box { flex: 1; min-width: 160px; position: relative; }
.search-box input { width: 100%; }

/* ---------------------------------------------------------------- Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-70); margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--ink-45); margin-top: 4px; }
input[type=text], input[type=search], input[type=date], input[type=datetime-local], input[type=number],
input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--paper);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--signal); outline-offset: 0; border-color: var(--signal); }
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .span2 { grid-column: 1 / -1; }
.chip-group { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper);
  font-size: 12.5px; font-weight: 600; color: var(--ink-70);
}
.chip.selected { background: var(--signal-wash); border-color: var(--signal); color: var(--signal-dark); }
.step-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.step-tabs .step { flex: 1; text-align: center; padding: 8px; border-radius: 8px; background: var(--surface-2); font-size: 12.5px; font-weight: 700; color: var(--ink-45); }
.step-tabs .step.active { background: var(--signal); color: #fff; }
.step-tabs .step.done { background: var(--gruen-wash); color: var(--gruen); }

/* ---------------------------------------------------------------- Detail Tabs */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.detail-head .num { font-weight: 700; color: var(--signal-dark); font-size: 13px; }
.detail-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; }
.detail-meta .item .eyebrow { margin-bottom: 2px; }
.detail-meta .item .value { font-weight: 700; font-size: 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab-btn { padding: 10px 14px; border: none; background: none; font-weight: 700; font-size: 13px; color: var(--ink-45); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn.active { color: var(--signal-dark); border-color: var(--signal); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------------------------------------------------------- Fotos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-tile { position: relative; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); aspect-ratio: 4/3; background: var(--surface-2); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .cap { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(55,55,54,.65); color: #fff; font-size: 11px; padding: 4px 7px; }
.photo-add-tile {
  border: 2px dashed var(--line); border-radius: var(--r); aspect-ratio: 4/3; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--ink-45); font-weight: 700; font-size: 12px; gap: 4px; background: none;
}
.lightbox { position: fixed; inset: 0; background: rgba(20,20,20,.92); z-index: 200; display: flex; flex-direction: column; }
.lightbox-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; }
.lightbox-top button { background: rgba(255,255,255,.15); color: #fff; border: none; border-radius: 8px; padding: 8px 12px; }
.lightbox-body { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; overflow: auto; }
.lightbox-body canvas { max-width: 92vw; max-height: 78vh; touch-action: none; border-radius: 4px; }
.anno-tools { display: flex; gap: 8px; justify-content: center; padding: 12px; }
.anno-tools button { background: rgba(255,255,255,.15); color: #fff; border: none; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; font-weight: 700; }
.anno-tools button.active { background: var(--signal); }

/* ---------------------------------------------------------------- Timeline (Kommentare/Verlauf) */
.timeline { display: flex; flex-direction: column; gap: 12px; }
.timeline-item { display: flex; gap: 10px; }
.timeline-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-45); margin-top: 7px; flex: none; }
.timeline-item .body { flex: 1; }
.timeline-item .meta { font-size: 11.5px; color: var(--ink-45); margin-bottom: 2px; }
.timeline-item .text { font-size: 13.5px; }
.comment-box { background: var(--surface-2); border-radius: var(--r); padding: 10px 12px; }

/* ---------------------------------------------------------------- Actions (Maßnahmen) */
.action-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; }
.action-card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.action-kind { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--signal-dark); }
.action-status-select { font-size: 12px; padding: 5px 8px; }

/* ---------------------------------------------------------------- Toast / Modal */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); }
.toast.error { background: var(--rot); }
.toast.success { background: var(--gruen); }
.modal-overlay { position: fixed; inset: 0; background: rgba(20,20,20,.45); z-index: 150; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--paper); border-radius: var(--r-lg); padding: 20px; max-width: 440px; width: 100%; box-shadow: var(--shadow-lg); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------------------------------------------------------------- Login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--surface); padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--paper); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 28px; }
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card .brand img { width: 36px; height: 36px; border-radius: 8px; }
.login-error { background: var(--rot-wash); color: var(--rot); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ---------------------------------------------------------------- Empty state / loading */
.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-45); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--surface-2); border-top-color: var(--signal); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 60px 0; }

/* ---------------------------------------------------------------- Pareto / Stats */
.pareto-row { display: grid; grid-template-columns: 160px 1fr 50px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.pareto-bar-track { background: var(--surface-2); border-radius: 6px; height: 18px; overflow: hidden; position: relative; }
.pareto-bar-fill { background: var(--signal); height: 100%; border-radius: 6px 0 0 6px; }
.pareto-cumline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--orange); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* ---------------------------------------------------------------- Notifications */
.notif-btn { position: relative; }
.notif-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--rot); }
.notif-panel { position: absolute; right: 20px; top: 56px; width: 320px; max-height: 420px; overflow: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); z-index: 100; }
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.notif-item.unread { background: var(--signal-wash); }
.notif-item .when { color: var(--ink-45); font-size: 11px; margin-top: 3px; }

/* ---------------------------------------------------------------- Mobile */
.mobile-bottom-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  #app { flex-direction: column; }
  main.content { padding: 14px 14px 96px; max-width: none; }

  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: var(--paper); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
  }
  .topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
  .topbar .brand img { width: 26px; height: 26px; border-radius: 6px; }

  .mobile-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--paper);
    border-top: 1px solid var(--line); padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
  }
  .mobile-bottom-nav .nav-link { flex: 1; flex-direction: column; gap: 2px; align-items: center; font-size: 10.5px; padding: 6px 2px; }
  .mobile-bottom-nav .nav-link .icon { font-size: 19px; }
  .mobile-bottom-nav .fab-slot { flex: 1; display: flex; align-items: center; justify-content: center; }
  .mobile-bottom-nav .fab-slot button {
    width: 46px; height: 46px; border-radius: 50%; background: var(--signal); color: #fff; border: none; font-size: 24px;
    display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: var(--shadow-lg);
  }

  .case-row { grid-template-columns: 1fr; gap: 6px; }
  .case-row .meta { text-align: left; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
