/* aprevo – Oberfläche */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #1f5fbf;
  --primary-h: #174ea0;
  --primary-soft: #e8f0fc;
  --ok: #15803d;
  --ok-soft: #e5f5ea;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --info: #0369a1;
  --info-soft: #e4f2fa;
  --neutral-soft: #eef1f5;
  --side: #0f1b2d;
  --side-2: #1a2b44;
  --side-text: #b3c0d3;
  --side-head: #6f819b;
  --chart-a: #2f7d4f;
  --chart-b: #c2563f;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .28);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #121a2a;
    --surface-2: #0f1726;
    --border: #233047;
    --border-strong: #33425c;
    --text: #e6ebf3;
    --text-2: #c3cddc;
    --muted: #8d9ab0;
    --primary: #5b9bf0;
    --primary-h: #79aef5;
    --primary-soft: #1b2c48;
    --ok: #4ccb7d;
    --ok-soft: #14301f;
    --warn: #f0a845;
    --warn-soft: #3a2a12;
    --danger: #f27373;
    --danger-soft: #3d1a1d;
    --info: #5ab8ea;
    --info-soft: #12304a;
    --neutral-soft: #1d2638;
    --side: #080e19;
    --side-2: #152238;
    --chart-a: #4cb87a;
    --chart-b: #e07a62;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #121a2a;
  --surface-2: #0f1726;
  --border: #233047;
  --border-strong: #33425c;
  --text: #e6ebf3;
  --text-2: #c3cddc;
  --muted: #8d9ab0;
  --primary: #5b9bf0;
  --primary-h: #79aef5;
  --primary-soft: #1b2c48;
  --ok: #4ccb7d;
  --ok-soft: #14301f;
  --warn: #f0a845;
  --warn-soft: #3a2a12;
  --danger: #f27373;
  --danger-soft: #3d1a1d;
  --info: #5ab8ea;
  --info-soft: #12304a;
  --neutral-soft: #1d2638;
  --side: #080e19;
  --side-2: #152238;
  --chart-a: #4cb87a;
  --chart-b: #e07a62;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* ---------- Layout ---------- */
