:root {
  --ink: #2B2724;
  --ink-soft: #413b34;
  --muted: #8C8479;
  --paper: #F7F3EC;
  --paper-soft: #FBF8F3;
  --card: #FFFFFF;
  --line: #E4DED4;
  --line-input: #D9CFC0;
  --hover-tint: #F0EAE0;
  --divider-tint: #EFE9DE;
  --accent: #B5563C;
  --accent-hover: #9c4830;
  --warn: #D9A441;
  --ok: #6E8A5E;
  --ok-dark: #4A5D3A;
  --rose: #C08B7D;
  --sage: #7C8B6F;
  --lieferung: #8E9BAA;
  --offen: #B9AFA0;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap');
.font-serif { font-family: 'Fraunces', serif; }

.muted { color: var(--muted); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 18px 60px; }

header.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
h1 { font-size: 24px; margin: 0; font-weight: 600; }
.subtitle { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button, .btn {
  cursor: pointer; border: none; border-radius: 10px;
  padding: 10px 16px; font-size: 14px; font-weight: 500;
  font-family: inherit; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-soft); }
.btn-secondary { background: #fff; border: 1px solid var(--line-input); color: var(--ink); }
.btn-secondary:hover { background: var(--hover-tint); }
.btn-secondary:disabled { opacity: .4; cursor: default; }
.btn-danger { background: none; color: var(--accent); padding: 6px 0; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.stat-value { font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-select {
  margin-top: 4px; font-size: 11px; padding: 2px 4px; border-radius: 6px;
  border: 1px solid var(--line-input); background: #fff; color: var(--ink);
}

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box input {
  width: 100%; padding: 10px 12px 10px 34px; border-radius: 10px;
  border: 1px solid var(--line-input); background: #fff; font-size: 14px;
}
.search-box .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
select.filter {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-input);
  background: #fff; font-size: 14px;
}

.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list-empty { padding: 40px; text-align: center; color: var(--muted); font-size: 14px; }
.row {
  width: 100%; text-align: left; background: none; border: none; border-radius: 0;
  padding: 14px 18px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  border-bottom: 1px solid var(--divider-tint); border-left: 4px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--paper); }
.row-main { flex: 1; min-width: 0; }
.row-line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-name { font-weight: 500; }
.row-code { font-family: monospace; font-size: 11px; color: var(--muted); background: var(--paper); padding: 1px 6px; border-radius: 4px; }
.row-line2 { display: flex; gap: 12px; margin-top: 4px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap; }

.dots { display: flex; gap: 6px; flex-shrink: 0; }
.dot-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--line); }
.dot-num { font-size: 9px; color: var(--muted); }

.footnote { font-size: 12px; color: var(--muted); margin-top: 16px; }

/* Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.overlay.open { display: flex; }
.modal {
  background: var(--paper-soft); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--paper-soft); border-radius: 16px 16px 0 0;
}
.modal-head h2 { font-size: 18px; margin: 0; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; border-top: 1px solid var(--line);
}

.field > label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); font-weight: 500; display: block; margin-bottom: 4px;
}
.field input[type=text], .field input[type=date], .field input[type=number],
.field input[type=email], .field input[type=tel], .field select, .field textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line-input);
  background: #fff; font-size: 14px; font-family: inherit;
}
.field textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }

.code-box { display: flex; gap: 12px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.code-box .field { flex: 1; margin-bottom: 0; }
.code-box img { border: 1px solid var(--line-input); border-radius: 6px; background: #fff; padding: 4px; height: 48px; }
.code-box .print-link { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; color: var(--muted); text-decoration: none; }
.code-box .print-link:hover { color: var(--accent); }
.barcode-fallback {
  font-family: monospace; font-size: 12px; background: #fff; border: 1px solid var(--line-input);
  border-radius: 6px; padding: 12px 8px; min-width: 90px; text-align: center; align-items: center; justify-content: center;
}
.historie-box { max-height: 180px; overflow-y: auto; background: #fff; border: 1px solid var(--line-input); border-radius: 8px; padding: 10px 12px; }
.historie-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.historie-list li { display: flex; flex-direction: column; gap: 1px; border-bottom: 1px solid var(--divider-tint); padding-bottom: 6px; }
.historie-list li:last-child { border-bottom: none; padding-bottom: 0; }
.historie-datum { font-size: 11px; color: var(--muted); font-weight: 500; }
.historie-text { font-size: 13px; color: var(--ink); }

.dokumente-liste { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.dokument-zeile {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #fff; border: 1px solid var(--line-input); border-radius: 8px; padding: 8px 10px;
}
.dokument-link { color: var(--ink); text-decoration: none; font-size: 13px; display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dokument-link:hover { color: var(--accent); }
.dokument-zeile button {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; flex-shrink: 0;
}
.dokument-zeile button:hover { color: var(--accent); }
.code-hint { font-size: 11px; color: var(--muted); margin: 4px 0 0; line-height: 1.4; }

.termin-row { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line-input); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.termin-row span.tlabel { font-size: 12px; color: var(--muted); width: 60px; flex-shrink: 0; }
.termin-row input[type=date] { border: none; flex: 1; font-size: 14px; }
.termin-row .cal-link { font-size: 11px; color: var(--muted); text-decoration: none; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.termin-row label.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }

.kontroll-row { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; }
.kontroll-row input[type=text] { flex: 1; min-width: 0; }
.kontroll-ort-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.kontroll-ort { display: flex; gap: 8px; align-items: center; background: #fff; border: 1px solid var(--line-input); border-radius: 8px; padding: 9px 10px; flex-shrink: 0; }
.kontroll-ort label { display: flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
@media (max-width: 420px) {
  .kontroll-row { flex-wrap: wrap; }
}

.photo-upload {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px dashed var(--line-input); border-radius: 10px; padding: 12px;
  background: #fff; font-size: 14px; color: var(--muted); cursor: pointer;
}
.photo-upload:hover { background: var(--hover-tint); }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-thumb { position: relative; }
.photo-thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line-input); }
.photo-thumb button {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: 11px; padding: 0; display: flex;
  align-items: center; justify-content: center;
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 100%; max-width: 320px; text-align: center;
}
.login-box h1 { font-family: 'Fraunces', serif; font-size: 22px; margin-bottom: 4px; }
.login-box input { width: 100%; padding: 10px 12px; margin: 16px 0 12px; border-radius: 8px; border: 1px solid var(--line-input); font-size: 14px; }
.login-box button { width: 100%; }
.fehler { color: var(--accent); font-size: 13px; }
