:root {
  --ssmc-50:  #E6F1FB;
  --ssmc-100: #B5D4F4;
  --ssmc-400: #378ADD;
  --ssmc-600: #185FA5;
  --ssmc-800: #0C447C;
  --ssmc-900: #042C53;

  --ink:      #1c2530;
  --muted:    #6b7684;
  --line:     #e4e9f0;
  --bg:       #f4f7fb;
  --white:    #ffffff;

  --success-bg: #E1F5EE; --success-fg: #0F6E56;
  --error-bg:   #FCEBEB; --error-fg:   #A32D2D;
  --amber-bg:   #FAEEDA; --amber-fg:   #854F0B;

  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.container { max-width: 860px; margin: 0 auto; padding: 24px 18px 48px; }
.container-narrow { max-width: 420px; margin: 0 auto; padding: 40px 18px; }

/* Kopfzeile / Branding */
.brandbar {
  background: var(--ssmc-50);
  border-bottom: 1px solid var(--ssmc-100);
}
.brandbar .inner {
  max-width: 860px; margin: 0 auto; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-tile {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--ssmc-600); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; flex-shrink: 0;
}
.brand-title { font-weight: 600; font-size: 15px; color: var(--ssmc-900); }
.brand-sub   { font-size: 12px; color: var(--ssmc-600); }

.topnav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topnav a {
  font-size: 13px; padding: 6px 12px; border-radius: 8px; color: var(--ssmc-800);
}
.topnav a:hover { background: #d9e8fb; text-decoration: none; }
.topnav a.active { background: var(--ssmc-600); color: #fff; }
.topnav .who { font-size: 12px; color: var(--ssmc-600); padding: 6px 4px; }

/* Karten */
.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

/* Formulare */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; color: var(--ink); background: #fff; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus {
  border-color: var(--ssmc-400);
  box-shadow: 0 0 0 3px rgba(55,138,221,.15);
}
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }

/* Checkbox-Label */
label.check {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  font-size: 14px; color: var(--ink); margin: 0;
}
label.check input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--ssmc-600); cursor: pointer; flex-shrink: 0;
}
.insurance-toggle {
  background: var(--ssmc-50); border: 1px solid var(--ssmc-100);
  border-radius: var(--radius); padding: 10px 14px; max-width: max-content;
}
.insurance-toggle label.check span { color: var(--ssmc-800); font-weight: 600; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  height: 40px; padding: 0 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  background: #fff; color: var(--ink); text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--ssmc-600); color: #fff; }
.btn-primary:hover { background: var(--ssmc-800); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ssmc-800); }
.btn-ghost:hover { border-color: var(--ssmc-400); }
.btn-danger { background: var(--error-bg); color: var(--error-fg); border-color: #f3caca; }
.btn-danger:hover { background: #f7dede; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

.iconbtn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer;
  color: var(--muted); font-size: 16px;
}
.iconbtn:hover { border-color: var(--ssmc-400); color: var(--ssmc-600); text-decoration: none; }
.iconbtn.danger:hover { border-color: #f0999a; color: var(--error-fg); }

/* Tabellen */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table .amount { font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block; font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600;
  background: var(--ssmc-50); color: var(--ssmc-800);
}
.pill-admin { background: var(--amber-bg); color: var(--amber-fg); }

/* Flash / Hinweise */
.flash { padding: 11px 15px; border-radius: var(--radius); font-size: 14px; margin-bottom: 18px; }
.flash-success { background: var(--success-bg); color: var(--success-fg); }
.flash-error   { background: var(--error-bg);   color: var(--error-fg); }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }

/* ---------- Generator ---------- */
.reasons-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px;
}
.reason-chip {
  position: relative; text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: #fff; border-radius: var(--radius);
  padding: 11px 13px; display: flex; flex-direction: column; gap: 3px;
  transition: border-color .12s, background .12s;
}
.reason-chip:hover { border-color: var(--ssmc-400); }
.reason-chip.on { background: var(--ssmc-50); border-color: var(--ssmc-600); }
.reason-chip .r-name { font-weight: 600; font-size: 14px; color: var(--ink); }
.reason-chip .r-price { font-size: 12px; font-weight: 600; color: var(--ssmc-600); }
.reason-chip .r-alt { font-size: 11px; color: var(--muted); }
.reason-chip .r-num {
  position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ssmc-600); color: #fff; font-size: 11px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.reason-chip.on .r-num { display: flex; }

