:root {
  --bg: #0f1318;
  --surface: #171d24;
  --surface-2: #1e252e;
  --line: #2a333d;
  --text: #e8eef4;
  --muted: #93a1b0;
  --accent: #5ec486;
  --ok: #4f9d78;
  --soon: #d6a13a;
  --urgent: #e0763c;
  --expired: #d45c5c;
  --freeze: #4a9fd8;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .28);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --surface: #fff; --surface-2: #eef1f4; --line: #dde3e9;
    --text: #17202a; --muted: #5d6b79; --accent: #227d51; --ok: #227d51;
    --soon: #a8730c; --urgent: #c25a1c; --expired: #b3312f; --freeze: #1f6f9c;
    --shadow: 0 8px 20px rgba(20, 30, 40, .08);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; padding-bottom: env(safe-area-inset-bottom);
}
svg { width: 18px; height: 18px; flex: none; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 30px; height: 30px; color: var(--accent); }
h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 14px;
  font: inherit; font-size: 14px; font-weight: 550; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; transition: background .15s, border-color .15s, transform .06s; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #0c1410; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.freeze { background: color-mix(in srgb, var(--freeze) 16%, transparent); color: var(--freeze); border-color: color-mix(in srgb, var(--freeze) 45%, transparent); }
.btn.freeze:hover { background: color-mix(in srgb, var(--freeze) 26%, transparent); }
.btn:disabled { opacity: .5; cursor: default; }
@media (max-width: 640px) {
  .actions .btn span { display: none; }
  .actions .btn { width: 40px; padding: 0; justify-content: center; }
}

/* Layout */
main { max-width: 1080px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) 96px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .n { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 1px; }
.stat[data-k="expired"] .n { color: var(--expired); }
.stat[data-k="urgent"] .n { color: var(--urgent); }
.stat[data-k="soon"] .n { color: var(--soon); }
.stat[data-k="freeze_due"] .n { color: var(--freeze); }
.stat[data-k="ok"] .n { color: var(--ok); }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } .stat { padding: 10px 12px; } .stat .n { font-size: 19px; } }

/* Toolbar */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 220px; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; color: var(--muted); }
.search input { padding-left: 38px; }
input, select {
  width: 100%; height: 42px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; appearance: none;
}
select {
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.toolbar select { width: auto; flex: 0 0 auto; }
input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent); outline-offset: 1px;
}

/* Produktkarten */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.card[data-worst="expired"] { border-left-color: var(--expired); }
.card[data-worst="urgent"] { border-left-color: var(--urgent); }
.card[data-worst="soon"] { border-left-color: var(--soon); }
.card[data-worst="due"] { border-left-color: var(--freeze); }
.card[data-worst="ok"] { border-left-color: var(--ok); }

