:root {
  --dark: #111;
  --accent: #9b0000;
  --line: #e2e2e2;
  --muted: #666;
  --bg: #f3f3f3;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--dark);
  background: var(--bg);
  line-height: 1.45;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--dark);
  padding: 14px 20px;
}
.topbar__brand { display: inline-flex; align-items: center; }
/* "Positiv"-Logo (schwarz) auf dunklem Hintergrund zu Weiss invertieren */
.topbar__logo { height: 34px; width: auto; filter: invert(1) brightness(1.6); }
.topbar__title { color: #fff; font-weight: bold; white-space: nowrap; }

/* Navigation (Desktop: inline; Mobile: Off-Canvas, s. Media-Query) */
.topbar__nav { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.topbar__nav a {
  color: #fff; text-decoration: none; font-size: 14px; opacity: .85; white-space: nowrap;
}
.topbar__nav a:hover { opacity: 1; text-decoration: underline; }

/* CSS-only Toggle (versteckte Checkbox), Hamburger + Backdrop nur mobil sichtbar */
.nav-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.nav-burger { display: none; }
.nav-backdrop { display: none; }

.wrap { max-width: 860px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 26px; margin: 8px 0 20px; }

/* Banners */
.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 20px; }
.banner--ok { background: #dff5df; border: 1px solid #8bcf8b; color: #0b5f24; }
.banner--err { background: #fdecec; border: 1px solid #e0a3a3; color: var(--accent); }
.banner__sub { color: #0b5f24; font-size: 13px; }

/* Cards / sections */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 8px;
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 16px;
  border-left: 4px solid var(--accent);
  padding-left: 10px;
}

/* Grid layout */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field--wide { grid-column: 1 / -1; }
.field--error input, .field--error select, .field--error textarea { border-color: var(--accent); }

label { font-size: 13px; color: var(--muted); font-weight: bold; }
.req { color: var(--accent); }

input:not([type=radio]):not([type=checkbox]):not([type=hidden]),
select, textarea {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  width: 100%;
}
input.calc { background: #f6f6f6; font-weight: bold; }
textarea { resize: vertical; }
.help { font-size: 12px; color: var(--muted); }
.error-msg { font-size: 12px; color: var(--accent); }

/* Option groups (radio / checkbox) */
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 14px;
  color: var(--dark);
  font-weight: normal;
  background: #fff;
}
.opt input { accent-color: var(--accent); }
.opt:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.opt:has(input:checked) input { accent-color: #fff; }
.options--check .opt { min-width: 0; }

/* Actions */
.actions { margin-top: 8px; }
.btn {
  font: inherit;
  font-weight: bold;
  border: none;
  border-radius: 6px;
  padding: 14px 22px;
  cursor: pointer;
  letter-spacing: .5px;
}
.btn--primary { background: var(--accent); color: #fff; width: 100%; font-size: 16px; }
.btn--primary:hover { background: #7c0000; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
}

/* ---- Auth pages ---- */
.auth {
  max-width: 380px;
  margin: 8vh auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
}
.auth img { height: 40px; display: block; margin: 0 auto 18px; }
.auth h1 { font-size: 20px; text-align: center; margin: 0 0 18px; }
.auth .field { margin-bottom: 16px; }
body.dark { background: var(--dark); }

/* ---- Admin ---- */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.toolbar .field { margin: 0; }
.btn--dark { background: var(--dark); color: #fff; }
.btn--ghost { background: #fff; border: 1px solid #ccc; color: var(--dark); text-decoration: none; display: inline-block; }
.btn--sm { padding: 8px 14px; font-size: 14px; }

table.data { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.data th { background: var(--dark); color: #fff; text-align: left; padding: 9px 10px; font-size: 13px; }
table.data td { padding: 8px 10px; border-top: 1px solid var(--line); font-size: 14px; }
table.data tr:nth-child(even) td { background: #fafafa; }
table.data .num { text-align: right; }
.cards-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 140px; }
.stat .n { font-size: 20px; font-weight: bold; color: var(--accent); }
.stat .l { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
a { color: var(--accent); }

/* ---- Off-Canvas-Navigation (Tablet & Mobile) ---- */
@media (max-width: 768px) {
  /* verhindert horizontalen Scroll durch das ausgeblendete Panel rechts */
  body { overflow-x: hidden; }

  /* Hamburger einblenden, über dem Panel klickbar halten */
  .nav-burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    margin-left: auto;
    width: 44px;
    height: 40px;
    padding: 0 10px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 6px;
    position: relative;
    z-index: 70;
  }
  .nav-burger span { display: block; height: 2px; background: #fff; border-radius: 2px; transition: transform .25s, opacity .2s; }

  /* Navigation als Panel von rechts */
  .topbar__nav {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 60;
    height: 100vh;
    width: min(80vw, 290px);
    margin: 0;
    padding: 76px 22px 24px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: var(--dark);
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  .topbar__nav a {
    font-size: 16px;
    opacity: 1;
    padding: 14px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
  }
  .nav-toggle:checked ~ .topbar__nav { transform: translateX(0); box-shadow: -8px 0 28px rgba(0, 0, 0, .45); }

  /* Abdunkelnder Hintergrund, Klick schliesst */
  .nav-toggle:checked ~ .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5); }

  /* Hamburger -> X, wenn geöffnet */
  .nav-toggle:checked ~ .nav-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle:checked ~ .nav-burger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .nav-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}

/* ---- Mobile (Admin + allgemein) ---- */
@media (max-width: 640px) {
  /* Kopfzeile kompakter */
  .topbar { gap: 12px; padding: 10px 12px; }
  .topbar__logo { height: 26px; }
  .topbar__title { font-size: 14px; }

  .wrap, .admin-wrap { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 22px; }

  /* Toolbar gestapelt und tap-freundlich */
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .field, .toolbar .btn { width: 100%; }
  .toolbar .field input { width: 100%; }

  /* Statistik-Karten 2 pro Reihe */
  .stat { flex: 1 1 calc(50% - 10px); min-width: 0; }

  /* Breite Listen-Tabellen (mit Kopfzeile) horizontal scrollbar statt Überlauf;
     Detail-Tabellen (Label/Wert, ohne thead) brechen weiterhin normal um. */
  table.data:has(thead) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
}
