/* ============================================================
   M18 — Apothecary Ledger
   Self-hosted variable fonts. font-display: swap so first paint
   isn't blocked; Georgia is a close metric fallback for both.
   ============================================================ */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/fraunces-var.woff2") format("woff2-variations"),
       url("/static/fonts/fraunces-var.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/fraunces-var-italic.woff2") format("woff2-variations"),
       url("/static/fonts/fraunces-var-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/static/fonts/source-serif-4-var.woff2") format("woff2-variations"),
       url("/static/fonts/source-serif-4-var.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("/static/fonts/source-serif-4-var-italic.woff2") format("woff2-variations"),
       url("/static/fonts/source-serif-4-var-italic.woff2") format("woff2");
}

:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --ink: #1c1c1c;
  --ink-muted: #6b6b6b;
  --ink-weak: #8a847b;
  --accent: #1f4d6b;
  --accent-hover: #163a52;
  --accent-soft: #e7eef3;
  --accent-deep: #143348;
  --error: #b53b3b;
  --info: #2c6e49;
  --warn: #b8860b;
  --border: #d8d3cb;
  --paper-rule: #ebe4d6;
  --brass: #b08a4a;
  --brass-soft: #efe4cd;
  --shadow-sm: 0 1px 2px rgba(28,28,28,0.06), 0 4px 12px rgba(28,28,28,0.04);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;

  --radius: 10px;
  --gap: 0.75rem;
  --pad: 1rem;
  --field-h: 2.6rem;
}

/* Density modes — defaulted to comfortable in app/__init__.py.
   Compact tightens on phones (long days = lots of scrolling);
   spacious gives desktop reading more room.                    */
body[data-density="compact"] {
  --gap: 0.55rem;
  --pad: 0.75rem;
  --field-h: 2.3rem;
}
body[data-density="comfortable"] {
  --gap: 0.75rem;
  --pad: 1rem;
  --field-h: 2.6rem;
}
body[data-density="spacious"] {
  --gap: 1rem;
  --pad: 1.25rem;
  --field-h: 2.9rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, .brand, .day-title, .day-header h1 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.55rem; font-weight: 500; margin: 0 0 0.5rem; }
h2 {
  font-size: 1.1rem; font-weight: 500;
  margin: 0; color: var(--accent); display: inline;
}
h3.sub {
  font-size: 0.92rem;
  font-weight: 600;
  font-family: var(--font-body);   /* sub-headings stay in body face */
  color: var(--ink-muted);
  margin: 0.75rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Brass focus ring for keyboard users — replaces browser default.
   Covers the keyboard-only case via :focus-visible so mouse clicks
   on chips/buttons stay clean.                                    */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 4px;
}

/* topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { color: #fff; font-weight: 600; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topbar-nav { display: flex; align-items: center; gap: 0.75rem; }
.topbar-nav a { color: #fff; font-size: 0.95rem; }
.inline-form { display: inline; margin: 0; }
.link-btn {
  background: none; border: none; color: inherit; cursor: pointer;
  padding: 0; font: inherit; text-decoration: underline;
}

/* container */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: 6rem;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

/* day header */
.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.day-header h1 { font-size: 1.15rem; margin: 0; }
.day-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* day-nav: prev / today / next + date picker + Gestern duplizieren */
.day-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.day-nav-arrow,
.day-nav-today {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}
.day-nav-arrow:hover,
.day-nav-today:not(.is-today):hover {
  background: var(--accent-soft);
  text-decoration: none;
}
.day-nav-today {
  font-weight: 600;
  color: var(--accent);
}
.day-nav-today.is-today {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: default;
}
.day-nav-label {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.day-nav .date-jump { margin-left: auto; }
.day-nav-duplicate { font-size: 0.9rem; padding: 0.4rem 0.7rem; }
@media (max-width: 480px) {
  .day-nav-label { display: none; }
  .day-nav { gap: 0.3rem 0.4rem; }
}

/* card / section */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: var(--gap);
}
details.section { padding: 0; }
details.section > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--accent);
  font-size: 0.85em;
}
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > *:not(summary) {
  padding: 0 1rem 1rem 1rem;
}

