:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #6a0dad; /* purple default */
  --danger: #dc2626;
  --shadow: 0 6px 20px rgba(0,0,0,.08);
}
.theme-pink { --accent: #ff69b4; }
.theme-blue { --accent: #1e90ff; }

/* Dark mode overrides */
.dark {
  --bg: #0b0f14;
  --surface: #0f1720;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --border: #1f2a37;
  --shadow: 0 6px 20px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji'; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); padding: 16px; position: sticky; top:0; height: 100vh; }
.sidebar .brand { font-weight: 800; margin-bottom: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 8px; }
.sidebar nav a { padding: 10px 12px; border-radius: 10px; color: var(--text); }
.sidebar nav a:hover { background: color-mix(in srgb, var(--accent), transparent 92%); }

.content { flex: 1; display:flex; flex-direction: column; overflow-x: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top:0; z-index: 10; }
.burger { display:none; font-size: 20px; background: transparent; border: none; }
.spacer { flex:1; }
.user-info form { display:inline; }

.main { padding: 16px; flex: 1 0 auto; overflow-x: hidden; max-width: 100vw; }
.footer { padding: 12px 16px; color: var(--muted); border-top: 1px solid var(--border); margin-top: auto; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
.header-actions { display:flex; align-items:center; gap: 12px; justify-content: space-between; }
.row { display:flex; gap: 12px; }
.form label { display:flex; flex-direction: column; gap:6px; margin-bottom: 10px; }
.form input, .form textarea, .form select { border:1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface); color: var(--text); }
.form input[type="text"], .form input[type="email"], .form input[type="password"], .form input[type="number"], .form input[type="date"], .form input[type="time"], .form select, .form textarea { width: 100%; max-width: 100%; }
.actions { display:flex; gap: 8px; flex-wrap: wrap; }
.btn { background: var(--accent); color: #fff; border: none; border-radius: 999px; padding: 8px 14px; box-shadow: var(--shadow); cursor: pointer; margin: 6px 0; }
.btn:hover { filter: brightness(1.05); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-danger { background: var(--danger); }
.btn-small { padding: 6px 10px; font-size: 90%; }
.muted { color: var(--muted); }
.list { list-style: none; padding-left: 0; display: flex; flex-direction: column; gap: 12px; }
.list li { display:flex; gap: 12px; justify-content: space-between; align-items:flex-start; padding-bottom: 12px; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.row-actions { display:flex; gap: 8px; margin-top: 8px; }
.table { width:100%; border-collapse: collapse; }
.table th, .table td { text-align:left; padding: 8px; border-bottom: 1px solid var(--border); }
.table td:last-child { white-space: nowrap; }
.table form { display:flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.table form input, .table form select { flex: 1 1 180px; min-width: 140px; }
/* Widen table cell inputs for readability */
.table td input[type="text"],
.table td input[type="number"],
.table td input[type="email"],
.table td input[type="password"],
.table td select {
  min-width: 180px;
}
@media (max-width: 480px) {
  .table td input[type="text"],
  .table td input[type="number"],
  .table td select {
    min-width: 220px; /* ensure a few words fit before wrapping */
  }
}

/* Lab values specific tweaks */
.lab-values td input[type="text"] { min-width: 200px; }
.lab-values td:nth-child(4) input[type="text"] { min-width: 260px; } /* Referenz */
.lab-values td:nth-child(5) select { min-width: 140px; }
.alert { padding:10px 12px; border-radius: 10px; margin-bottom: 10px; }
.alert-error { background: #fee2e2; color: #991b1b; border:1px solid #fecaca; }
.badge { font-size: 12px; line-height: 1.6; display: inline-block; }

/* Page description helper */
.page-desc { font-size: 0.95rem; color: var(--muted); margin: 8px 0 16px; }

/* Filters layout */
.filters { display:flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { margin: 0; }

/* Chips */
[data-tags-input] { display:flex; gap:8px; flex-wrap: wrap; align-items: center; padding: 8px; border:1px dashed var(--border); border-radius: 12px; }
.chip { display:inline-flex; align-items:center; gap:6px; background: color-mix(in srgb, var(--accent), transparent 92%); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent), transparent 80%); padding: 4px 10px; border-radius: 999px; }
.chip .chip-close { appearance:none; border:none; background:transparent; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.chip-input { border:none; outline:none; padding: 6px 8px; min-width: 160px; }

/* Symptom picker */
[data-symptom-picker] .symptom-list { display:flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.symptom-row { display:grid; grid-template-columns: auto 1fr 160px 28px auto; align-items:center; gap: 8px; padding: 6px 8px; border:1px solid var(--border); border-radius: 10px; background: var(--surface); }
.symptom-row input[type="range"] { width: 100%; }
.symptom-row > span.sev-val { text-align: center; font-variant-numeric: tabular-nums; }
/* The first span in the row is the symptom name */
.symptom-row > span:first-of-type { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.symptom-add { display:flex; gap: 8px; }
/* Make symptom picker horizontally scrollable on small screens */
.symptom-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-x; overscroll-behavior-x: contain; scrollbar-gutter: stable both-edges; }
[data-symptom-picker] { display: block; width: max-content; min-width: 100%; }
[data-symptom-picker] .symptom-list { width: max-content; }
@media (max-width: 600px) {
  /* Fix a stable min-width so the Entfernen-Button is reachable via horizontal scroll */
  .symptom-row { grid-template-columns: auto 160px 180px 28px auto; min-width: 620px; }
}

/* Explicit scroll wrapper for symptom picker (reinforced above) */
fieldset.card { overflow: visible; }
.symptom-scroll { padding-bottom: 8px; }
.symptom-scroll::after { content: ''; display:block; height: 10px; width: 24px; background: transparent; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s ease; }
  .sidebar.open { left: 0; }
  .burger { display:block; }
  .main { padding-bottom: 80px; }
  /* Ensure sidebar overlays topbar when open */
  .sidebar { z-index: 30; }
  .topbar { z-index: 20; }
}

/* Collapsible journal content */
.journal-content { margin-top: 6px; }
.journal-content summary { cursor: pointer; list-style: none; }
.journal-content summary::-webkit-details-marker { display: none; }
.journal-content summary::before { content: '▸'; display: inline-block; margin-right: 6px; transition: transform .15s ease; }
.journal-content[open] summary::before { transform: rotate(90deg); }
.journal-content .content-body { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Header actions layout improvements */
.header-actions { gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.header-actions .head { min-width: 220px; }
.header-actions .actions { display:flex; gap:8px; align-items:center; flex-wrap: wrap; }

/* Forms responsive rows */
.form .row { flex-wrap: wrap; }
.form .row > label { flex: 1 1 280px; min-width: 220px; }
@media (max-width: 600px) {
  .form .row > label { flex-basis: 100%; }
}

/* Tables responsiveness */
.table-responsive { width: 100%; overflow-x: auto; }

/* Mobile bottom navigation */
.mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; height: 56px; background: var(--surface); border-top: 1px solid var(--border); display:none; z-index: 50; }
.mobile-nav .nav-inner { display:flex; height:100%; align-items:center; justify-content: space-around; }
.mobile-nav a, .mobile-nav button { background: transparent; border: none; color: var(--text); padding: 6px 8px; border-radius: 10px; }
.mobile-nav a.active { color: var(--accent); }
@media (max-width: 900px) {
  .mobile-nav { display:block; }
}
