:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1d1f24;
  --ink-2: #555a64;
  --ink-3: #8a8f98;
  --line: #e4e2dc;
  --line-2: #d6d3cb;
  --accent: #2347a8;
  --accent-soft: #e8edfa;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #a15c00;
  --warn-soft: #fbf0dc;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 2px 8px rgba(20, 20, 30, .04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2026;
    --ink: #ecebe7;
    --ink-2: #b1b4bb;
    --ink-3: #7f838c;
    --line: #2c2f36;
    --line-2: #3a3e46;
    --accent: #8aa6f0;
    --accent-soft: #232c45;
    --ok: #6fcf9a;
    --ok-soft: #1c3328;
    --warn: #e9b35a;
    --warn-soft: #3a2e17;
    --danger: #f08a82;
    --danger-soft: #3d2120;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--ink-3); font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-lg { font-size: 22px; margin-bottom: 8px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 17l5 5 11-12' stroke='white' stroke-width='4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 18px no-repeat;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-danger { color: #111; } }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .lbl { display: none; }
.icon-btn.ok:hover { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.icon-btn.edit:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn.no:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.icon-btn[disabled] { opacity: .4; pointer-events: none; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 14px; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--surface); font-size: 15px; font-weight: 400; color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.error { margin: 0; color: var(--danger); font-size: 14px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.nav {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 22px;
  padding: 22px 14px; border-right: 1px solid var(--line); background: var(--bg);
}
.nav .brand { padding: 0 10px; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 550;
}
.nav-item.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); border: 1px solid var(--line); }
.nav-item.is-soon { color: var(--ink-3); cursor: default; }
.nav-item small { font-size: 11px; font-weight: 500; color: var(--ink-3); }
.count {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 99px; display: inline-grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .count { color: #111; } }
.nav-logout {
  margin-top: auto; align-self: start; background: none; border: 0; padding: 8px 10px; color: var(--ink-3); cursor: pointer;
}
.nav-logout:hover { color: var(--ink); }

.main { padding: 28px clamp(16px, 3vw, 40px) 80px; max-width: 1280px; width: 100%; }
.main-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.main-head h1 { font-size: 26px; letter-spacing: -.02em; }
.filter select { width: auto; min-width: 170px; padding: 7px 10px; }

.section { margin-bottom: 30px; }
.section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); margin-bottom: 10px; }
.section-alt summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.section-alt summary::-webkit-details-marker { display: none; }
.section-alt summary::before {
  content: ""; width: 7px; height: 7px; margin: 0 2px 10px 2px; border: solid var(--ink-3); border-width: 0 2px 2px 0;
  transform: rotate(-45deg); transition: transform .15s;
}
.section-alt[open] summary::before { transform: rotate(45deg); margin-bottom: 14px; }

.list { display: grid; gap: 10px; }

.empty {
  display: grid; gap: 4px; padding: 28px; text-align: center; color: var(--ink-3);
  border: 1px dashed var(--line-2); border-radius: var(--radius);
}
.empty strong { color: var(--ink-2); }

/* ---------- Item (Neu) ---------- */
.item {
  display: grid;
  grid-template-columns: minmax(200px, 1.15fr) minmax(0, 2.4fr) auto;
  gap: 18px; align-items: center;
  padding: 14px 14px 14px 18px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  position: relative;
}
.item.prio-hoch::before {
  content: ""; position: absolute; left: -1px; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--danger);
}
.item.is-busy { opacity: .55; pointer-events: none; }