/* fields */
label { display: block; font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }

@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

input[type="text"], input[type="password"], input[type="number"],
input[type="time"], input[type="date"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
textarea { resize: vertical; min-height: 4.5rem; }

button, input[type="submit"], a.secondary, a.primary {
  display: inline-block;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.95rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
button:hover, input[type="submit"]:hover { background: var(--accent-hover); }
button.secondary, .secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
}
button.secondary:hover, .secondary:hover { background: var(--accent-soft); text-decoration: none; }

.hint { color: var(--ink-muted); font-size: 0.9rem; margin: 0 0 0.75rem; }
.small { font-size: 0.82rem; color: var(--ink-muted); font-weight: normal; }
.actions {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  margin-top: 1rem;
}

/* segmented buttons (replaces sliders for 1-5/1-7 scales) */
.scale-grid { display: flex; flex-direction: column; gap: 0.85rem; }
.scale-row {
  display: grid;
  grid-template-columns: minmax(6.5rem, 30%) 1fr;
  gap: 0.6rem;
  align-items: center;
}
.scale-row > label { margin: 0; font-weight: 500; }
@media (max-width: 480px) {
  .scale-row { grid-template-columns: 1fr; gap: 0.3rem; }
}

.segmented {
  display: flex;
  gap: 0.25rem;
  align-items: stretch;
}
.segmented .seg-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  padding: 0 0.4rem;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.08s linear, transform 0.05s linear;
}
.segmented .seg-btn:hover { background: var(--accent-soft); }
.segmented .seg-btn:active { transform: scale(0.97); }
.segmented .seg-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.segmented .seg-clear {
  flex: 0 0 auto;
  width: 36px; height: 48px;
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0;
}
.segmented .seg-clear:hover { background: #f1ede5; color: var(--error); }
.segmented .seg-clear.hidden { display: none; }

.scale-caption {
  display: flex;
  justify-content: space-between;
  margin-top: 0.25rem;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

/* chip rows (preset values + andere…) */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.chip-row .chip {
  height: 40px;
  padding: 0 0.7rem;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip-row .chip:hover { background: var(--accent-soft); }
.chip-row .chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.chip-row .chip-unit {
  margin-left: 0.15rem; font-weight: 400; opacity: 0.8;
}
.chip-row .chip-other {
  font-style: italic;
  color: var(--accent);
}
.chip-row .chip-other.active {
  color: #fff;
  background: var(--accent);
  font-style: normal;
}
.chip-row .chip-other-input {
  width: 6.5rem;
  height: 40px;
  padding: 0 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: #fff;
}
.chip-row .chip-other-input.hidden { display: none; }

/* Hide native number-input spin buttons. We provide our own chip UI; the
   bare number inputs that remain (vitals, room temp/humidity) feel cleaner
   without arrows on mobile. inputmode='decimal' triggers the numeric pad. */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* picker (selected rows + autocomplete input) */
.picker { display: block; }
.picker-rows {
  display: flex; flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.picker-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  column-gap: 0.5rem;
  row-gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfaf7;
}
.picker-row.flash-already {
  animation: pickerFlash 0.7s ease-out;
}
@keyframes pickerFlash {
  0% { background: #fff7d6; }
  100% { background: #fbfaf7; }
}
.picker-label {
  font-weight: 600;
  align-self: center;
}
.picker-controls {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.7rem;
  align-items: end;
}
.picker-control {
  display: flex; flex-direction: column; gap: 0.15rem;
  font-weight: normal; margin: 0;
}
.picker-control > .small {
  color: var(--ink-muted);
  font-size: 0.8rem;
}
.picker-control input[type="number"] { width: 6rem; }
.picker-control select { width: 7.5rem; }
.picker-severity {
  flex: 1 1 100%;          /* segmented severity always claims its own row */
  min-width: 0;
}
.picker-severity .segmented { width: 100%; }
.picker-side {
  flex: 0 0 auto;
}
.picker-side .segmented .seg-btn {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 40px;
  padding: 0;
}
.picker-remove {
  color: var(--error);
  font-size: 1.15rem;
  padding: 0 0.3rem;
  grid-row: 1;
  grid-column: 2;
  align-self: start;
}
@media (max-width: 480px) {
  .picker-control { flex: 1 1 100%; }
  .picker-control input[type="number"],
  .picker-control select { width: 100%; }
  .picker-side { flex: 0 0 auto; }
}

.picker-search {
  position: relative;
}
.picker-input {
  width: 100%;
}
.picker-input.error {
  border-color: var(--error);
  background: #fbeaea;
}
.picker-suggestions {
  list-style: none;
  margin: 0;
  padding: 0.2rem 0;
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  max-height: 14rem;
  overflow-y: auto;
}
.picker-suggestion {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.picker-suggestion.active,
.picker-suggestion:hover {
  background: var(--accent-soft);
}
.picker-suggestion.synthetic {
  color: var(--accent);
  font-style: italic;
  border-top: 1px dashed var(--border);
}
.picker-suggestion.synthetic::before {
  content: "+ ";
  font-style: normal;
  font-weight: 600;
}
.picker-meta { color: var(--ink-muted); font-size: 0.8rem; }

/* chip-toggle (multi-select chip list — digestion_complaint, travel_mode, …) */
.chip-toggle-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column;
  gap: 0.4rem;
}
.chip-toggle-row {
  display: flex; flex-direction: column;
  gap: 0.35rem;
  padding: 0.35rem 0;
}
.chip-toggle-btn {
  align-self: flex-start;
  padding: 0.45rem 0.95rem;
  height: 40px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.chip-toggle-detail {
  padding-left: 0.4rem;
}
.chip-toggle-detail.hidden { display: none; }

.chip-add-inline {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.5rem;
}
.chip-add-inline .chip-add-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.chip-add-inline .chip-add-input.error {
  border-color: #c33;
  background: #fee;
}
.chip-add-btn { white-space: nowrap; }

.past-desc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  margin: 0.3rem 0;
}
.past-desc-row .small { color: var(--muted, #666); }
.past-desc-chip {
  font-size: 0.85em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-toggle-row.flash-already {
  animation: flash-already 0.7s ease-out;
}
@keyframes flash-already {
  0%   { background: #fff7c2; }
  100% { background: transparent; }
}

/* sub-card (e.g. Muskelkater inside Sport, each acute_med) */
.sub-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin-top: 0.6rem;
  background: #fbfaf7;
}
.sub-card h3.sub { margin-top: 0; }

/* acute med block */
.acute-med-list { display: flex; flex-direction: column; gap: 0.6rem; }
.med-block.med-warn { border-color: var(--warn); background: #fff8e6; }
.med-block.med-cap  { border-color: var(--error); background: #fbeaea; }
.med-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.med-total { font-variant-numeric: tabular-nums; }
.med-block.med-warn .med-total { color: var(--warn); font-weight: 600; }
.med-block.med-cap  .med-total { color: var(--error); font-weight: 700; }

.dose-list { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.dose-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px dashed var(--border);
  font-size: 0.95rem;
}
.dose-row:last-child { border-bottom: none; }
.dose-summary { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: baseline; }

.dose-add {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: end;
  padding: 0.4rem; background: rgba(255,255,255,0.6);
  border-radius: 6px;
}
.dose-add > .small { width: 100%; color: var(--ink-muted); }
.dose-add-mg { flex: 1 1 100%; }
.dose-add-time { display: flex; flex-direction: column; gap: 0.1rem; min-width: 7rem; }
.dose-add-note { flex: 1 1 12rem; }
.dose-add-btn { flex: 0 0 auto; }

/* range toggle */
.range-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}
.range-btn {
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
  color: var(--ink);
  border-right: 1px solid var(--border);
}
.range-btn:last-child { border-right: none; }
.range-btn.active { background: var(--accent); color: #fff; }
.range-btn:hover { text-decoration: none; background: var(--accent-soft); }
.range-btn.active:hover { background: var(--accent); }

/* heatmap */
.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  padding: 0.4rem 0;
  overflow-x: auto;
}
.hm-dow {
  font-size: 0.7rem;
  color: var(--ink-muted);
  padding-right: 0.4rem;
  display: flex; align-items: center;
}
.hm-cell {
  width: 16px; height: 16px;
  border-radius: 3px;
  display: inline-block;
  background: #ebe8e2;
  text-decoration: none;
  cursor: default;
}
a.hm-cell:hover { outline: 2px solid var(--accent); cursor: pointer; }
.hm-empty { background: transparent; }
.hm-na  { background: #ebe8e2; }
.hm-0   { background: #cfe6d4; }
.hm-1   { background: #f5e29a; }
.hm-2   { background: #e9b06a; }
.hm-3   { background: #cc5454; }

.heatmap-legend {
  display: flex; flex-wrap: wrap; gap: 0.7rem;
  margin-top: 0.4rem;
  font-size: 0.85rem; color: var(--ink-muted);
  align-items: center;
}
.heatmap-legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.heatmap-legend i.hm-cell { width: 14px; height: 14px; }

/* chart container */
.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
}
.chart-container.chart-tall { height: 360px; }

/* quick-log badge & "Mehr eintragen" link */
.quick-log-badge {
  display: inline-block;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.5rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.more-link {
  text-align: center;
  margin: 1rem 0;
  font-size: 0.95rem;
}
.more-link a {
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  display: inline-block;
}
.more-link a:hover { background: var(--accent-soft); text-decoration: none; }
.more-link .hint {
  display: block;
  margin: 0.4rem 0 0;
  color: var(--ink-muted);
  font-weight: normal;
}

/* settings — Tier-1/Tier-2 visibility manager */
.visibility-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column;
  gap: 0.25rem;
}
.visibility-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px dashed var(--border);
  font-size: 0.95rem;
}
.visibility-row:last-child { border-bottom: none; }

/* settings — items list */
.items-list { list-style: none; padding: 0; margin: 0; }
.settings-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: end;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
}
.settings-item.archived { opacity: 0.55; }
.settings-row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  flex: 1 1 30rem;
}
.settings-row-grid {
  display: grid;
  grid-template-columns: minmax(8rem, 1.4fr) minmax(8rem, 1.4fr) auto;
  gap: 0.5rem;
  flex: 1 1 100%;
}
@media (max-width: 600px) {
  .settings-row-grid { grid-template-columns: 1fr; }
}
.settings-row-grid .field.meta { align-self: end; padding-bottom: 0.5rem; }
.settings-row-actions { display: flex; align-items: end; }
.small-btn { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.add-item-form .actions { margin-top: 0.5rem; }

/* mahlzeiten — chip-styled meal_component tickboxes */
.component-chips {
  list-style: none;
  padding: 0;
  margin: 0.3rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.component-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}
/* Chip-toggle look for meal components: native checkbox is hidden;
   the wrapping label visually IS the chip. */
.component-chip {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 0.85rem;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.component-chip input { position: absolute; opacity: 0; pointer-events: none; }
.component-chip:hover { background: var(--accent-soft); }
.component-chip:has(input:checked) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.component-children {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.3rem 0 0 0;
  padding: 0.4rem 0.5rem;
  background: rgba(0,0,0,0.03);
  border-left: 2px solid var(--accent);
  border-radius: 0 6px 6px 0;
  flex-basis: 100%;
}
.component-children.hidden { display: none; }
.component-children .component-chip { height: 32px; padding: 0 0.7rem; font-size: 0.85rem; }

/* meal-add-row — chip buttons to add a new empty meal of a given type */
.meal-add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
}
.meal-add-row .small {
  color: var(--ink-muted);
  width: 100%;
  margin-bottom: 0.1rem;
}
.add-meal-btn {
  border-style: dashed;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}
.add-meal-btn:hover {
  background: var(--accent-soft);
}

/* getränke — Tier-1 cards + alcohol badge */
.alcohol-badge {
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 0.6rem;
}
.alcohol-badge.hidden { display: none; }

.drink-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.drink-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  background: #fbfaf7;
  display: flex; flex-direction: column;
  gap: 0.3rem;
}
.drink-tile.active {
  background: #f0eadf;
  border-color: var(--accent);
}
.drink-tile-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.95rem;
}
.drink-tile-head .small { color: var(--ink-muted); }
.drink-tile .field { gap: 0.15rem; }
.drink-tile .chip-row { gap: 0.2rem; }
.drink-tile .chip {
  height: 32px;
  padding: 0 0.5rem;
  font-size: 0.85rem;
}
@media (max-width: 480px) {
  .drink-tile-grid { grid-template-columns: 1fr; }
}

/* chip clear (×) for chip-select rows */
.chip-clear-x {
  width: 28px;
  padding: 0 !important;
  color: var(--ink-muted);
}
.chip-clear-x:hover { color: var(--error); }

/* meals */
.meal-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  margin-bottom: 0.6rem;
  background: #fbfaf7;
}
.meal-row-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.4rem;
}
.flag-row {
  display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center;
}
.flag-row label.checkbox { font-weight: 400; }
.meal-remove { color: var(--error); font-size: 1.1rem; }

/* grid table for environment readings */
.grid-table {
  width: 100%;
  border-collapse: collapse;
}
.grid-table th, .grid-table td { padding: 0.3rem 0.35rem; text-align: left; }
.grid-table thead th { color: var(--ink-muted); font-weight: 500; font-size: 0.85rem; }
.grid-table tbody th { font-weight: 500; }
.grid-table input { padding: 0.4rem 0.5rem; }

.weather-readout {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.hidden-by-default { display: none; }

/* save bar (sticky) */
.save-bar {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 80%, transparent);
  padding: 0.75rem 0 0.5rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
}
.save-status {
  font-size: 0.85rem;
  color: var(--ink-muted);
  min-width: 7rem;
  text-align: right;
}
.save-status.save-ok { color: var(--info); }
.save-status.save-error { color: var(--error); }
.save-status.save-pending { color: var(--warn); }

/* duplicate page */
.duplicate-cats {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin-top: 0.5rem;
}
.duplicate-cats legend { padding: 0 0.4rem; color: var(--ink-muted); font-size: 0.9rem; }

/* auth */
.auth-card {
  max-width: 360px;
  margin: 4rem auto 0;
  background: var(--surface);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.auth-card form { display: flex; flex-direction: column; gap: 0.5rem; }
.auth-card .primary { margin-top: 0.5rem; }

/* flashes */
.flashes { list-style: none; padding: 0; margin: 0 0 1rem; }
.flash { padding: 0.55rem 0.75rem; border-radius: 6px; margin-bottom: 0.4rem; }
.flash-info { background: #e6f0ec; color: var(--info); }
.flash-error { background: #f6e2e2; color: var(--error); }

.errors {
  list-style: none; padding: 0; margin: 0.25rem 0 0;
  color: var(--error); font-size: 0.9rem;
}

/* ============================================================
   M18-B — Two-pane desktop shell
   Mobile (<900px): app-shell is just a block container; the
   rail and marginalia stay display:none. Behavior identical
   to pre-M18 layout.
   ≥900px on body[data-shell="day"]: rail appears as left col.
   ≥1280px on body[data-shell="day"]: marginalia rail joins.
   Other pages keep a single-column layout at every width.
   ============================================================ */
.app-shell { display: block; }

.day-rail,
.day-marginalia { display: none; }

@media (min-width: 900px) {
  body[data-shell="day"] .app-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 720px);
    column-gap: 2.25rem;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1rem;
    align-items: start;
  }
  body[data-shell="day"] .app-shell > .container {
    max-width: none;     /* the grid column already constrains width */
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }
  body[data-shell="day"] .day-rail {
    display: block;
    position: sticky;
    top: 56px;            /* topbar height */
    align-self: start;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    padding: 1rem 0.25rem 1rem 0;
    border-right: 1px solid var(--paper-rule);
  }
  /* Container max-width relaxes on the other pages so they
     breathe a bit on a desktop monitor without becoming wide. */
  body:not([data-shell="day"]) .app-shell > .container {
    max-width: 980px;
  }
}

@media (min-width: 1280px) {
  body[data-shell="day"] .app-shell {
    grid-template-columns: 220px minmax(0, 720px) 280px;
    max-width: 1320px;
  }
  body[data-shell="day"] .day-marginalia {
    display: block;
    position: sticky;
    top: 56px;
    align-self: start;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    padding: 1rem 0 1rem 0.25rem;
    border-left: 1px solid var(--paper-rule);
  }
}

/* ----- Rail TOC ----- */
.rail-toc { font-size: 0.95rem; }
.rail-toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}
.rail-toc__item {
  position: relative;
  padding-left: 0.85rem;
  border-left: 2px solid transparent;   /* reserves space — no jump on hover */
}
.rail-toc__link {
  display: block;
  padding: 0.4rem 0.5rem 0.4rem 0;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-weight: 400;
  letter-spacing: 0.01em;
  border-radius: 0;
  transition: color 0.15s ease;
  text-decoration: none;
}
.rail-toc__link:hover {
  color: var(--ink);
  text-decoration: none;
}
.rail-toc__item--full .rail-toc__link {
  /* Sections that live behind ?full=1 — slightly muted in rail. */
  color: var(--ink-weak);
}
/* Active-section state set by IntersectionObserver in app.js. */
.rail-toc__item.is-active {
  border-left-color: var(--brass);
}
.rail-toc__item.is-active .rail-toc__link {
  color: var(--ink);
  font-weight: 600;
}
.rail-toc__item.is-active::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 50%;
  width: 8px;
  height: 8px;
  background: var(--brass);
  border-radius: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 3px var(--bg);
}

/* The body of every section gets a little extra scroll-margin so the
   sticky topbar doesn't cover the title when the rail jumps to it. */
.section[id^="sec-"] {
  scroll-margin-top: 72px;
}

/* ============================================================
   M18-C — Marginalia rail content + autosave pulse + save-bar
   relocation. Mobile/tablet keep the sticky-bottom save-bar;
   desktop ≥1280px hides it and shows the in-rail copy.
   ============================================================ */

/* Mobile-first defaults: sticky-bottom save-bar visible, rail copy hidden. */
.save-bar--rail { display: none; }

@media (min-width: 1280px) {
  body[data-shell="day"] .save-bar--mobile { display: none; }
  body[data-shell="day"] .save-bar--rail   { display: flex; }
}

.marginalia {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  font-size: 0.95rem;
}

.marginalia__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--paper-rule);
}
.marginalia__nav .day-nav-arrow {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink); background: var(--surface);
  font-size: 1.05rem; line-height: 1;
}
.marginalia__nav .day-nav-arrow:hover { background: var(--accent-soft); text-decoration: none; }
.marginalia__nav .day-nav-today {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}
.marginalia__nav .day-nav-today.is-today {
  background: var(--accent); color: #fff; border-color: var(--accent);
  cursor: default;
}

.marginalia__deltas {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.marginalia__row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--paper-rule);
}
.marginalia__row:last-child { border-bottom: 0; }
.marginalia__label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}
.marginalia__values {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  font-variant-numeric: tabular-nums;
}
.marginalia__y {
  color: var(--ink-weak);
  font-size: 0.9rem;
}
.marginalia__arrow {
  color: var(--ink-weak);
  font-size: 0.85rem;
}
.marginalia__t {
  color: var(--ink);
  font-weight: 600;
  font-size: 1.05rem;
}

/* Direction matching `better` paints brass on the today value;
   the opposite direction paints --ink-weak (regression).
   `flat` and `n/a` stay neutral.                                  */
.marginalia__row[data-better="up"].marginalia__row--up   .marginalia__t { color: var(--brass); }
.marginalia__row[data-better="up"].marginalia__row--down .marginalia__t { color: var(--ink-weak); }
.marginalia__row[data-better="down"].marginalia__row--down .marginalia__t { color: var(--brass); }
.marginalia__row[data-better="down"].marginalia__row--up   .marginalia__t { color: var(--ink-weak); }

/* In-rail save-bar: not sticky; sits at the bottom of the marginalia. */
.save-bar--rail {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--paper-rule);
  background: transparent;
  position: static;
}
.save-bar--rail .save-status { text-align: left; min-width: 0; }
.save-bar--rail .primary { width: 100%; }

