:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e6e8ee;
  --border-strong: #d3d7e0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0a1a3a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .04);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100vh;
  position: sticky;
  top: 0;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.brand img { width: 100%; max-width: 220px; height: auto; object-fit: contain; }

/* Hamburger-Toggle: nur auf Mobile sichtbar */
.nav-toggle { display: none; }
.brand-title { font-weight: 700; color: var(--brand); font-size: 14px; }
.brand-sub { color: var(--muted); font-size: 12px; }

.nav-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 12px 12px 6px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: background .12s, color .12s;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.nav a:hover, .nav-btn:hover { background: #f1f3f8; text-decoration: none; }
.nav a.active {
  background: #eef3ff;
  color: var(--accent);
  font-weight: 600;
}
.nav .ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  font-size: 16px;
  color: var(--muted);
}
.nav a.active .ico { color: var(--accent); }

/* ── Main area ───────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 60px;
  max-width: 1440px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 24px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--brand);
  margin: 0 0 6px;
  letter-spacing: -.01em;
}
.muted { color: var(--muted); }
.muted.small { font-size: 13px; }

.flash-stack { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s, border .12s, transform .04s;
  font-family: inherit;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border-strong); }
.btn-ghost:hover { background: #f1f3f8; text-decoration: none; color: var(--text); }

.btn-mini, button.btn-mini {
  display: inline-block;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: white;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background .12s, border .12s;
}
.btn-mini:hover { background: #f1f3f8; text-decoration: none; }
.btn-mini-success { color: #065f46; border-color: #a7f3d0; background: #ecfdf5; }
.btn-mini-success:hover { background: #d1fae5; }
.btn-mini-danger { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.btn-mini-danger:hover { background: #fee2e2; }

/* ── Toolbar / chips ─────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.input {
  flex: 1;
  min-width: 240px;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #f9fafc;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border .12s, background .12s, box-shadow .12s;
}
.input:focus {
  background: white;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  background: #f1f3f8;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s, border .12s;
}
.chip:hover { background: #e6e9f0; color: var(--text); }
.chip.active { background: white; color: var(--brand); border-color: var(--border-strong); box-shadow: var(--shadow); }
.chip .count {
  font-size: 11px;
  background: rgba(15, 23, 42, .08);
  color: inherit;
  padding: 1px 7px;
  border-radius: 999px;
}
.chip.active .count { background: var(--accent); color: white; }

/* ── Table ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card.menu-open { overflow: visible; }
.card.menu-open .table-wrap { overflow: visible; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
}
.table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: #fafbfd; }
.table tbody tr.row-clickable { cursor: pointer; }
.table tbody tr.row-clickable:hover { background: #f1f5ff; }
.table tbody tr:last-child td { border-bottom: none; }
.mono { font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace; font-size: 12px; color: var(--muted); }
.strong { font-weight: 600; color: var(--text); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
.actions .inline { display: inline; }
.actions > form { display: inline-block; margin-left: 4px; }
.truncate {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Pills ──────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: .01em;
}
.pill-offen { background: #ede9fe; color: #6d28d9; }
.pill-bezahlt { background: #dcfce7; color: #166534; }
.pill-verspaetet { background: #fee2e2; color: #991b1b; }
.pill-archiviert { background: #f1f3f8; color: #475569; }
.pill-terminiert { background: #fff7ed; color: #9a3412; margin-left: 4px; }

/* ── Terminierter Versand (Popover) ──────────────────────── */
.actions details.sched { display: inline-block; position: relative; margin-left: 4px; }
.actions details.sched > summary {
  list-style: none;
  display: inline-block;
}
.actions details.sched > summary::-webkit-details-marker { display: none; }
.actions details.sched[open] > summary { background: #f1f3f8; }
.sched-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  padding: 12px;
  width: 240px;
  text-align: left;
  white-space: normal;
}
.sched-form { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.sched-form input[type="datetime-local"] {
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}
.sched-label { font-size: 12px; font-weight: 600; color: var(--muted, #64748b); }
.sched-pop .inline { margin-top: 8px; display: block; }
.sched-pop .inline button { width: 100%; }

/* ── Aktionen-Menü (⋯) ──────────────────────────────────── */
.actions details.menu { display: inline-block; position: relative; margin-left: 4px; }
.actions details.menu > summary {
  list-style: none;
  display: inline-block;
  font-weight: 700;
  letter-spacing: .1em;
  padding-left: 10px;
  padding-right: 10px;
}
.actions details.menu > summary::-webkit-details-marker { display: none; }
.actions details.menu[open] > summary { background: #f1f3f8; }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  padding: 6px;
  width: 230px;
  text-align: left;
  white-space: normal;
}
.menu-form { display: block; margin: 0; }
.menu-item {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
}
.menu-item:hover { background: #f1f3f8; text-decoration: none; }
.menu-item-success { color: #065f46; }
.menu-item-success:hover { background: #ecfdf5; }
.menu-item-danger { color: #991b1b; }
.menu-item-danger:hover { background: #fef2f2; }
.menu-sched {
  margin: 6px 4px;
  padding: 10px 6px 4px;
  border-top: 1px solid var(--border);
}
.menu-sched .sched-form { margin-bottom: 8px; }
.menu-sched .btn-mini { width: 100%; }

/* ── Empty state ────────────────────────────────────────── */
.empty {
  padding: 60px 20px;
  text-align: center;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--brand); font-weight: 600; }
.empty p { margin: 0 0 20px; }

/* ── Form ───────────────────────────────────────────────── */
.form { padding: 0; }
.form-section {
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
}
.form-section.subtle { background: #fafbfd; }
.form-section h2 {
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
}
.grid label.full { grid-column: 1 / -1; }
.grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.grid input, .grid select {
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: white;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border .12s, box-shadow .12s;
}
.grid input:focus, .grid select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.form-actions {
  padding: 20px 28px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #fafbfd;
}

/* ── Login-Seite ─────────────────────────────────────────────────── */
.login-body {
  display: flex;
  min-height: 100vh;
  margin: 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, .06);
}
.login-logo {
  display: block;
  max-width: 170px;
  height: auto;
  margin: 4px auto 22px;
}
.login-bio { width: 100%; justify-content: center; font-size: 15px; padding: 12px; }
.login-bio-msg { min-height: 1.2em; margin: 8px 0 0; text-align: center; font-size: 13px; }
.login-sep {
  position: relative;
  text-align: center;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12px;
}
.login-sep::before {
  content: "";
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 1px;
  background: var(--border);
}
.login-sep span { position: relative; background: var(--surface); padding: 0 10px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input {
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
}
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login-submit { width: 100%; justify-content: center; margin-top: 4px; padding: 12px; }

/* ── Passkey-Liste (Einstellungen) ───────────────────────────────── */
.pk-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.pk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafbfd;
  font-size: 14px;
}

/* ── Mobile / Tablet ─────────────────────────────────────── */
@media (max-width: 820px) {
  /* Sidebar wird zur kompakten oberen Leiste statt linker Spalte */
  body { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
  }
  /* Obere Leiste: Logo links, Hamburger rechts */
  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  .brand {
    padding: 0;
    margin: 0;
    border-bottom: none;
    justify-content: flex-start;
  }
  .brand img { max-width: 120px; }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--text);
    cursor: pointer;
  }
  .nav-toggle:hover { background: #f1f3f8; }

  /* Funktionen einklappbar: standardmäßig versteckt */
  .nav-groups { display: none; width: 100%; padding-top: 8px; }
  .sidebar.nav-open .nav-groups { display: block; }
  .nav-section { display: block; padding: 10px 12px 4px; }
  .nav { flex-direction: column; gap: 2px; }
  .nav a, .nav-btn {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Hauptbereich nimmt volle Breite ein */
  .main {
    padding: 18px 16px 48px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    max-width: none;
  }
  .page-head { gap: 12px; margin-bottom: 18px; }
  .page-head h1 { font-size: 22px; }
  .page-head .btn { width: 100%; justify-content: center; }

  /* Toolbar: Suche volle Breite, Filter-Chips horizontal scrollbar */
  .toolbar { padding: 12px 14px; gap: 10px; }
  .input { flex: 1 1 100%; min-width: 0; width: 100%; }
  .filter-group {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .chip { flex: 0 0 auto; }

  /* Formular einspaltig */
  .grid { grid-template-columns: 1fr; }
  .form-section { padding: 18px 16px; }
  .form-actions { padding: 16px; flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

/* ── Rechnungstabelle als Karten auf dem Handy ────────────────── */
@media (max-width: 720px) {
  .table-wrap { overflow: visible; padding: 14px; }
  .table, .table tbody { display: block; width: 100%; }
  .table thead { display: none; }

  .table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .05);
    padding: 4px 16px;
  }
  .table tr + tr { margin-top: 14px; }
  .table tbody tr:hover { background: #fff; }

  .table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 0;
    border-bottom: none;
    border-top: 1px solid var(--border);
    text-align: right;
    white-space: normal;
  }
  .table td:first-child { border-top: none; }
  .table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: left;
  }

  /* Empfänger hervorheben, Beschreibung darf umbrechen */
  .table td.strong { font-size: 15px; }
  .table td.truncate {
    max-width: none;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
  }
  .table td.num { font-size: 15px; }

  /* Aktionen: Label links, Buttons rechts gruppiert */
  .table td.actions { justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
  .table td.actions::before { margin-right: auto; }
}

/* ── Update-Banner (neue App-Version verfuegbar) ───────────────── */
.update-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translate(-50%, 0);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 18px;
  background: var(--brand, #0a1a3a);
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(10, 26, 58, 0.35);
  /* iOS-Notch / Home-Indicator beruecksichtigen */
  margin-bottom: env(safe-area-inset-bottom, 0px);
  /* Von unten hereingleiten, statt aufzupoppen. */
  animation: update-banner-in .35s cubic-bezier(.16, 1, .3, 1) both;
}
.update-banner[hidden] { display: none; }
@keyframes update-banner-in {
  from { transform: translate(-50%, calc(100% + 32px)); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}
.update-banner-text { font-size: 14px; font-weight: 500; white-space: nowrap; }
.update-banner-btn {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background .12s, opacity .12s;
}
.update-banner-btn:hover { background: var(--accent-hover); }
.update-banner-btn:disabled { opacity: .6; cursor: default; }

@media (max-width: 640px) {
  .update-banner {
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: translateY(0);
    max-width: none;
    justify-content: space-between;
    animation-name: update-banner-in-full;
  }
  .update-banner-text { white-space: normal; }
  @keyframes update-banner-in-full {
    from { transform: translateY(calc(100% + 24px)); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .update-banner { animation: none; }
}
