:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2630;
  --muted: #66717e;
  --line: #d9e0e7;
  --accent: #126c78;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --ok-bg: #edf8f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar strong {
  display: block;
  font-size: 18px;
}

.topbar span {
  color: var(--muted);
  font-size: 13px;
}

nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 14px;
  max-width: 860px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

main {
  width: min(1440px, calc(100vw - 32px));
  margin: 28px auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stats article,
.panel,
.import-grid form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats article {
  padding: 18px;
}

.stats span {
  color: var(--muted);
}

.stats strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.stats .danger strong {
  color: var(--danger);
}

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2 {
  margin: 0 0 16px;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 17px;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.num {
  text-align: right;
}

tr.missing {
  background: var(--danger-bg);
}

tr.sent {
  background: var(--ok-bg);
}

tr.partial {
  background: #fff8df;
}

tr.over {
  background: #eef4ff;
}

tr.muted-row {
  color: var(--muted);
  background: #f8fafb;
}

.status {
  font-weight: 700;
}

.actions form {
  margin: 0;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font: inherit;
  cursor: pointer;
}

.logout {
  margin: 0;
}

.logout button {
  min-height: 30px;
  background: #52616f;
}

.button.secondary {
  background: #52616f;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.filters input,
.filters select {
  width: auto;
  min-width: 190px;
  margin: 0;
}

select {
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 10px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.login-page {
  background: #eef2f5;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-box {
  width: min(380px, calc(100vw - 32px));
  padding: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.error {
  padding: 10px 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 6px;
}

input {
  width: 100%;
  min-height: 38px;
  margin: 6px 0 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

label {
  color: var(--muted);
  font-size: 13px;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.import-grid form {
  padding: 16px;
}

.empty {
  color: var(--muted);
  text-align: center;
}

/* ---- Abgleich-Board (Packschein <-> Wareneingang) ---- */
.board { display: flex; flex-direction: column; gap: 16px; }
.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.board-head h1 { margin: 0 0 4px; }
.board .sub { margin: 0; color: var(--muted); font-size: 13px; max-width: 900px; }

.flash { padding: 11px 14px; border-radius: 8px; font-size: 14px; }
.flash.ok { background: var(--ok-bg); color: #1a7f4b; border: 1px solid #b7e2c8; }

.toolbar {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 12px;
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.toolbar .field.grow { flex: 1; min-width: 200px; }
.toolbar .field label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.toolbar .field input { margin: 0; min-width: 150px; }
.toolbar .field.grow input { width: 100%; }
.toolbar .sep { flex: 1; }

.button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.button.secondary { background: #eef2f5; color: var(--ink); border: 1px solid var(--line); }

.mailbox { position: relative; }
.mailbox > summary { list-style: none; cursor: pointer; }
.mailbox > summary::-webkit-details-marker { display: none; }
.mailform {
  position: absolute; right: 0; z-index: 20; margin-top: 8px; width: 300px;
  padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(20,40,60,.16);
}
.mailform label { font-size: 12px; }
.mailform input { margin: 6px 0 10px; }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.kpi {
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid #c7d0d8; border-radius: 10px;
}
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { display: block; margin-top: 6px; font-size: 26px; line-height: 1; }
.kpi.bad { border-left-color: #d64545; } .kpi.bad strong { color: #b42318; }
.kpi.good { border-left-color: #2fa36b; }
.kpi.warn { border-left-color: #e0a63c; }
.kpi.info { border-left-color: #3f81cf; }

.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: 74vh; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid thead th {
  position: sticky; top: 0; z-index: 1; background: #f2f5f7; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 10px; text-align: left; white-space: nowrap;
}
table.grid td { padding: 9px 10px; border-top: 1px solid var(--line); vertical-align: top; }
table.grid tbody tr:hover { background: #f7fafb; }
table.grid td.desc { max-width: 220px; }
table.grid td.dates { font-size: 12px; color: var(--ink); white-space: nowrap; }
.red { color: var(--danger); }
tr.st-fehlmenge { background: #fdf3f2; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.fehlmenge { background: #fdecea; color: #b42318; }
.pill.vollstaendig { background: #e9f7ef; color: #1a7f4b; }
.pill.offen { background: #fff6e0; color: #8a5a00; }
.pill.ueberlieferung { background: #eaf2fd; color: #1f5fa8; }

table.grid details > summary { cursor: pointer; color: var(--accent); font-size: 13px; white-space: nowrap; }
table.mini { margin-top: 8px; border-collapse: collapse; font-size: 12px; background: #fbfdfe; }
table.mini th, table.mini td { padding: 4px 8px; border: 1px solid var(--line); text-align: left; }
table.mini tr.arrived { background: #e6f6ec; }
table.mini tr.arrived td { color: #14603a; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.ok { background: #2fa36b; } .dot.warn { background: #e0a63c; } .dot.muted { background: #c1c9d1; }
.foot { color: var(--muted); font-size: 13px; margin: 4px 2px 0; }

.pill.ohne_packschein { background: #fff6e0; color: #8a5a00; }
.intlink { font-size: 11px; color: var(--muted); }
.intlink:hover { color: var(--accent); text-decoration: underline; }
.done { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #e9f7ef; color: #1a7f4b; }
.notebadge { display: inline-block; margin-left: 6px; font-size: 11px; color: #8a5a00; cursor: help; }
.filelist { margin-top: 6px; font-size: 12px; max-height: 220px; overflow: auto; }
.toolbar .check { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.toolbar .check input { width: auto; min-width: 0; margin: 0; }

/* WE-Blöcke (nach Einbuchungstag) */
.block { display: flex; flex-direction: column; }
.block-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 6px 2px 8px; }
.daybadge { font-size: 15px; font-weight: 700; color: #fff; background: var(--accent); padding: 4px 12px; border-radius: 8px; }
.block-meta { color: var(--muted); font-size: 13px; }
.block-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.bignote { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.sources { min-width: 320px; }
.src { display: inline-block; margin: 2px 10px 2px 0; padding: 2px 8px; background: #f2f6f8; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; white-space: nowrap; }
.src .lead { color: var(--accent); font-weight: 700; }
tr.st-ohne_packschein { background: #fff6e0; }
tr.st-ueberlieferung { background: #eaf2fd; }

/* Fixierte Kennspalten (Status / OE-Nummer / Bezeichnung) beim horizontalen Scrollen */
.grid.sticky3 .c1, .grid.sticky3 .c2, .grid.sticky3 .c3 { position: sticky; z-index: 1; }
.grid.sticky3 .c1 { left: 0; min-width: 122px; }
.grid.sticky3 .c2 { left: 122px; min-width: 150px; }
.grid.sticky3 .c3 { left: 272px; min-width: 200px; max-width: 240px; box-shadow: 6px 0 8px -6px rgba(20,40,60,.18); }
.grid.sticky3 td.c1, .grid.sticky3 td.c2, .grid.sticky3 td.c3 { background: #fff; }
.grid.sticky3 tr.st-ohne_packschein td.c1, .grid.sticky3 tr.st-ohne_packschein td.c2, .grid.sticky3 tr.st-ohne_packschein td.c3 { background: #fff6e0; }
.grid.sticky3 tr.st-ueberlieferung td.c1, .grid.sticky3 tr.st-ueberlieferung td.c2, .grid.sticky3 tr.st-ueberlieferung td.c3 { background: #eaf2fd; }
.grid.sticky3 thead th.c1, .grid.sticky3 thead th.c2, .grid.sticky3 thead th.c3 { z-index: 3; background: #f2f5f7; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .board-head, .toolbar { flex-direction: column; align-items: stretch; }
  .mailform { position: static; width: auto; }
  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats,
  .import-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .filters {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .filters input,
  .filters select,
  .filters button {
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