/* 7-day dots strip (M18-E populates the data; M18-C styles the markup
   so the partial can render conditionally without a flash later). */
.marginalia__week {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}
.marginalia__week-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1px solid var(--paper-rule);
  background: transparent;
}
.marginalia__week-dot.is-filled {
  background: var(--brass);
  border-color: var(--brass);
}

/* Autosave pulse: 1px brass underline that fades over 800ms.
   Apply on the wrapping .field/label so the underline sits below the
   visible control, not under a hidden input. Keep layout stable by
   reserving 1px of space at the baseline.                         */
.field, label {
  border-bottom: 1px solid transparent;   /* baseline; no visual shift */
  transition: border-color 0.2s ease;
}
.just-saved {
  animation: gt-just-saved 800ms ease-out;
}
@keyframes gt-just-saved {
  0%   { border-bottom-color: var(--brass); }
  60%  { border-bottom-color: var(--brass); }
  100% { border-bottom-color: transparent; }
}

/* ============================================================
   M18-D — Quick-Log in-place toggle + density card
   The 10 full-only sections are always in the DOM. Visibility is
   purely CSS-driven by body[data-quick-mode]. We use opacity +
   max-height (not display:none) so the IntersectionObserver from
   M18-B doesn't lose track when the user toggles.
   ============================================================ */

