:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #5d6b7a;
  --line: #dde2e8;
  --accent: #0b5cad;
  --accent-ink: #ffffff;
  --new: #1d7a46;
  --new-bg: #e6f4ec;
  --upd: #0b5cad;
  --upd-bg: #e5eff9;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --err: #a32020;
  --err-bg: #fde8e8;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b; --surface: #1b2128; --ink: #e6ebf0; --muted: #98a5b3; --line: #2d3540;
    --accent: #4d9be6; --accent-ink: #0b1420;
    --new: #6fd19a; --new-bg: #173325; --upd: #7db8f0; --upd-bg: #162a3f;
    --warn: #f0c060; --warn-bg: #3a2e12; --err: #f19090; --err-bg: #3d1a1a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 3px 8px; border-radius: 4px; letter-spacing: .04em; }
.brand-title { font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 0; padding: 8px 12px; border-radius: 6px; color: var(--muted); font: inherit; cursor: pointer; }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.status { margin-left: auto; font-size: 13px; color: var(--muted); }
.status .pill { display: inline-block; padding: 2px 8px; border-radius: 999px; margin-left: 6px; font-weight: 600; }
.pill.ok { background: var(--new-bg); color: var(--new); }
.pill.dry { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

.notice { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 12px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.err { background: var(--err-bg); color: var(--err); }
.notice.ok { background: var(--new-bg); color: var(--new); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

.upload-row { display: grid; grid-template-columns: 1fr 300px; gap: 20px; margin-bottom: 20px; }
@media (max-width: 760px) { .upload-row { grid-template-columns: 1fr; } }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 150px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; text-align: center; padding: 20px; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--accent); outline: none; }
.dropzone.over { background: var(--upd-bg); }
.dz-title { font-size: 18px; font-weight: 600; }
.dz-sub { color: var(--muted); font-size: 13px; }
.upload-opts { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.upload-opts label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.upload-opts p { margin: 8px 0 0; }
select.need { outline: 2px solid var(--err); outline-offset: -1px; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[readonly] { color: var(--muted); }
textarea { min-height: 70px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.queue { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.queue li { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; font-size: 14px; }
.queue .q-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .q-state.err { color: var(--err); }
.queue .q-state.done { color: var(--new); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.card-head { display: flex; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }
.card-title { flex: 1; min-width: 200px; }
.card-title .photo { font-size: 13px; color: var(--muted); }
.card-title .name { font-weight: 600; }
.badge { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge.new { background: var(--new-bg); color: var(--new); }
.badge.update { background: var(--upd-bg); color: var(--upd); }
.card-body { padding: 16px; display: grid; gap: 14px; }
.hints { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 8px 12px; font-size: 14px; }
.hints ul { margin: 0; padding-left: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: none; }
.field.wide { grid-column: 1 / -1; }
.field .sub { font-weight: 400; }
.field.changed input, .field.changed select { border-color: var(--upd); }
.menge-calc { display: flex; align-items: center; gap: 8px; }
.menge-calc input { width: 90px; }
.menge-calc span { color: var(--muted); white-space: nowrap; }
.serials { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .serials { grid-template-columns: 1fr; } }
.serial-list { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-height: 120px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; white-space: pre-wrap; }
.actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.actions .msg { margin-right: auto; font-size: 14px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--new); }

.btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 8px 16px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: none; }
.btn:disabled { opacity: .55; cursor: default; }

.card.saved .card-body { display: none; }
.card.saved { opacity: .85; }
.card.discarded { display: none; }

.protocol-head { display: flex; align-items: center; justify-content: space-between; }
.protocol-head h2 { margin: 0 0 12px; font-size: 18px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.serials-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-width: 260px; word-break: break-all; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; z-index: 20; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }

.logout { font-size: 13px; color: var(--muted); text-decoration: none; }
.logout:hover { color: var(--ink); }
.field .tag { font-weight: 400; color: var(--muted); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-box .brand { margin-bottom: 18px; }
.login-box form { display: grid; gap: 8px; }
.login-box label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.login-box .btn { margin-top: 12px; }
main > .notice { max-width: 700px; margin: 40px auto; }
