/* ==========================================================================
   Pocket Rocket · Mahnwesen — Stylesheet
   Farbwerte gemäß validierter Referenzpalette (siehe dataviz-Skill).
   ========================================================================== */

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

  --series-blue: #2a78d6;
  --series-blue-strong: #1c5cab;

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

  --good-bg: rgba(12, 163, 12, 0.12);
  --warning-bg: rgba(250, 178, 25, 0.16);
  --serious-bg: rgba(236, 131, 90, 0.16);
  --critical-bg: rgba(208, 59, 59, 0.12);
  --neutral-bg: rgba(137, 135, 129, 0.14);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 8px 24px rgba(11, 11, 11, 0.10);
  --shadow-lg: 0 20px 48px rgba(11, 11, 11, 0.18);

  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #201f1e;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8d86;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  --series-blue: #3987e5;
  --series-blue-strong: #86b6ef;

  --good: #0ca30c;
  --good-text: #37c837;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;

  --good-bg: rgba(12, 163, 12, 0.18);
  --warning-bg: rgba(250, 178, 25, 0.16);
  --serious-bg: rgba(236, 131, 90, 0.16);
  --critical-bg: rgba(230, 103, 103, 0.16);
  --neutral-bg: rgba(143, 141, 134, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
}

* { 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;
}
body.no-scroll { overflow: hidden; }

button, input { font-family: inherit; }

a { color: var(--series-blue); }

.muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, Menlo, monospace; font-size: 0.92em; }
.text-good { color: var(--good-text); }
.text-warning { color: #9a6a00; }
:root[data-theme="dark"] .text-warning { color: var(--warning); }
.text-critical { color: var(--critical); }

.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }

/* ---------------------------------- App shell ---------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
}
.brand__mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--series-blue), var(--series-blue-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.brand__text { line-height: 1.15; }
.brand__title { font-weight: 700; font-size: 14.5px; }
.brand__subtitle { font-size: 11.5px; color: var(--text-muted); }

.nav-group { margin-top: 6px; }
.nav-group__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--neutral-bg); color: var(--text-primary); }
.nav-item--active {
  background: var(--series-blue);
  color: #fff;
}
.nav-item--active .icon { color: #fff; }
.nav-icon { display: flex; align-items: center; }
.nav-item__label { flex: 1; }
.nav-item__badge {
  background: rgba(255, 255, 255, 0.25);
  color: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}
.nav-item:not(.nav-item--active) .nav-item__badge {
  background: var(--critical);
  color: #fff;
}

.sidebar__foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------------------------------- Main / Topbar ---------------------------------- */
.main {
  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: 5;
}
.topbar__titles { flex: 1; min-width: 0; }
.topbar__titles h1 { font-size: 19px; margin: 0 0 2px; }
.topbar__titles p { margin: 0; font-size: 12.5px; color: var(--text-muted); }

.topbar__date {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--neutral-bg); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  white-space: nowrap;
}
.user-chip__avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--series-blue), var(--series-blue-strong));
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content {
  flex: 1;
  padding: 24px 28px 48px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; animation: fade-in 0.18s ease; }
.view--active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------- KPI cards ---------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-card--accent { border-color: rgba(42, 120, 214, 0.35); background: linear-gradient(180deg, rgba(42,120,214,0.07), transparent 60%); }
.kpi-card__label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.kpi-card__value { font-size: 27px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -0.01em; }
.kpi-card__hint { font-size: 12px; color: var(--text-muted); }