body[data-quick-mode="quick"] [data-quick="false"] {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-color: transparent;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, max-height 0.25s ease,
              margin 0.25s ease, padding 0.25s ease;
}
body[data-quick-mode="full"] [data-quick="false"] {
  opacity: 1;
  max-height: none;
  transition: opacity 0.18s ease;
}

/* Rail items for full-only sections dim in Quick-Log mode. */
body[data-quick-mode="quick"] .rail-toc__item--full .rail-toc__link {
  opacity: 0.5;
}

/* Toggle button labels: show the right one for the current mode. */
.mode-toggle {
  margin: 1rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mode-toggle button { font-size: 0.95rem; }
body[data-quick-mode="quick"] .mode-toggle__label-full,
body[data-quick-mode="full"]  .mode-toggle__label-quick {
  display: none;
}
.mode-toggle__hint { color: var(--ink-weak); }
body[data-quick-mode="full"] .mode-toggle__hint { display: none; }

/* Density card — three chips in a row. */
.density-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.density-options__form { display: inline-flex; }
.density-chip { font-size: 0.95rem; }
.density-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================================
   M18-E — Polish: marginalia hover highlight, print stylesheet,
   density-per-breakpoint nudges. The 7-day dots + .marginalia__week
   styles already shipped in M18-C; M18-E populates the data.
   ============================================================ */

/* Hovering a marginalia row paints a thin brass left-border on
   the matching form field — soft visual link between rail and form. */
.field-highlight,
label.field-highlight {
  border-left: 2px solid var(--brass);
  padding-left: 0.4rem;
  margin-left: -0.4rem - 2px;
  transition: border-color 0.18s ease, padding-left 0.18s ease;
}

/* Spacious mode on phones is wasteful — fold back to comfortable. */
@media (max-width: 599px) {
  body[data-density="spacious"] {
    --gap: 0.75rem;
    --pad: 1rem;
    --field-h: 2.6rem;
  }
}

/* Print: clean single column, no chrome, all sections visible. */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .day-rail, .day-marginalia, .save-bar,
  .mode-toggle, .day-nav { display: none !important; }
  .app-shell {
    display: block !important;
    grid-template-columns: none !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .container { max-width: none !important; padding: 0 !important; }
  body[data-quick-mode="quick"] [data-quick="false"] {
    opacity: 1 !important;
    max-height: none !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }
  details.section { break-inside: avoid; }
  details.section > summary::before { content: "" !important; }
  details.section[open] > summary { break-after: avoid; }
  /* Force-open every <details> for print without modifying DOM. */
  details:not([open]) > *:not(summary) { display: block !important; }
}