.card-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer;
  transition: background .15s; width: 100%; background: none; border: 0; color: inherit;
  font: inherit; text-align: left;
}
.card-head:hover { background: var(--surface-2); }
.card-head .chev { color: var(--muted); transition: transform .18s; }
.card.open .card-head .chev { transform: rotate(90deg); }
.card-title { min-width: 0; flex: 1; }
.card-title .name { font-weight: 600; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-title .name .qty { color: var(--muted); font-weight: 400; font-size: 13.5px; }
.card-title .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  font-size: 11.5px; font-weight: 600; border-radius: 999px; letter-spacing: .01em;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.soon { color: var(--soon); border-color: color-mix(in srgb, var(--soon) 40%, transparent); }
.chip.urgent { color: var(--urgent); border-color: color-mix(in srgb, var(--urgent) 45%, transparent); }
.chip.expired { color: var(--expired); border-color: color-mix(in srgb, var(--expired) 45%, transparent); }
.chip.freeze { color: var(--freeze); border-color: color-mix(in srgb, var(--freeze) 45%, transparent); }
.card-head .card-tools { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; background: transparent;
  border: 1px solid var(--line); border-radius: 9px; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* Chargen */
.batches { border-top: 1px solid var(--line); padding: 4px 0; display: none; }
.card.open .batches { display: block; }
.batch {
  display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}
.batch:last-of-type { border-bottom: 0; }
.batch .days { text-align: center; }
.batch .days .d { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; }
.batch .days .u { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.batch[data-status="expired"] .days .d { color: var(--expired); }
.batch[data-status="urgent"] .days .d { color: var(--urgent); }
.batch[data-status="soon"] .days .d { color: var(--soon); }
.batch-info { min-width: 0; }
.batch-info .l1 { font-size: 13.5px; font-weight: 550; }
.batch-info .l2 { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 3px 9px; margin-top: 2px; }
.batch-actions { display: flex; gap: 6px; align-items: center; }
.batch-empty { padding: 14px; color: var(--muted); font-size: 13.5px; }
.add-batch { padding: 4px 14px 12px; }

@media (max-width: 640px) {
  .batch { grid-template-columns: 62px 1fr; grid-template-areas: "days info" "days actions"; row-gap: 6px; }
  .batch .days { grid-area: days; }
  .batch-info { grid-area: info; }
  .batch-actions { grid-area: actions; justify-content: flex-start; }
  .card-head { flex-wrap: wrap; }
}

/* Dialoge */
.empty { text-align: center; color: var(--muted); padding: 48px 16px; font-size: 14.5px; }
dialog.sheet {
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  box-shadow: var(--shadow); overflow-y: auto;
}
dialog.sheet::backdrop { background: rgba(6, 10, 14, .62); backdrop-filter: blur(3px); }
dialog.sheet form { padding: 20px; }
dialog.sheet h2 { margin: 0 0 14px; font-size: 17px; }
.sheet-sub { margin: -8px 0 14px; font-size: 12.5px; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.field > span em { font-style: normal; color: var(--muted); opacity: .8; }
@media (max-width: 520px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: 0; border-radius: 18px 18px 0 0; position: fixed; bottom: 0; top: auto; }
  .sheet-actions { flex-direction: column-reverse; }
  .sheet-actions .btn { width: 100%; justify-content: center; }
}
@media (max-width: 360px) { .grid { grid-template-columns: 1fr; } }
.form-error { color: var(--expired); font-size: 13px; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 18px 0 0; padding: 0; flex-wrap: wrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.login-logo { width: 34px; height: 34px; color: var(--accent); }
.login-card h1 { font-size: 19px; margin: 10px 0 2px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
.login-card .field + .field { margin-top: 12px; }
.login-btn { width: 100%; justify-content: center; margin-top: 18px; height: 44px; }
.hint.full-hint { grid-column: 1 / -1; margin: -6px 0 0; }

/* Lösch-Aktionen: erst beim Hover der Karte rot, damit nichts versehentlich passiert */
.icon-btn.danger:hover { color: var(--expired); border-color: color-mix(in srgb, var(--expired) 50%, transparent); }

/* ---------- Einstellungen (Abschnitte) ---------- */
.settings-body { padding: 20px; }
.settings-body h2 { margin: 0 0 4px; font-size: 17px; }
.settings-section {
  border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px;
}
.settings-section h3 {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 12px; font-weight: 650;
}
.settings-section .field + .field { margin-top: 10px; }
.section-actions { display: flex; gap: 8px; margin-top: 14px; }
.section-actions.spread { justify-content: space-between; }
.settings-footer {
  display: flex; justify-content: flex-end; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--line);
}
.form-ok { color: var(--ok); font-size: 13px; margin: 10px 0 0; }

/* ---------- Benutzerverwaltung ---------- */
.user-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.user-item {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.user-item .u-name { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-item .u-meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.user-item .u-actions { display: flex; gap: 6px; }
.role-badge {
  font-size: 10.5px; font-weight: 650; letter-spacing: .03em; padding: 2px 7px;
  border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
}
.role-badge.admin { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.user-form { border-top: 1px dashed var(--line); padding-top: 14px; }
@media (max-width: 520px) {
  .user-item { grid-template-columns: 1fr; }
  .user-item .u-actions { justify-content: flex-start; }
}

/* ---------- Protokoll ---------- */
.sheet.wide { width: min(1040px, 96vw); }
.log-filters {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 14px 0 10px;
}
.log-scroll { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.log-table thead th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 650;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: var(--surface-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.log-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log-table tr:last-child td { border-bottom: 0; }
.log-table td.when { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-table td.who { white-space: nowrap; }
.log-table td.detail { color: var(--muted); }
.log-type {
  display: inline-block; font-size: 10.5px; font-weight: 650; padding: 2px 7px;
  border-radius: 999px; border: 1px solid var(--line); white-space: nowrap;
}
.log-type.t-danger { color: var(--expired); border-color: color-mix(in srgb, var(--expired) 45%, transparent); }
.log-type.t-warn { color: var(--soon); border-color: color-mix(in srgb, var(--soon) 45%, transparent); }
.log-type.t-info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.log-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 620px) {
  .log-filters { grid-template-columns: 1fr; }
  .log-table td.detail, .log-table th:nth-child(5) { display: none; }
}

/* ---------- Anwesenheit ---------- */
.presence {
  font-size: 10px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 999px; display: inline-flex; align-items: center; gap: 4px;
}
.presence::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.presence.on { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.presence.off { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, transparent); }

/* ---------- Einstellungen als eigene Seite ---------- */
.topbar .back {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  color: var(--muted); text-decoration: none; flex: none;
  border: 1px solid var(--line); background: var(--surface-2);
}
.topbar .back:hover { color: var(--text, inherit); }
.topbar .back svg { width: 18px; height: 18px; }
.settings-main { max-width: 820px; margin: 0 auto; padding: 18px 16px 60px; }

.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px;
  border-bottom: 1px solid var(--line); margin-bottom: 18px;
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer; font: inherit;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  padding: 9px 12px; border-radius: 9px 9px 0 0; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text, inherit); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab[hidden] { display: none; }

.panel h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 650; margin: 22px 0 12px;
}
.panel h2:first-child { margin-top: 0; }
.panel .field + .field { margin-top: 10px; }
.panel .section-actions { margin-top: 14px; }
@media (max-width: 520px) {
  .settings-main { padding: 14px 12px 48px; }
  .tab { padding: 8px 10px; font-size: 13px; }
}

/* ---------- Zugeklapptes Benutzer-Formular ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.panel-head .btn svg { width: 15px; height: 15px; }
.user-form-wrap { margin-top: 22px; }
.user-form-wrap h2 { margin-top: 0; }
@media (max-width: 520px) {
  .panel-head { flex-wrap: wrap; }
}

/* ---------- Geräte ---------- */
.device-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.device-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px;
}
.device-item.is-current { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.device-icon {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); flex: none;
}
.device-icon svg { width: 18px; height: 18px; }
.device-name { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.device-body { min-width: 0; }
@media (max-width: 560px) {
  .device-item { grid-template-columns: auto 1fr; }
  .device-item .u-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---------- Passwortfelder ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.check {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- Passwortfeld mit Auge ---------- */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 42px; width: 100%; box-sizing: border-box; }
.pw-eye {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; background: none; cursor: pointer; border-radius: 8px; color: var(--muted);
}
.pw-eye:hover { color: var(--text, inherit); background: color-mix(in srgb, currentColor 10%, transparent); }
.pw-eye.on { color: var(--accent); }
.pw-eye svg { width: 17px; height: 17px; }
.pw-eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Passwortstärke ---------- */
.pw-meter { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.pw-meter-bar {
  flex: 1; height: 4px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--muted) 25%, transparent);
}
.pw-meter-bar span {
  display: block; height: 100%; width: 0; border-radius: 999px;
  transition: width .18s ease, background .18s ease; background: var(--muted);
}
.pw-meter-bar span[data-level="1"] { background: var(--expired); }
.pw-meter-bar span[data-level="2"] { background: var(--soon); }
.pw-meter-bar span[data-level="3"] { background: #d8b24a; }
.pw-meter-bar span[data-level="4"] { background: var(--accent); }
.pw-meter-bar span[data-level="5"] { background: var(--ok); }
.pw-meter-text { font-size: 11.5px; color: var(--muted); min-width: 76px; text-align: right; }

/* Dialog: Innenabstand, wenn kein <form> direktes Kind ist */
dialog.sheet .settings-body { padding: 20px; }
dialog.sheet .settings-body h2 { margin: 0 0 10px; font-size: 17px; }
dialog.sheet .settings-body form { padding: 0; }

/* ---------- Bestandsprüfung ---------- */
.chip.check-due {
  background: color-mix(in srgb, #d8b24a 18%, transparent);
  color: #d8b24a;
  border-color: color-mix(in srgb, #d8b24a 40%, transparent);
}

/* Prüf-Modus: nur zählen, alles andere tritt zurück */
body.check-mode .stats,
body.check-mode .toolbar { display: none; }
body.check-mode .card { border-color: var(--line); }
body.check-mode .batch .days,
body.check-mode .batch .batch-actions,
body.check-mode .add-batch,
body.check-mode .card-tools { display: none; }
body.check-mode .check-row { display: flex; }
.check-row { display: none; align-items: center; gap: 10px; width: 100%; }
.check-dot {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  border: 2px solid var(--line);
}
.check-dot.ok { background: var(--ok); border-color: var(--ok); }
.check-dot.adjusted { background: #d8b24a; border-color: #d8b24a; }
.check-dot.open { background: transparent; border-color: var(--expired); }
.check-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.check-meta { font-size: 11.5px; color: var(--muted); }
.check-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  margin: 16px -16px -16px;
}
.check-bar .tally { flex: 1; font-size: 12.5px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.tally b { color: var(--text, inherit); font-variant-numeric: tabular-nums; }