.sumcard {
  background: #fff; border: 1px solid var(--ssmc-100); border-radius: 12px; overflow: hidden;
}
.sumcard-head {
  background: var(--ssmc-50); padding: 8px 14px; font-size: 11px;
  letter-spacing: .03em; color: var(--ssmc-800); text-transform: uppercase;
}
.sumrow {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  font-size: 14px; border-top: 1px solid var(--line);
}
.sumrow:first-of-type { border-top: 0; }
.sumrow .s-name { flex: 1; }
.sumrow .s-val  { min-width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.sumrow.empty-row { color: var(--muted); }

.qty { display: flex; align-items: center; gap: 6px; }
.qty button {
  width: 26px; height: 26px; border: 1px solid var(--line); background: #fff;
  border-radius: 7px; cursor: pointer; color: var(--ssmc-600); font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.qty button:hover { border-color: var(--ssmc-400); }
.qty span { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; }

.sumtotal {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px; background: var(--ssmc-600);
}
.sumtotal .t-label { color: var(--ssmc-50); font-size: 13px; }
.sumtotal .t-val { color: #fff; font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }

.output {
  background: var(--ssmc-900); color: var(--ssmc-50); border-radius: var(--radius);
  padding: 15px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; cursor: pointer; display: flex; align-items: center; gap: 10px;
  justify-content: space-between; line-height: 1.5; word-break: break-word;
}
.output:hover { background: var(--ssmc-800); }
.output .copy-ico { flex-shrink: 0; font-size: 18px; }
.copied-note { font-size: 12px; color: var(--success-fg); margin-top: 7px; opacity: 0; transition: opacity .2s; }
.copied-note.show { opacity: 1; }

/* Login */
.login-head { text-align: center; margin-bottom: 20px; }
.login-head .brand-tile { margin: 0 auto 10px; }
.login-head h1 { font-size: 17px; margin: 0; }
.login-head p { font-size: 13px; color: var(--muted); margin: 4px 0 0; }

footer.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 22px 0 8px; }

/* Toggle-Schalter (Krankenversicherung) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; height: 40px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 42px; height: 24px; border-radius: 20px; background: #cdd6e2;
  position: relative; flex-shrink: 0; transition: background .15s;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--ssmc-600); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(55,138,221,.25); }
.switch-label { font-size: 14px; color: var(--ink); }

/* Rechnungsgrund-Auswahl als Tabelle (Generator) */
.table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.reason-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.reason-table thead th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 9px 14px; border-bottom: 1px solid var(--line); background: #fafcff;
}
.reason-table th.rt-amt, .reason-table td.rt-amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reason-table th.rt-sel, .reason-table td.rt-sel { width: 34px; text-align: center; }
.reason-table tbody tr { cursor: pointer; transition: background .12s; }
.reason-table tbody tr + tr td { border-top: 1px solid var(--line); }
.reason-table tbody td { padding: 11px 14px; }
.reason-table tbody tr:hover { background: #f2f7fd; }
.reason-table tbody tr.on { background: var(--ssmc-50); }
.reason-table tbody tr.on td { box-shadow: inset 2px 0 0 var(--ssmc-600); }
.reason-table .rr-name { font-weight: 600; }
.reason-table .rr-num {
  display: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ssmc-600); color: #fff; font-size: 11px; font-weight: 700;
  line-height: 20px; text-align: center; margin: 0 auto;
}
.reason-table tbody tr.on .rr-num { display: block; }
/* Aktive Betragsspalte je nach KV-Schalter betonen */
.reason-table .rr-ins { color: var(--muted); }
.reason-table.ins-on .rr-ins { color: var(--ssmc-800); font-weight: 600; }
.reason-table.ins-on .rr-amt { color: var(--muted); }

/* Ein-/ausklappbare Gruppen (Generator) */
.reason-group { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 10px; }
.reason-group .group-head {
  width: 100%; display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 11px 14px; background: var(--ssmc-50); border: 0; text-align: left;
  font-size: 14px; font-weight: 600; color: var(--ssmc-900);
}
.reason-group .group-head:hover { background: #dcebfb; }
.reason-group .group-chevron { color: var(--ssmc-600); transition: transform .15s; font-size: 12px; }
.reason-group.collapsed .group-chevron { transform: rotate(-90deg); }
.reason-group .group-name { flex: 1; }
.reason-group .group-count {
  font-size: 11px; font-weight: 700; color: var(--ssmc-800);
  background: #fff; border: 1px solid var(--ssmc-100); border-radius: 20px; padding: 1px 9px;
}
.reason-group .group-body { border-top: 1px solid var(--line); }
.reason-group.collapsed .group-body { display: none; }
.reason-group .table-wrap { border: 0; border-radius: 0; }
.reason-group .reason-table tbody tr:first-child td { border-top: 0; }

/* Gruppen-Sektionen im Backend */
.grp { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.grp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: var(--ssmc-50); border-bottom: 1px solid var(--line);
}
.grp-title { font-weight: 600; font-size: 14px; color: var(--ssmc-900); display: flex; align-items: center; gap: 8px; }
.grp-count {
  font-size: 11px; font-weight: 700; color: var(--ssmc-800);
  background: #fff; border: 1px solid var(--ssmc-100); border-radius: 20px; padding: 1px 9px;
}
.grp-actions { display: flex; align-items: center; gap: 4px; }
.grp .table { }
.grp .table thead th { background: #fafcff; }

/* kleine Sortier-Buttons */
.iconbtn-xs { width: 28px; height: 28px; font-size: 12px; }
.iconbtn:disabled { opacity: .35; cursor: default; }
.iconbtn:disabled:hover { border-color: var(--line); color: var(--muted); }