.item-head { min-width: 0; cursor: pointer; }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 5px; font-size: 12px; color: var(--ink-3); }
.item-title { font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
.item-sub { margin-top: 3px; color: var(--ink-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line);
}
.chip.typ-entscheidung { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.typ-kontrolle { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.prio { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.felder {
  display: grid; grid-template-columns: repeat(var(--n, 1), minmax(0, 1fr)); gap: 0;
  border-left: 1px solid var(--line); min-width: 0;
}
.feld { padding: 2px 14px; border-right: 1px solid var(--line); min-width: 0; }
.feld:last-child { border-right: 0; }
.feld-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 2px; }
.feld-wert { font-size: 14px; overflow-wrap: anywhere; }
.feld-wert.mono { font-family: var(--mono); font-size: 13px; }
.felder-leer { color: var(--ink-3); font-size: 13px; padding: 0 14px; }

.optionen { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; border-left: 1px solid var(--line); }
.opt { min-height: 34px; padding: 0 12px; font-weight: 550; }
.opt.is-empfohlen { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.opt .tag { font-size: 11px; font-weight: 700; opacity: .8; }

.actions { display: flex; gap: 6px; }

.item-details {
  grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; margin-top: -4px;
  display: grid; gap: 12px;
}
.kv { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); }
.kv b { color: var(--ink); font-weight: 600; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 8px;
  background: var(--accent-soft); text-decoration: none; font-size: 13px; font-weight: 600;
}

/* ---------- Markdown ---------- */
.md { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote { margin: 0 0 .6em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 14px; margin: .8em 0 .3em; }
.md ul, .md ol { padding-left: 1.3em; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line-2); padding-left: 10px; color: var(--ink-2); }
.md hr { border: 0; border-top: 1px solid var(--line); }

/* ---------- Alt ---------- */
.old {
  display: grid; grid-template-columns: 110px minmax(0, 1.3fr) minmax(0, 2fr) auto; gap: 14px; align-items: center;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}
.old-title { font-weight: 600; overflow-wrap: anywhere; }
.old-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.old-res { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; min-width: 0; }
.old-res .info { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.badge {
  justify-self: start; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 650; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.s-genehmigt, .badge.s-angepasst { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge.s-ausgefuehrt, .badge.s-erledigt { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.s-abgelehnt { color: var(--ink-2); }
.badge.s-fehler { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-size: 13px; font-weight: 600; }
.old-more { grid-column: 1 / -1; text-align: center; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(520px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dialog::backdrop { background: rgba(15, 17, 22, .45); }
.dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog h3 { font-size: 18px; }
.dialog p { margin: -6px 0 0; }
.edit-fields { display: grid; gap: 12px; }
.edit-fields .orig { font-size: 12px; font-weight: 400; color: var(--ink-3); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 10; max-width: calc(100vw - 24px);
}
.toast-undo { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 4px; }
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------- Mobil ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; gap: 12px;
    padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
    border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto;
  }
  .nav .brand { padding: 0; }
  .nav ul { display: flex; gap: 2px; }
  .nav-item { white-space: nowrap; padding: 6px 10px; }
  .nav-item.is-soon { display: none; }
  .nav-logout { margin: 0 0 0 auto; white-space: nowrap; }
  .main { padding-top: 18px; }
  .main-head h1 { font-size: 22px; }

  .item { grid-template-columns: 1fr; gap: 12px; padding: 14px; }
  .felder { grid-template-columns: 1fr 1fr; border-left: 0; gap: 10px; background: var(--bg); border-radius: 10px; padding: 10px 0; }
  .feld { border-right: 0; padding: 0 12px; }
  .felder.n1 { grid-template-columns: 1fr; }
  .optionen { border-left: 0; padding: 0; }
  .actions { display: grid; grid-template-columns: repeat(var(--a, 3), 1fr); }
  .icon-btn { width: 100%; height: 44px; display: inline-flex; gap: 7px; justify-content: center; font-weight: 600; font-size: 14px; }
  .icon-btn .lbl { display: inline; }
  .item-details { margin-top: 0; }

  .old { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .old .badge { grid-row: 1; grid-column: 2; }
  .old-head { grid-row: 1; grid-column: 1; }
  .old-res { grid-column: 1 / -1; }
  .old-act { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .felder { grid-template-columns: 1fr; }
  .filter select { min-width: 0; max-width: 150px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
input[readonly], textarea[readonly] { background: var(--bg); color: var(--ink-2); }