/* ---------------------------------- Panels ---------------------------------- */
.panel-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-grid--settings { grid-template-columns: 1.3fr 1fr; align-items: start; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.panel--flush { padding: 0; overflow: hidden; }
.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.panel__head h2 { font-size: 15px; margin: 0; flex: 1; }

/* ---------------------------------- Aging chart ---------------------------------- */
.agechart {
  display: flex;
  align-items: flex-end;
  gap: 22px;
  height: 190px;
  padding: 6px 8px 0;
}
.agebar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.agebar__track {
  flex: 1;
  width: 100%;
  max-width: 64px;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--baseline);
}
.agebar__fill {
  width: 100%;
  border-radius: 6px 6px 2px 2px;
  min-height: 6px;
  transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.agebar__fill--warning { background: var(--warning); }
.agebar__fill--serious { background: var(--serious); }
.agebar__fill--critical { background: var(--critical); }
.agebar__value { font-size: 12.5px; font-weight: 700; margin-top: 8px; }
.agebar__label { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------------------------------- Activity list ---------------------------------- */
.activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 210px; overflow-y: auto; }
.activity { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-bottom: 1px solid var(--gridline); font-size: 13px; }
.activity:last-child { border-bottom: none; }
.activity__icon { color: var(--series-blue); margin-top: 1px; }
.activity__text { flex: 1; line-height: 1.4; }
.activity__meta { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.activity--empty { color: var(--text-muted); }

/* ---------------------------------- Tables ---------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--neutral-bg); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-zweck { color: var(--text-secondary); max-width: 280px; }
.clickable-row { cursor: pointer; }
.link-like { cursor: pointer; text-decoration: underline; text-decoration-color: var(--border-strong); }
.link-like:hover { color: var(--series-blue); }

.row-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ---------------------------------- Badges ---------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge--good { background: var(--good-bg); color: var(--good-text); }
.badge--warning { background: var(--warning-bg); color: #8a5c00; }
:root[data-theme="dark"] .badge--warning { color: var(--warning); }
.badge--serious { background: var(--serious-bg); color: #a1461f; }
:root[data-theme="dark"] .badge--serious { color: var(--serious); }
.badge--critical { background: var(--critical-bg); color: var(--critical); }
.badge--neutral { background: var(--neutral-bg); color: var(--text-secondary); }

/* ---------------------------------- Toolbar ---------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar__spacer { flex: 1; }
.toolbar__count { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }

.search-input {
  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;
  color: var(--text-muted);
}
.search-input input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13.5px;
  flex: 1;
}

.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chip:hover { border-color: var(--border-strong); }
.chip--active { background: var(--series-blue); border-color: var(--series-blue); color: #fff; }
.chip__count {
  display: inline-block;
  margin-left: 4px;
  font-size: 10.5px;
  font-weight: 700;
  opacity: 0.85;
}

/* ---------------------------------- Buttons ---------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--series-blue); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--series-blue-strong); }
.btn--ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn--ghost:hover { background: var(--neutral-bg); }
.btn--outline { background: var(--surface-1); color: var(--text-primary); border-color: var(--border-strong); }
.btn--outline:hover { background: var(--neutral-bg); }
.btn--sm { padding: 6px 10px; font-size: 12px; }

/* ---------------------------------- Abgleich panel ---------------------------------- */
.panel--abgleich { margin-bottom: 18px; }
.abgleich-head { display: flex; align-items: center; gap: 16px; }
.abgleich-head h2 { margin: 0 0 3px; font-size: 15.5px; }
.abgleich-head p { margin: 0; font-size: 12.5px; }

.abgleich-progress { margin-top: 16px; }
.abgleich-progress__bar {
  height: 6px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}
.abgleich-progress__fill {
  height: 100%;
  width: 4%;
  background: var(--series-blue);
  border-radius: 999px;
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.abgleich-progress__label { margin-top: 8px; font-size: 12.5px; color: var(--text-muted); }

.abgleich-summary {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.abgleich-summary__item {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--text-secondary);
}
.abgleich-summary__num { font-size: 21px; font-weight: 700; color: var(--text-primary); }

/* ---------------------------------- Empty state ---------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state .icon { color: var(--good); }

/* ---------------------------------- Detail / settings misc ---------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.detail-status { margin-bottom: 16px; }
.detail-section { margin-bottom: 16px; }
.detail-section h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 6px; }
.detail-section p { margin: 0; font-size: 13.5px; line-height: 1.55; }
.detail-section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.mini-list { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.mini-list li { display: flex; align-items: flex-start; gap: 6px; }

.def-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin: 0; }
.def-list dt { color: var(--text-muted); }
.def-list dd { margin: 0; }

.input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-primary);
  width: 74px;
}
.input--sm { width: 64px; }

/* ---------------------------------- Modal ---------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-overlay.is-open { display: flex; }
:root[data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, 0.6); }

.modal {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  animation: modal-in 0.18s ease;
}
.modal--wide { max-width: 680px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal__head h2 { margin: 0; font-size: 17px; }
.modal__head p { margin: 3px 0 0; }
.modal__body { padding: 20px 22px; max-height: 62vh; overflow-y: auto; }
.modal__body--letter { background: var(--page); }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ---------------------------------- Letter ---------------------------------- */
.letter {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 30px 34px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-primary);
}
.letter__head { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); margin-bottom: 26px; }
.letter__addressblock { margin-bottom: 26px; }
.letter__subject { font-weight: 700; margin-bottom: 14px; }
.letter__table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.letter__table td { padding: 6px 0; border-bottom: 1px solid var(--gridline); }
.letter__table .num { text-align: right; font-variant-numeric: tabular-nums; }
.letter__table tfoot td { border-bottom: none; border-top: 2px solid var(--text-primary); padding-top: 10px; }
.letter__bank { font-variant-numeric: tabular-nums; }
.letter__foot { margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--gridline); font-size: 10.5px; color: var(--text-muted); line-height: 1.6; }

/* ---------------------------------- Toasts ---------------------------------- */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  max-width: 340px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast--show { opacity: 1; transform: none; }
.toast--good { border-left: 3px solid var(--good); }
.toast--good .icon { color: var(--good); }
.toast--critical { border-left: 3px solid var(--critical); }
.toast--critical .icon { color: var(--critical); }
.toast--neutral { border-left: 3px solid var(--text-muted); }

/* ---------------------------------- Responsive ---------------------------------- */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid, .panel-grid--settings, .detail-section-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; }
  .brand { display: none; }
  .nav-group { display: flex; gap: 4px; margin-top: 0; }
  .nav-group__label { display: none; }
  .sidebar__foot { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .content { padding: 18px 14px 40px; }
}

/* ---------------------------------- Print ---------------------------------- */
@media print {
  .sidebar, .topbar, .modal__head, .modal__foot, .toast-root { display: none !important; }
  .modal-overlay { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; max-width: none; }
  .modal__body { max-height: none; overflow: visible; padding: 0; }
  body { background: #fff; }
}
