:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6b82;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --on-accent: #ffffff;
  --track: #e9eef5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --good: #15803d;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #23304a;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --on-accent: #0b1120;
    --track: #1c2840;
    --warn: #fbbf24;
    --warn-soft: #3f2e0b;
    --bad: #fca5a5;
    --bad-soft: #451a1a;
    --good: #4ade80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: inherit; text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  color: var(--muted); text-decoration: none; font-weight: 550;
}
.tabs a.active { background: var(--accent-soft); color: var(--text); }
.tabs .ico { font-size: 13px; }
.top .link { margin-left: auto; }

main { max-width: 1000px; margin: 0 auto; padding: 6px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card > h2 { margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head > div { min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }

button.primary, a.button, button.secondary, button.danger {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none;
}
button.primary, a.button.primary { background: var(--accent); color: var(--on-accent); }
button.secondary, a.button.secondary { background: transparent; border-color: var(--line); color: var(--text); }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button.link { background: none; border: 0; padding: 4px; color: var(--muted); cursor: pointer; text-decoration: underline; }
button:disabled { opacity: .6; cursor: default; }

/* Kennzahlen */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 680; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; overflow-wrap: anywhere; }

/* Kosten je Gruppe */
.bars { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.bar-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.bar-label b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 8px; }
.bar { height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }

/* Vertragslisten */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; color: inherit; text-decoration: none; }
.row:hover .row-name { text-decoration: underline; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row-side { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card > .rows > li:first-child .row { padding-top: 0; }
.card > .rows > li:last-child .row { padding-bottom: 0; }

.pill { display: inline-block; font-size: 12px; font-weight: 550; padding: 2px 9px; border-radius: 99px; background: var(--track); color: var(--text); white-space: nowrap; }
.pill.urgent { background: var(--bad-soft); color: var(--bad); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--accent-soft); color: var(--text); }

.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; }
.filter-sum { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 12px 0 10px; }

/* Formulare */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; color: var(--muted); min-width: 0; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; font-size: 16px; font-weight: 400;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
}
textarea { min-height: 100px; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-weight: 650; font-size: 16px; margin-bottom: 10px; color: var(--text); }
.form { display: flex; flex-direction: column; gap: 14px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }
.inline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 9px; margin: 0; }

/* Details */
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .wide { grid-column: 1 / -1; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.deadline { border-left: 4px solid var(--line); padding-left: 12px; }
.deadline.urgent { border-color: var(--bad); }
.deadline.soon { border-color: var(--warn); }
.deadline.ok { border-color: var(--good); }
.deadline b { font-size: 18px; display: block; }
.upload { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.doc-actions { display: flex; gap: 6px; flex: none; }
.back { text-decoration: none; font-size: 14px; }
.empty { text-align: center; padding: 28px 16px; }
.empty p { margin: 6px 0 14px; }
a.anchor-block { display: block; }

.login { display: flex; justify-content: center; align-items: center; min-height: 80vh; padding: 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }
.login img { align-self: center; }
.login h1 { text-align: center; }
.login p { margin: 0; }
code { font-size: 12px; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 10;
  bottom: calc(82px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; max-width: calc(100% - 32px);
}

@media (min-width: 761px) {
  body { padding-bottom: 24px; }
  .toast { bottom: 24px; }
}
@media (max-width: 760px) {
  /* backdrop-filter wuerde die fest positionierte Navigation an den Kopfbereich binden */
  .top { backdrop-filter: none; background: var(--bg); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; gap: 0;
    background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs a { flex: 1; flex-direction: column; gap: 0; font-size: 12px; padding: 8px 4px; border-radius: 0; min-height: 56px; justify-content: center; }
  .tabs a.active { background: none; color: var(--accent); }
  .tabs .ico { font-size: 17px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 22px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .search, .filters .category { grid-column: 1 / -1; }
  .upload { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 460px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
}