#app { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }
#sidebar {
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 30;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 18px 18px 14px; }
.logo {
  width: 38px; height: 38px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, #3b82f6, #1e40af);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; line-height: 1; padding-bottom: 3px;
}
.brand-t { color: #fff; font-weight: 700; font-size: 17px; line-height: 1.15; letter-spacing: .01em; }
.brand-s { font-size: 12px; color: var(--side-text); line-height: 1.2; }
#nav { padding: 4px 10px 16px; flex: 1; }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-head); padding: 14px 10px 6px; font-weight: 600; }
.nav-i {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px;
  color: var(--side-text); font-size: 13.5px;
}
.nav-i:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav-i.active { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 #3b82f6; }
.nav-i .cnt { margin-left: auto; font-size: 11px; padding: 0 7px; border-radius: 10px; background: #b91c1c; color: #fff; line-height: 18px; }
.nav-i .cnt.warn { background: #b45309; }
.side-foot { padding: 12px 18px 16px; font-size: 11.5px; color: var(--side-head); border-top: 1px solid var(--side-2); }

#main-wrap { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
#menu-btn { display: none; }
.global-search { flex: 1; max-width: 520px; position: relative; }
.global-search .ic { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.global-search input { width: 100%; padding-left: 34px; }
#view { flex: 1; overflow-y: auto; padding: 22px 24px 48px; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 40; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 7px 10px; border: 0; background: none; color: var(--text); border-radius: 6px; cursor: pointer; font: inherit; text-align: left; }
.dropdown-menu button:hover { background: var(--neutral-soft); }

/* ---------- Seitenkopf ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.back .ic { width: 15px; height: 15px; }

/* ---------- Karten & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px; }
.card > h2, .card > h3, .card-h { margin-bottom: 12px; }
.card-h { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.card.tight { padding: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 18px; margin-bottom: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 16px; box-shadow: var(--shadow); color: var(--text); position: relative; overflow: hidden;
}
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); opacity: .8; }
.kpi.ok::before { background: var(--ok); }
.kpi.warn::before { background: var(--warn); }
.kpi.danger::before { background: var(--danger); }
.kpi-l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-v { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-s { font-size: 12px; color: var(--muted); margin-top: 1px; }
.kpi.danger .kpi-v { color: var(--danger); }
.kpi.warn .kpi-v { color: var(--warn); }

/* ---------- Listen ---------- */
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .t { flex: 1; min-width: 0; }
.mini-list .t a, .mini-list .t div { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list .s { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; line-height: 19px; white-space: nowrap; background: var(--neutral-soft); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--neutral-soft); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--neutral-soft); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; border: 0; background: transparent; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--neutral-soft); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
.fld.err input, .fld.err select, .fld.err textarea { border-color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld.full { grid-column: 1 / -1; }
.fld > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.fld input, .fld select, .fld textarea { width: 100%; }
.req { color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); }
.form-sec { grid-column: 1 / -1; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.form-sec:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.ref-row { display: flex; gap: 4px; }
.ref-row select { flex: 1; }
.chk { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; padding: 7px 0; cursor: pointer; }
.chk input { width: 16px; height: 16px; }

/* ---------- Tabellen ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search-box { position: relative; }
.search-box .ic { position: absolute; left: 9px; top: 9px; width: 16px; height: 16px; color: var(--muted); }
.search-box input { padding-left: 31px; width: 220px; }
.list-title { display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.list-title .count { color: var(--muted); font-weight: 500; font-size: 13px; }
.table-wrap { overflow-x: auto; margin: 0 -18px; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th:first-child, .tbl td:first-child { padding-left: 18px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 18px; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; user-select: none; }
.tbl th[data-sort] { cursor: pointer; }
.tbl th[data-sort]:hover { color: var(--text); }
.tbl th.sorted { color: var(--primary); }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl td.act { width: 1%; white-space: nowrap; text-align: right; }
.tbl td.act .icon-btn { opacity: .55; }
.tbl tr:hover td.act .icon-btn { opacity: 1; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
.tbl tr.sub td { background: var(--surface-2); font-size: 12.5px; }
.tbl .empty { padding: 26px; }
.more-row td { text-align: center; }
.embed .toolbar { margin-bottom: 10px; }
.embed .search-box input { width: 180px; }

/* ---------- Detail ---------- */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 24px; margin: 0; }
.dl dt { font-size: 12px; color: var(--muted); font-weight: 500; }
.dl dd { margin: 1px 0 0; word-break: break-word; }
.dl .wide { grid-column: 1 / -1; }

/* ---------- Kacheln (Einstellungen) ---------- */
.tile-grid { display: flex; flex-direction: column; gap: 8px; }
.tile { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-weight: 550; }
.tile:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }
.tile .ic { color: var(--primary); }
.tile.opt { cursor: pointer; font-weight: 400; }
.tile.opt input { width: 18px; height: 18px; flex: none; }
.tile.opt b { display: block; font-weight: 600; }
.tile.opt .s { display: block; font-size: 12.5px; color: var(--muted); }

/* ---------- Tabs & Chips ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .n { opacity: .75; margin-left: 4px; }

/* ---------- Diagramm ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar.a { fill: var(--chart-a); }
.chart .bar.b { fill: var(--chart-b); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Modal & Toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 14, 25, .55); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh; display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal-body { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal.lg { max-width: 780px; }
.modal.xl { max-width: 1040px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-body p { margin: 0 0 10px; }
.modal-foot { display: flex; gap: 8px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: tin .2s ease-out; }
.toast.err { background: #b91c1c; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Sonstiges ---------- */
.banner { display: flex; gap: 12px; align-items: center; padding: 11px 16px; border-radius: var(--radius); margin-bottom: 18px; background: var(--warn-soft); color: var(--warn); border: 1px solid transparent; flex-wrap: wrap; }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner .grow { color: var(--text-2); }
.welcome { max-width: 760px; margin: 5vh auto; text-align: center; }
.welcome .logo { width: 64px; height: 64px; font-size: 36px; border-radius: 16px; margin: 0 auto 18px; }
.welcome h1 { justify-content: center; font-size: 28px; }
.welcome p { color: var(--muted); font-size: 15px; }
.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 28px 0; text-align: left; }
.feature-grid div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; color: var(--muted); }
.feature-grid b { display: block; color: var(--text); margin-bottom: 2px; }
.empty-state { text-align: center; color: var(--muted); padding: 48px 16px; }
.split { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stat-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.stat-line:last-child { border-bottom: 0; }
.stat-line.total { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; margin-top: 4px; padding-top: 8px; }
.scroll-y { max-height: 460px; overflow-y: auto; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
kbd { font: 11px var(--font); border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 5px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.menu-open #sidebar { transform: none; }
  #menu-btn { display: inline-grid; }
  #topbar { padding: 8px 16px; }
  #view { padding: 16px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  .table-wrap { margin: 0 -16px; }
  .search-box input { width: 100%; }
  .search-box { flex: 1 1 100%; }
  .top-label { display: none; }
}

/* ---------- Druck ---------- */
@media print {
  #sidebar, #topbar, .page-head .actions, .toolbar, .tbl td.act, .tbl th:last-child:empty, .no-print { display: none !important; }
  #app { display: block; height: auto; }
  #main-wrap, #view { height: auto; overflow: visible; padding: 0; }
  body { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
