/*

 */

/* Grundfarben und Maße an einer Stelle. Keine externen Fonts: Systemschrift. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d9dde3;
  --text: #1d2430;
  --muted: #5f6b7a;
  --accent: #1f5f8b;
  --accent-hover: #174a6d;
  --accent-soft: #e6eff6;
  --danger: #a3261b;
  --danger-soft: #fbeceb;
  --success: #24663b;
  --success-soft: #e8f4ec;
  --warning-soft: #fff6dd;
  --warning-border: #e8cf86;
  --radius: 6px;
  --sidebar-width: 200px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; font-weight: 600; }

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

/* Kopfzeile */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 48px;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.prototype-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-name { font-weight: 600; }
.user-role { color: var(--muted); font-size: 0.9rem; }
.topbar-user form { margin: 0; }

/* Grundgerüst: Navigation links, Inhalt rechts */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - 48px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.nav-link:hover { background: var(--bg); }

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.content {
  padding: 1.5rem 2rem;
  max-width: 1400px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Meldungen */
.flash {
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.flash-notice { background: var(--success-soft); border-color: #b9dcc4; color: var(--success); }
.flash-alert { background: var(--danger-soft); border-color: #efc4c0; color: var(--danger); }

.placeholder-notice {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px dashed var(--warning-border);
}

.item-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0;
  list-style: none;
  max-width: 480px;
}

.item-list li { padding: 0.4rem 1rem; }

/* Buttons */
.btn {
  display: inline-block;
  font: inherit;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--bg); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-quiet { border-color: transparent; color: var(--muted); }

/* Formulare */
.form-stack { display: grid; gap: 1rem; }

.field { display: grid; gap: 0.3rem; }

.field label { font-weight: 600; font-size: 0.9rem; }

.field input,
.field select,
.field textarea {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Anmeldeseite */
body.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-card .btn-primary { width: 100%; }

.btn-small { padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.btn-danger { color: var(--danger); border-color: #efc4c0; }
.btn-danger:hover { background: var(--danger-soft); }

.actions { display: flex; gap: 0.5rem; align-items: center; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Suche über der Patientenliste */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-bar input[type=search] {
  flex: 1;
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.search-bar select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 280px;
}

.list-meta { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.5rem; }
.empty-state { color: var(--muted); padding: 1rem 0; }

/* Kompakte Tabellen */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: #eef0f3;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.data-table tbody tr:hover { background: #f7f9fb; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
.data-table .actions-col { text-align: right; white-space: nowrap; width: 1%; }
.data-table td a { text-decoration: none; }
.data-table td a:hover { text-decoration: underline; }

.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { text-decoration: underline; }
.sort-link.is-sorted { color: var(--accent); }

/* Geöffneter Patient: Kopf und Reiter */
.patient-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.patient-header h1 { margin: 0; font-size: 1.35rem; }
.patient-meta { color: var(--muted); }
.patient-meta strong { color: var(--text); font-weight: 600; }

.patient-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.55rem 0.9rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

/* Stammdaten: Ansicht und Formular in Kacheln */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem 1rem;
  margin: 0;
  min-width: 0;
}

.panel h2,
.panel legend {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  padding: 0;
}

fieldset.panel legend { float: left; width: 100%; margin-bottom: 0.75rem; }
fieldset.panel legend + * { clear: both; }

.field-list {
  display: grid;
  grid-template-columns: minmax(150px, 40%) 1fr;
  gap: 0.3rem 0.75rem;
  margin: 0;
}

.field-list dt { color: var(--muted); font-size: 0.9rem; }
.field-list dd { margin: 0; white-space: pre-line; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-grid .span-2 { grid-column: span 2; }
.field input, .field select, .field textarea { width: 100%; }
.field-hint { color: var(--muted); font-size: 0.82rem; }

.form-hint {
  padding: 0.6rem 0.9rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-errors {
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid #efc4c0;
  color: var(--danger);
}

.form-errors p { margin: 0 0 0.3rem; font-weight: 600; }
.form-errors ul { margin: 0; padding-left: 1.2rem; }

.narrow { max-width: 560px; }

.family-note { white-space: pre-line; color: var(--muted); }

.demo-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Kartei */
.section-title { font-size: 1.15rem; margin: 0 0 0.75rem; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 0.75rem; }
.encounter-form .panel { max-width: 1000px; }

.search-bar.inline { flex: 1; margin: 0; }

.status-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 4px;
}

tr.is-cancelled td { color: var(--muted); }
tr.is-cancelled td a { color: var(--muted); text-decoration: line-through; }

.cancelled-notice {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid #efc4c0;
  color: var(--danger);
}

.notes { margin-top: 1rem; }
.note { padding: 0.6rem 0; border-top: 1px solid var(--border); }
.note:first-of-type { border-top: none; }
.note.is-cancelled .note-body { color: var(--muted); text-decoration: line-through; }
.note-meta { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.88rem; }
.note-body { white-space: pre-line; margin-top: 0.25rem; }
.note-form { display: grid; gap: 0.4rem; margin-top: 1rem; max-width: 800px; }
.note-form label { font-weight: 600; font-size: 0.9rem; }
.note-form textarea { font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); }
.note-form .btn { justify-self: start; }

.cancel-box { display: inline-block; position: relative; }
.cancel-box summary { list-style: none; }
.cancel-box summary::-webkit-details-marker { display: none; }
.cancel-box[open] .cancel-form {
  position: absolute;
  z-index: 10;
  top: 2.2rem;
  left: 0;
  display: grid;
  gap: 0.4rem;
  width: 340px;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
.cancel-form label { font-weight: 600; font-size: 0.85rem; }
.cancel-form input[type=text] { font: inherit; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

.audit-log { margin-top: 1rem; }
.audit-log summary { cursor: pointer; }
.audit-log summary h2 { display: inline; font-size: 1rem; }
.audit-log table { margin-top: 0.75rem; font-size: 0.88rem; }
.audit-before { color: var(--danger); white-space: pre-line; }
.audit-after { color: var(--success); white-space: pre-line; }

/* Fallblatt und Mittel */
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.sheet-grid textarea { width: 100%; font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); }
.sheet-tools { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.sheet-tools select { font: inherit; max-width: 100%; flex: 1; padding: 0.3rem; border: 1px solid var(--border); border-radius: var(--radius); }
.sheet-text { white-space: pre-line; }

.qa-rows { display: grid; gap: 0.5rem; }
.qa-row { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem; padding: 0.5rem; background: var(--bg); border-radius: var(--radius); }
.qa-row input, .qa-row textarea { font: inherit; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.qa-row textarea { grid-column: 1; }
.qa-row button { grid-row: 1; grid-column: 2; }

.qa-list { margin: 0; }
.qa-list dt { font-weight: 600; margin-top: 0.5rem; }
.qa-list dt:first-child { margin-top: 0; }
.qa-list dd { margin: 0.1rem 0 0; white-space: pre-line; }

.not-implemented { border-style: dashed; color: var(--muted); cursor: not-allowed; }

.checkbox { display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem; font-weight: 600; }
.label-spacer { display: block; height: 1.2rem; }

.status-open, .status-closed, .reserve-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  vertical-align: middle;
}
.status-open { color: #7a5600; background: var(--warning-soft); border: 1px solid var(--warning-border); }
.status-closed { color: var(--success); background: var(--success-soft); }
.reserve-badge { color: var(--accent); background: var(--accent-soft); }

.link-list { margin: 0 0 0.75rem; padding-left: 1.1rem; }
.link-list li { margin-bottom: 0.25rem; }
h2.spaced { margin-top: 1.25rem; }
#mittel { margin-top: 1rem; }

/* Liquidation */
.invoice-items input, .invoice-items select {
  width: 100%;
  font: inherit;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.invoice-items .input-short { max-width: 70px; }
.invoice-items .input-money { max-width: 100px; text-align: right; }
.invoice-items tfoot td { border-top: 2px solid var(--border); }
.amount { white-space: nowrap; }
.spaced-panel { margin-top: 1rem; }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); margin-bottom: 0.75rem; }
