:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dcdfe4;
  --border-strong: #c3c8d0;
  --text: #1c2024;
  --text-muted: #5b6370;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --success-bg: #e3f4e8;
  --success-text: #1c6b38;
  --error-bg: #fdeaea;
  --error-text: #9b2020;
  --warn-bg: #fdf3e0;
  --warn-text: #8a5a08;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22272c;
    --border: #333a41;
    --border-strong: #454e57;
    --text: #e6e9ec;
    --text-muted: #9aa4b0;
    --accent: #5aa7db;
    --accent-text: #0c1116;
    --success-bg: #17301f;
    --success-text: #7fd39b;
    --error-bg: #351a1a;
    --error-text: #f19b9b;
    --warn-bg: #362a13;
    --warn-text: #e5bf72;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

/* --- Kopfzeile --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); letter-spacing: -0.2px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a.active { background: var(--accent); color: var(--accent-text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--text-muted); text-decoration: none; font-size: 14px; }
.who:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.foot { text-align: center; color: var(--text-muted); font-size: 13px; padding: 0 0 24px; }

/* --- Überschriften --- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.2px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }

/* --- Karten --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card.tight { padding: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.stat .l { color: var(--text-muted); font-size: 13px; }

/* --- Tabellen --- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 12px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-muted); border-bottom: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap, th.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* --- Formulare --- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field { margin-bottom: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check label { margin: 0; font-weight: 500; color: var(--text); }
.check input { width: auto; }

/* --- Schaltflächen --- */
.btn {
  display: inline-block; padding: 8px 14px; font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.1); color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--error-text); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--error-bg); border-color: var(--error-text); color: var(--error-text); }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions-end { justify-content: flex-end; }
form.inline { display: inline; }

/* --- Meldungen --- */
.flash {
  padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px;
  border: 1px solid transparent; font-size: 14px;
}
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: currentColor; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
.flash-info { background: var(--surface); color: var(--text); border-color: var(--border); }

/* --- Etiketten --- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border-strong);
  color: var(--text-muted); white-space: nowrap;
}
.tag-offen { background: var(--surface-2); }
.tag-in_arbeit { background: var(--warn-bg); color: var(--warn-text); border-color: currentColor; }
.tag-teilgeliefert { background: var(--warn-bg); color: var(--warn-text); border-color: currentColor; }
.tag-geliefert { background: var(--success-bg); color: var(--success-text); border-color: currentColor; }
.tag-geplant { background: var(--surface-2); }
.tag-abgelehnt, .tag-storniert, .tag-fehlgeschlagen {
  background: var(--error-bg); color: var(--error-text); border-color: currentColor;
}
.tag-hoch { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
.overdue { color: var(--error-text); font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* --- Filterleiste --- */
.filters {
  display: grid; gap: 10px; align-items: end;
  grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(140px, 1fr)) auto;
  margin-bottom: 18px;
}
.filters .field { margin: 0; }

/* --- Verlauf / Bemerkungen --- */
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.notes li:last-child { border-bottom: none; }
.note-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.note-body { white-space: pre-wrap; }

dl.kv { margin: 0; display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 8px 18px; }
dl.kv dt { color: var(--text-muted); font-size: 13px; font-weight: 600; }
dl.kv dd { margin: 0; }
.pre { white-space: pre-wrap; }

/* --- Anfordernde Personen im Formular --- */
.people { display: flex; flex-direction: column; gap: 10px; }
.person {
  display: grid; gap: 10px; align-items: end;
  grid-template-columns: 1fr 1fr 1fr auto;
  padding: 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.person .field { margin: 0; }

/* --- Anmeldung --- */
.login-wrap { max-width: 380px; margin: 10vh auto; padding: 0 16px; }
.login-wrap h1 { text-align: center; margin-bottom: 6px; }
.login-wrap .sub { text-align: center; margin-bottom: 22px; }

/* --- Blätterfunktion --- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }

@media (max-width: 720px) {
  .person { grid-template-columns: 1fr; }
  .topbar { padding: 8px 14px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dd { margin-bottom: 10px; }
}
