/* ── Variablen ─────────────────────────────────────────────────── */
:root {
  --primary:      #e05a5a;
  --primary-dark: #c44444;
  --bg:           #f5f6fa;
  --surface:      #ffffff;
  --border:       #e2e6ea;
  --text:         #2d3748;
  --text-muted:   #718096;
  --success:      #38a169;
  --error:        #e53e3e;
  --info:         #3182ce;
  --radius:       10px;
  --shadow:       0 2px 12px rgba(0,0,0,.08);
  --input-h:      48px;    /* Touch-freundliche Mindesthöhe */
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;   /* Verhindert iOS-Zoom bei Focus */
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, select, button { font: inherit; }

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}
.topbar-brand { display: flex; align-items: center; }
.brand-link { display: flex; align-items: center; gap: .45rem; text-decoration: none !important; }
.brand-icon  { font-size: 1.35rem; }
.brand-name  { font-weight: 800; font-size: 1.15rem; color: var(--primary); }
.topbar-nav  { display: flex; align-items: center; gap: .75rem; }
.topbar-link { color: var(--text-muted); font-size: .9rem; font-weight: 500; }
.topbar-link:hover { color: var(--primary); text-decoration: none; }

/* Mobile Menu */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: .25rem .5rem;
  color: var(--text);
}
.mobile-menu {
  display: none;
  position: absolute;
  top: 56px;
  right: 0;
  left: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-direction: column;
  z-index: 199;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
  display: block;
  padding: 1rem 1.5rem;
  color: var(--text);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.mobile-menu a:hover { background: var(--bg); }

/* ── Container ─────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

/* ── Page Header ───────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.page-header h2, .page-header h3 {
  font-size: 1.3rem;
  font-weight: 700;
}

/* ── Alerts ────────────────────────────────────────────────────── */
.alert {
  padding: .85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .93rem;
  font-weight: 500;
}
.alert-success { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
.alert-error   { background: #fff5f5; color: #9b2c2c; border: 1px solid #feb2b2; }
.alert-info    { background: #ebf8ff; color: #2a4a6b; border: 1px solid #bee3f8; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.15rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: .92rem;
  font-weight: 600;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none !important;
  white-space: nowrap;
  min-height: 44px;  /* Touch-Target */
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost    { background: transparent; color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-outline-primary { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline-primary:hover { background: #fff0f0; }
.btn-danger   { background: transparent; color: var(--error); border: 1.5px solid #fecaca; }
.btn-danger:hover { background: #fff5f5; }
.btn-sm { min-height: 36px; padding: .3rem .8rem; font-size: .84rem; }
.btn-full { width: 100%; }

/* ── Profil-Karte (Dashboard) ──────────────────────────────────── */
.profile-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.profile-card-info { display: flex; align-items: center; gap: 1rem; }
.profile-avatar {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--primary), #f08080);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.profile-name    { font-weight: 700; font-size: 1.05rem; }
.profile-meta    { color: var(--text-muted); font-size: .86rem; margin-top: .1rem; }
.profile-comments { color: var(--text-muted); font-size: .82rem; margin-top: .3rem; font-style: italic; max-width: 500px; }
.profile-card-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ── Auth-Seiten ───────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(135deg, #ffd6d6 0%, #fff0f0 50%, #f5f6fa 100%);
}
.auth-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  padding: 2.25rem 1.75rem;
  width: 100%;
  max-width: 420px;
}
.auth-logo     { font-size: 2.4rem; text-align: center; margin-bottom: .4rem; }
.auth-title    { text-align: center; font-size: 1.55rem; font-weight: 800; color: var(--primary); }
.auth-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; font-size: .92rem; }
.auth-links    { text-align: center; margin-top: 1.2rem; font-size: .88rem; color: var(--text-muted); }
.auth-links a  { color: var(--primary); font-weight: 600; }
.separator     { margin: 0 .4rem; }

/* ── Formulare ─────────────────────────────────────────────────── */
.auth-form   { display: flex; flex-direction: column; gap: .9rem; }
.form-group  { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-weight: 600; font-size: .9rem; }
.form-group small { color: var(--text-muted); font-weight: 400; font-size: .82rem; }
.form-group input,
.form-group textarea,
.form-group select {
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
  font-size: 16px;    /* iOS zoom prevention */
  min-height: var(--input-h);
}
.form-group textarea { min-height: auto; }
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(224,90,90,.14);
  background: #fff;
}
.form-group input[disabled] {
  opacity: .6;
  cursor: not-allowed;
}

/* Grid-Layouts für Formular-Zeilen */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* Form-Karte */
.form-card     { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.vital-form    { display: flex; flex-direction: column; gap: .25rem; }
.form-section  { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: none; }
.form-section-title { font-size: .9rem; font-weight: 700; margin-bottom: .85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.form-actions  { display: flex; justify-content: flex-end; gap: .75rem; padding-top: 1rem; flex-wrap: wrap; }

/* Wellbeing-Picker */
.wellbeing-picker {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.wellbeing-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  cursor: pointer;
  padding: .7rem .9rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  transition: border-color .15s, background .15s;
  background: var(--bg);
  min-width: 74px;
  flex: 1;
  max-width: 100px;
  -webkit-tap-highlight-color: transparent;
}
.wellbeing-option:has(input:checked) {
  border-color: var(--primary);
  background: #fff0f0;
}
.wellbeing-option input { display: none; }
.wellbeing-emoji  { font-size: 1.9rem; line-height: 1; }
.wellbeing-label  { font-size: .75rem; color: var(--text-muted); font-weight: 600; }

/* ── Tabellen ──────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.vitals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  min-width: 640px;
}
.vitals-table th {
  background: #f8f9fb;
  text-align: left;
  padding: .75rem .9rem;
  font-size: .76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.vitals-table td {
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.vitals-table tr:last-child td { border-bottom: none; }
.vitals-table tr:hover td { background: #fafbfc; }
.val        { font-weight: 600; font-variant-numeric: tabular-nums; }
.emoji      { font-size: 1.15rem; text-align: center; }
.nowrap     { white-space: nowrap; color: var(--text-muted); font-size: .86rem; }
.notes-col  { min-width: 140px; }
.delta       { color: var(--text-muted); font-size: .84rem; white-space: nowrap; }
.delta-warn  { font-weight: 700; color: var(--text); }
.delta-alert { font-weight: 700; color: #dc3545; }
.notes-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: .84rem; }
.notes-cell [data-tip] { position: relative; cursor: default; }
.notes-cell:has([data-tip]:hover) { overflow: visible; z-index: 100; }
.notes-cell [data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 180px;
  max-width: 320px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #2d3748;
  color: #fff;
  font-size: .82rem;
  line-height: 1.45;
  padding: .45rem .6rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 999;
}
.notes-cell [data-tip]:hover::after { opacity: 1; }
.actions    { white-space: nowrap; display: flex; gap: .35rem; align-items: center; }
.actions form { display: inline; }

/* ── Leerzustand ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty-icon { font-size: 2.8rem; margin-bottom: .9rem; }
.empty-state p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-admin { background: #fff0f0; color: var(--primary); }
.badge-user  { background: #ebf8ff; color: var(--info); }

/* ── Export-Panel ──────────────────────────────────────────────── */
.export-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin: 1.25rem 0;
}
.export-panel h3 { font-size: .95rem; font-weight: 700; margin-bottom: .85rem; color: var(--text-muted); }
.export-buttons { display: flex; flex-wrap: wrap; gap: .6rem; }

/* ── Collapsible ───────────────────────────────────────────────── */
.collapsible { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 1rem; }
.collapsible-title { cursor: pointer; padding: 1rem 1.25rem; font-weight: 700; font-size: .95rem; list-style: none; user-select: none; }
.collapsible-title::-webkit-details-marker { display: none; }
.collapsible-title::before { content: "▶ "; font-size: .7rem; margin-right: .3rem; color: var(--text-muted); }
details[open] .collapsible-title::before { content: "▼ "; }
.collapsible > .form-card { border-radius: 0; box-shadow: none; border-top: 1px solid var(--border); }

/* ── Admin-Kontext-Bar ─────────────────────────────────────────── */
.admin-context-bar {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: .6rem 1rem;
  font-size: .88rem;
  margin-bottom: 1rem;
  color: #92400e;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar-nav  { display: none; }
  .mobile-menu-btn { display: block; }

  .form-row-2 { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }

  .profile-card { flex-direction: column; }
  .profile-card-actions { width: 100%; }

  .auth-card { padding: 1.75rem 1.25rem; }
  .container { padding: 0 .75rem; }

  .export-buttons { flex-direction: column; }
  .export-buttons .btn { width: 100%; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }

  .wellbeing-picker { gap: .3rem; }
  .wellbeing-option { padding: .6rem .4rem; min-width: 60px; }
  .wellbeing-emoji { font-size: 1.6rem; }
}

@media (max-width: 400px) {
  .form-row-3 { grid-template-columns: 1fr; }
  .vitals-table { min-width: 560px; }
}

/* ── Triple-Messungen ──────────────────────────────────────────── */
.triple-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: .75rem;
}
.triple-grid-pulse {
  /* Pulse-Felder etwas schmaler */
}
.triple-col {
  background: var(--bg);
  border-radius: 8px;
  padding: .75rem;
  border: 1.5px solid var(--border);
}
.triple-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .5rem;
}
.triple-label small {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.form-row-bp {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.form-row-bp .form-group label {
  font-size: .8rem;
}
.form-row-bp input {
  min-height: 42px;
}

/* Mittelwert-Anzeige */
.avg-display {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: #fff8f0;
  border: 1.5px solid #fcd34d;
  border-radius: 8px;
  padding: .6rem 1rem;
  margin-top: .5rem;
}
.avg-label {
  font-size: .85rem;
  font-weight: 600;
  color: #92400e;
}
.avg-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: #92400e;
}

/* Responsive: Triple-Grid auf Mobile */
@media (max-width: 640px) {
  .triple-grid {
    grid-template-columns: 1fr;
    gap: .6rem;
  }
  .triple-col {
    padding: .6rem;
  }
}

/* ── Sequentielle Messreihen ───────────────────────────────────── */
.measure-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: .75rem;
  align-items: start;
  padding: .6rem 0;
  border-bottom: 1px dashed var(--border);
}
.measure-row:last-of-type { border-bottom: none; }
.measure-optional { opacity: .85; }
.measure-badge {
  background: var(--primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  border-radius: 8px;
  padding: .4rem .6rem;
  text-align: center;
  line-height: 1.3;
  margin-top: 1.5rem;
}
.measure-optional .measure-badge {
  background: #aab;
}
.measure-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .75rem;
}

/* Kombinierte Mittelwert-Box */
.avg-display {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: #fff8f0;
  border: 1.5px solid #fcd34d;
  border-radius: 8px;
  padding: .65rem 1.1rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.avg-item   { display: flex; align-items: center; gap: .5rem; }
.avg-sep    { color: #ccc; font-size: 1.2rem; }
.avg-label  { font-size: .83rem; font-weight: 600; color: #92400e; }
.avg-value  { font-size: 1.05rem; font-weight: 800; color: #92400e; }

@media (max-width: 600px) {
  .measure-row    { grid-template-columns: 1fr; }
  .measure-badge  { display: inline-block; margin-top: 0; margin-bottom: .4rem; }
  .measure-fields { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 380px) {
  .measure-fields { grid-template-columns: 1fr 1fr; }
}

/* ── Ampel-Werte ───────────────────────────────────────────────── */
.val-high     { color: #c0392b !important; font-weight: 700; }
.val-critical { color: #922b21 !important; font-weight: 700; background: #fdf2f2; border-radius: 4px; padding: 1px 4px; }
.val-low      { color: #1a5276 !important; font-weight: 700; }

/* ── Dashboard Diagramme ───────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: .5rem;
}
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem .75rem;
}
.chart-title {
  font-size: .88rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: .5rem;
}
.chart-unit { font-weight: 400; font-size: .8rem; }
.chart-card canvas {
  width: 100% !important;
  height: 220px !important;
  display: block;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .75rem;
  margin-top: .5rem;
}
.chart-stats {
  width: 100%;
  margin-top: .4rem;
  padding-top: .35rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .9rem;
}
.chart-stat {
  font-size: .75rem;
  color: var(--text-muted);
}
.chart-stat-label {
  font-weight: 600;
  color: var(--text);
}
.chart-legend-item {
  font-size: .78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .25rem;
}

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

.notes-toolbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: .35rem;
}
.notes-correct-msg {
  font-size: .82rem;
  color: var(--text-muted);
}
.notes-correct-msg.ok  { color: #2e8b57; }
.notes-correct-msg.err { color: #dc3545; }
