:root {
  color-scheme: light;
  --ink: #183229;
  --muted: #64756e;
  --line: #dce5df;
  --surface: #fff;
  --canvas: #f6f8f4;
  --green: #176746;
  --green-dark: #0e4b32;
  --green-light: #e4f1e9;
  --amber: #8f590f;
  --amber-light: #fff3d6;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html { background: var(--canvas); }
/* viewport-fit=cover makes env(safe-area-inset-*) real on iPhone (home-screen app): keep content off notch and home indicator. */
body { margin: 0; color: var(--ink); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #7bb995; outline-offset: 2px; }
.shell { max-width: 1380px; margin: 0 auto; padding: 0 32px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; min-height: 72px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: block; width: 40px; height: 40px; flex: none; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.02em; }
.status { font-size: 12px; font-weight: 650; color: var(--amber); background: var(--amber-light); border-radius: 999px; padding: 8px 13px; white-space: nowrap; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--canvas); padding-top: env(safe-area-inset-top, 0px); }
.glucose-widget { min-width: 230px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 11px; background: #edf1ee; color: #44564d; }
.glucose-widget small { display: block; font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.glucose-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.glucose-main strong { font-size: 22px; letter-spacing: -.04em; white-space: nowrap; }
.glucose-main span { font-size: 12px; font-weight: 700; }
.glucose-widget[data-status="in_range"] { background: #e0f3e7; border-color: #acd9ba; color: #145c38; }
.glucose-widget[data-status="outside"] { background: #fff3ce; border-color: #e9d782; color: #70510b; }
.glucose-widget[data-status="low"] { background: #fde8e7; border-color: #edb4b1; color: #9a2925; }
.glucose-widget[data-status="high"] { background: #ffeddb; border-color: #edc09b; color: #9b4d11; }
main { min-height: 70vh; }
.view { padding: 36px 0 50px; }
[hidden] { display: none !important; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
h1 { margin: 0; font-size: clamp(28px, 3vw, 38px); font-weight: 680; letter-spacing: -.045em; }
.day-nav { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.day-nav button, .day-nav input { min-height: 40px; }
.day-nav button, button:not(.tab):not(.primary) { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 8px; padding: 9px 13px; font-weight: 600; }
.day-nav .quiet { font-size: 12px; }
input, select { width: 100%; background: white; color: var(--ink); border: 1px solid #cddbd2; border-radius: 8px; min-height: 42px; padding: 9px 11px; }
.day-nav input { width: auto; font-size: 13px; font-weight: 600; }
.diary-grid { display: grid; grid-template-columns: minmax(295px, 360px) minmax(0, 1fr); gap: 30px; align-items: start; }
.panel, .summary-card { background: var(--surface); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 5px 20px rgba(27, 64, 41, .035); }
.panel { padding: 24px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 0 0 18px; letter-spacing: -.02em; }
.section-head h2 { margin: 0; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
label { display: block; font-size: 12px; font-weight: 650; margin-bottom: 16px; }
label span { color: var(--muted); font-weight: 450; }
label input, label select { display: block; margin-top: 7px; }
/* iOS Safari renders native time fields with no height when empty and centres the value. */
input[type=time] { -webkit-appearance: none; appearance: none; text-align: left; }
input[type=time]::-webkit-date-and-time-value { text-align: left; min-height: 1.2em; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.entry-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.entry-switch:has(> :nth-child(3)) { grid-template-columns: 1.4fr 1fr 1fr; }
.entry-switch button.entry-mode { min-height: 44px; padding: 9px 10px; background: var(--canvas); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font-size: 12px; font-weight: 700; }
.entry-switch button.entry-mode[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: white; }
.primary { background: var(--green); border: 1px solid var(--green); color: #fff; border-radius: 9px; min-height: 43px; padding: 10px 15px; font-weight: 650; }
.primary:hover { background: var(--green-dark); }
.primary span { font-size: 11px; opacity: .7; margin-left: 12px; }
.entry-panel .primary { width: 100%; }
.entry-day-type { margin: 0 0 16px; }
.entry-day-type .entry-switch { margin-bottom: 0; }
.entry-switch button.day-type-option { min-height: 40px; padding: 8px 10px; background: var(--canvas); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font-size: 12px; font-weight: 700; }
.entry-switch button.day-type-option[aria-pressed="true"] { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
#entry-dose .meal-surcharge { margin-bottom: 12px; }
.meal-surcharge .hint { margin: 0; }
.entry-day-type .hint { margin: 6px 0 0; }
.panel > .check-label, .notify-option > .check-label { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.panel > .check-label input, .notify-option > .check-label input { width: 18px; height: 18px; min-height: 18px; margin: 0; accent-color: var(--green); }
.settings-grid .panel .notify-status { margin: 0 0 16px; }
.notify-option { margin-bottom: 18px; }
.notify-option > .check-label { margin-bottom: 0; }
.settings-grid .notify-option > .hint { margin: 4px 0 0 27px; }
.notify-option > .notify-pause { display: flex; align-items: center; gap: 8px; margin: 6px 0 0 27px; font-size: 14px; font-weight: 450; color: var(--muted); }
.notify-option > .notify-pause input { width: 72px; }
.notify-option > .notify-priority { display: block; margin: 6px 0 0 27px; width: calc(100% - 27px); max-width: 320px; }

.timezone-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.banner-action { margin-left: 6px; padding: 4px 10px; font-size: 13px; }
.banner { background: var(--amber-light); color: #69410a; border: 1px solid #f3dfa9; padding: 12px 15px; border-radius: 9px; margin: 0 0 23px; font-size: 13px; }
.meal-type { color: var(--green); font-size: 11px; text-transform: uppercase; font-weight: 750; letter-spacing: .12em; }
h3 { margin: 4px 0 0; font-size: 22px; letter-spacing: -.035em; }
h3 small { font-size: 13px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.factor { text-align: right; }
.factor span, .factor small { display: block; font-size: 11px; color: var(--muted); }
.factor strong { display: block; color: var(--green-dark); font-size: 27px; letter-spacing: -.05em; white-space: nowrap; }
.factor strong small { display: inline; font-size: 13px; font-weight: 500; }
.factor.unavailable strong { color: var(--muted); }
.factor.unavailable small { max-width: 210px; }
.meal-note { font-size: 13px; margin: 16px 0 0; color: var(--muted); }
.delete-treatment { color: #9b3c33 !important; font-size: 12px; padding: 7px 9px !important; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { color: var(--muted); font-weight: 600; text-align: left; }
td, th { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.empty { border: 1px dashed #bdcdc2; color: var(--muted); border-radius: 13px; padding: 36px; text-align: center; font-size: 14px; }
.empty strong { color: var(--ink); }
.analysis-controls { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 25px; }
.analysis-controls label { margin: 0; min-width: 150px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.summary-card { padding: 23px; }
.summary-card strong { display: block; margin-top: 13px; font-size: 30px; color: var(--green-dark); letter-spacing: -.04em; }
.summary-card strong small { font-size: 13px; }
.summary-card p { font-size: 12px; color: var(--muted); line-height: 1.6; }
.settings-grid { display: grid; gap: 20px; align-items: stretch; }
.settings-top { grid-template-columns: 2fr 1fr; }
.settings-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.settings-grid .panel { display: flex; flex-direction: column; }
.settings-grid .panel > button { align-self: flex-start; margin-top: auto; }
.settings-grid .panel p { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 10px 0 0; }
.settings-grid .panel p:empty { display: none; }
.settings-grid .panel h2 .unit { margin-left: 6px; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: 0; }
.settings-grid .isf-table { margin-top: 0; }
.settings-heading { margin: 36px 0 14px; color: var(--muted); font-size: 13px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-save { display: grid; grid-template-columns: 180px 120px auto 1fr; gap: 14px; align-items: end; margin-top: 20px; padding: 18px 24px; }
.settings-save label { margin: 0; }
.settings-save .hint { margin: 0 0 12px; text-align: right; }
.mono, code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
/* Above every page layer (sticky topbar z 20, entry save bar z 5); dialogs use the top layer. */
#toast { position: fixed; z-index: 100; right: 24px; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); max-width: min(360px, calc(100vw - 36px)); background: var(--ink); color: #fff; border-radius: 9px; padding: 13px 17px; font-size: 13px; box-shadow: 0 12px 28px #10281833; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s; }
#toast.visible { opacity: 1; transform: translateY(0); }
#toast.error { background: #8e372e; }
#toast.has-action { pointer-events: auto; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.toast-action { flex: none; border: 1px solid #ffffff66; border-radius: 7px; background: transparent; color: #fff; padding: 6px 11px; font: inherit; font-weight: 700; cursor: pointer; }
.toast-action:hover { background: #ffffff1f; }
@media (max-width: 950px) {
  .diary-grid, .settings-top, .settings-cols { grid-template-columns: minmax(0, 1fr); }
  .settings-save { grid-template-columns: 1fr 1fr; }
  .settings-save .primary { grid-column: 1 / -1; }
  .settings-save .hint { grid-column: 1 / -1; text-align: left; }
  .entry-panel { max-width: 620px; }
}
@media (max-width: 650px) {
  .shell { padding: 0 16px; }
  .topbar { min-height: 76px; flex-wrap: wrap; padding: 10px 0; gap: 10px; }
  .glucose-widget { order: 3; flex: 1 1 100%; }
  .brand strong { font-size: 15px; }
  .status { max-width: 125px; white-space: normal; text-align: center; }
  .page-head { display: block; }
  .day-nav { margin-top: 18px; }
  .summary-grid { grid-template-columns: 1fr; }
  .factor { text-align: left; margin-top: 15px; }
  .factor.unavailable small { max-width: none; }
}


.calc-block { margin-top: 14px; padding-top: 15px; border-top: 1px solid var(--line); }
.calc-block .factor { text-align: left; margin: 0; }
.calc-block .factor small { max-width: none; }
.summary-primary { margin-top: 13px; }
.summary-primary span { color: var(--muted); font-size: 11px; }
.summary-primary strong { margin-top: 2px; }

.analysis-list { margin-top: 20px; }
.analysis-table { min-width: 900px; }
.analysis-table.compact { min-width: 520px; }
.derivation-note { margin: 14px 0 6px; }
.analysis-table tr.matrix-group td { border-top: 2px solid var(--line); }
.matrix .matrix-cell { min-width: 150px; padding: 8px; }
.matrix-cell .range-bar { display: block; width: 100%; height: 8px; border-radius: 4px; overflow: hidden; margin: 2px 0 5px; }
.matrix-cell .range-nums { display: block; white-space: nowrap; color: var(--muted); }
.matrix-cell .range-glucose { display: block; white-space: nowrap; font-size: 12px; }
.matrix-cell small { display: block; margin-top: 2px; }
.matrix-cell.is-active { outline: 2px solid var(--ink); outline-offset: -2px; }
.matrix-cell .active-badge { display: inline-block; margin-bottom: 3px; padding: 1px 7px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 11px; font-weight: 700; }
.matrix-cell.is-best { background: var(--green-light); box-shadow: inset 0 0 0 2px var(--green); }
.matrix-cell.is-best small { color: var(--green); font-weight: 700; }
.matrix-cell.is-overall-best { box-shadow: inset 0 0 0 4px var(--green); }
rect.range-low { fill: #c8463f; }
rect.range-ok { fill: #2f9a63; }
rect.range-high { fill: #e0a43a; }
span.range-low { color: #b23a33; font-weight: 650; }
.range-ok { color: var(--green); }
span.range-high { color: #9a6410; font-weight: 650; }
.range-legend span { margin-right: 10px; white-space: nowrap; }
.glucose-change { display: inline-block; padding: 3px 7px; border-radius: 6px; font-weight: 650; white-space: nowrap; }
.glucose-change.rising { color: #8a3b16; background: #fff0e5; }
.glucose-change.falling { color: #145c78; background: #e5f3f9; }
.glucose-change.steady { color: #4f625b; background: #eaf0ec; }
.analysis-table td { vertical-align: middle; }
.analysis-table td.surcharge-cell { white-space: normal; min-width: 320px; }
.surcharge-days { display: block; line-height: 1.5; }
.analysis-table td small { color: var(--muted); }
.analysis-table td b { font-weight: 650; }
.analysis-table .summary-unavailable { color: var(--muted); font-weight: 400; white-space: normal; }
.analysis-table .analysis-excluded { background: #f4f5f2; color: var(--muted); }
.analysis-table .quiet { font-size: 11px; padding: 6px 9px; }

.analysis-day-row th { padding: 12px 11px; background: var(--green-light); color: var(--green-dark); font-size: 12px; font-weight: 750; text-align: left; text-transform: capitalize; white-space: normal; border-top: 2px solid #c8dfd1; }
.outlier-badge { display: inline-block; margin-left: 7px; padding: 3px 6px; border-radius: 5px; background: var(--amber-light); color: var(--amber); font-size: 11px; font-weight: 750; white-space: nowrap; }

.breakfast-subcards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 17px; }
.breakfast-subcard { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--green-light); }
.breakfast-subcard > span { display: block; font-size: 12px; font-weight: 750; color: var(--green-dark); }
.breakfast-subcard strong { margin-top: 7px; font-size: 20px; }
.breakfast-subcard strong small { font-size: 11px; font-weight: 500; }
.breakfast-subcard > small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.day-type-label { display: inline-flex; align-items: center; gap: 6px; margin-left: 14px; text-transform: none; color: var(--green-dark); font-weight: 600; }
.day-type-label select { min-height: 30px; padding: 3px 6px; font-size: 12px; }
.isf-table { margin: 10px 0 14px; border-top: 1px solid var(--line); }
.isf-table-head, .isf-readonly-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.isf-table-head { color: var(--muted); font-size: 11px; font-weight: 650; }
.isf-readonly-row { font-size: 13px; }
.isf-readonly-row strong { font-weight: 650; }
.isf-readonly-row small { color: var(--muted); font-size: 11px; font-weight: 450; }
.ic-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ic-row input { max-width: 150px; }


/* Rebuilt diary */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.logout-row { display: flex; justify-content: flex-end; margin: 18px 0 32px; }
.logout-row button { font-size: 13px; }

.records > .panel { margin-bottom: 18px; }
.timeline-item { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 13px 0; border-top: 1px solid var(--line); }
.timeline-item:first-child { border-top: 0; }
.timeline-item time { color: var(--muted); font-size: 12px; padding-top: 2px; }
.timeline-item strong { font-size: 14px; }
.timeline-item p { margin: 4px 0; color: var(--ink); font-size: 12px; line-height: 1.45; }
.timeline-item small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.timeline-actions { display: flex; gap: 5px; }
.timeline-actions button { font-size: 11px; padding: 6px 8px !important; }
.form-actions { display: flex; gap: 8px; }
.form-actions .primary { flex: 1; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(100%, 400px); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.login-brand img { display: block; flex: none; }
.login-card h1 { margin-bottom: 8px; }
.login-card form { margin-top: 22px; }
.login-card .primary { width: 100%; }
.login-card .form-error { color: #9b3c33; }
@media (max-width: 700px) {
  .timeline-item { grid-template-columns: 50px minmax(0, 1fr); }
  .timeline-actions { grid-column: 2; }
  .topbar-actions { flex-direction: column; gap: 5px; }
}

/* A saved entry as a card (web/ui/entry-card.js): header, scrolling body, save button at the bottom. */
#edit-dialog { width: min(480px, calc(100vw - 28px)); max-height: min(820px, calc(100vh - 32px)); max-height: min(820px, calc(100dvh - 32px)); overflow: hidden; border: 1px solid var(--line); border-radius: 15px; padding: 0; color: var(--ink); background: var(--canvas); box-shadow: 0 18px 70px #10281840; }
#edit-dialog[open] { display: flex; }
#edit-dialog::backdrop { background: #0c2419a8; }
.entry-sheet { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.card-head { align-items: center; margin: 0; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.card-head h2 { margin: 0; }
.card-date { color: var(--muted); font-size: 13px; }
.card-head button.quiet { font-size: 22px; line-height: 1; padding: 3px 9px; }
.card-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.card-foot { padding: 12px 18px max(14px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.card-foot .primary { width: 100%; }
.card-photos { display: grid; gap: 6px; }
.card-photos.many { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.card-photos img { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }
.card-photos.many img { height: 120px; }
.card-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.card-tiles.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-tiles.one { grid-template-columns: minmax(0, 1fr); }
.tile { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; padding: 10px 8px 9px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-align: center; font-weight: 650; }
.tile > small { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.tile-value { display: flex; align-items: baseline; justify-content: center; gap: 3px; color: var(--ink); }
.tile-value small { color: var(--muted); font-size: 12px; font-weight: 600; }
.tile-value b { font-size: 22px; letter-spacing: -.03em; }
.tile input { width: 3.6em; min-height: 0; margin: 0; padding: 0; border: 0; border-bottom: 1px dashed #b9c7bf; border-radius: 0; background: none; text-align: center; font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.tile input:focus-visible { outline: none; border-bottom: 2px solid var(--green); }
.card-tiles.one .tile input { width: 4.5em; }
.tile button.meter { display: inline-flex; gap: 3px; margin-top: 4px; min-height: 0; padding: 6px 6px; border: 0; border-radius: 6px; background: none; }
.meter i { width: 14px; height: 5px; border-radius: 3px; background: #d6ddd9; }
.meter[data-level="unsure"] i.on { background: #e5786d; }
.meter[data-level="known"] i.on { background: #ecc94b; }
.meter[data-level="weighed"] i.on { background: #4fa36f; }
.card-certainty { display: flex; padding: 4px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.card-food { display: flex; flex-direction: column; gap: 8px; }
.card-food textarea { width: 100%; min-height: 6em; max-height: 50vh; field-sizing: content; resize: vertical; padding: 10px 12px; border: 1px solid #cddbd2; border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-size: 15px; font-weight: 400; line-height: 1.45; }
.card-food .entry-chips { align-items: center; gap: 6px; }
.card-food .card-refine { margin-left: auto; }
.card-list { border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.card-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin: 0; padding: 7px 13px; min-height: 46px; border-top: 1px solid var(--line); font-size: 14px; font-weight: 600; }
.card-row:first-child { border-top: 0; }
.card-row > span:first-child { color: var(--ink); font-weight: 600; }
.card-row input, .card-row select { flex: 1 1 auto; width: auto; max-width: 62%; min-height: 34px; margin: 0; padding: 4px 6px; border: 0; background: none; text-align: right; font-weight: 700; }
.card-row input[type=time] { flex: 0 0 auto; text-align: right; }
.card-row select { text-align-last: right; }
.card-number { display: inline-flex; align-items: baseline; gap: 4px; color: var(--ink); }
.card-row .card-number input { width: 4.5em; max-width: none; }
.card-number small { color: var(--muted); }
.card-number.wide { padding: 4px 12px; border: 1px solid #cddbd2; border-radius: 10px; background: #fff; }
.card-number.wide input { width: 4.5em; min-height: 36px; margin: 0; padding: 0; border: 0; background: none; font-size: 18px; font-weight: 750; }
.card-group { display: flex; flex-direction: column; gap: 8px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.card-group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.card-group-head small { color: var(--muted); font-size: 12.5px; }
.card-group-head:not(:first-child) { margin-top: 6px; }
.segments { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: #edf2ee; }
.segments button { flex: 1; min-height: 36px; padding: 6px 8px; border: 0 !important; border-radius: 8px !important; background: transparent !important; color: var(--muted) !important; font-size: 13px; font-weight: 700; }
.segments button[aria-pressed="true"] { background: var(--surface) !important; color: var(--ink) !important; box-shadow: 0 1px 3px #18322922; }
.card-body button.card-delete { align-self: center; min-height: 0; margin-top: 2px; padding: 8px 14px; border: 0; background: none; color: #a8322a; font-size: 13px; font-weight: 650; }
.card-body button.card-delete.armed { background: #fdecea; border-radius: 9px; }
@media (max-width: 650px) {
  #edit-dialog { width: 100vw; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0; padding-top: env(safe-area-inset-top, 0px); }
}

/* Compact analysis controls */
.summary-card .summary-primary { margin-top: 14px; }
.summary-card .summary-primary strong { margin-top: 3px; }
.summary-card > p { margin: 12px 0 0; }
.breakfast-subcard > small { font-size: 11px; }

.ui-icon { width: 16px; height: 16px; flex: none; vertical-align: middle; }
.analysis-table .icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 5px; color: var(--green-dark); }
.analysis-table .icon-button .ui-icon { width: 18px; height: 18px; }
.analysis-table .exclude-meal { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 8px; border-color: #bdd8c5; background: var(--green-light); color: var(--green-dark); font-size: 11px; white-space: nowrap; }
.analysis-table .exclude-meal.is-excluded { background: #f3f4f1; border-color: var(--line); color: var(--muted); }
.analysis-table .analysis-outlier td:nth-child(2) { color: var(--amber); }

.sport-state { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 650; }
.sport-state.is-applied { color: var(--green-dark); }
.sport-custom summary { width: fit-content; color: var(--green); font-size: 11px; font-weight: 650; cursor: pointer; }
.sport-custom-fields { display: flex; align-items: end; gap: 7px; margin-top: 9px; }
.sport-custom-fields label { margin: 0; }
.sport-custom-fields label span { display: block; font-size: 11px; }
.sport-custom-fields input { width: 100px; min-height: 32px; margin-top: 4px; padding: 5px 7px; }
.sport-custom-fields button { min-height: 32px; padding: 5px 9px; }

/* Meal window chart and editor */
.meal-chart { margin: 15px 0 5px; }
.day-overview { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.day-overview .section-head { gap: 10px; }
.day-overview-chart { margin: 8px 0 4px; min-height: 120px; }
.day-overview p.hint { margin: 0; }
.overview-span { display: inline-flex; gap: 4px; }
.overview-span button { min-height: 32px; padding: 5px 10px; background: var(--canvas); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 12px; font-weight: 700; }
.overview-span button[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.window-chart-svg { --plot: #fbfcfa; --grid: #e3ebe5; --label: var(--muted); --curve: #267855; --band: #dff0e5; --shade: #17674614; --handle: #0e4b32; --event: #50645b;
  display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.window-chart-svg .plot-bg { fill: var(--plot); }
.window-chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.window-chart-svg .axis, .window-chart-svg .tick { stroke: var(--label); stroke-width: 1; opacity: .6; }
.window-chart-svg text { fill: var(--label); font-size: 11px; }
.window-chart-svg .y-unit { font-size: 10px; }
.window-chart-svg .target-band { fill: var(--band); }
.window-chart-svg .limit-high { stroke: #d87a2a; stroke-width: 1.6; stroke-dasharray: 7 5; }
.window-chart-svg .limit-low { stroke: #cf3b32; stroke-width: 1.6; stroke-dasharray: 7 5; }
.window-chart-svg .curve { fill: none; stroke: var(--curve); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.window-chart-svg .window-shade { fill: var(--shade); }
.window-chart-svg .auto-marker { stroke: var(--label); stroke-width: 1; stroke-dasharray: 2 4; opacity: .8; }
.window-chart-svg .chart-event { opacity: .38; }
.window-chart-svg .chart-event.is-included { opacity: 1; }
.window-chart-svg .chart-event path { fill: none; stroke: var(--event); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.window-chart-svg .chart-event.carbs path { stroke: #a1600f; }
.window-chart-svg .chart-event.insulin path { stroke: #1f6d9a; }
.window-chart-svg .chart-event.non-rapid path { stroke: var(--label); }
.window-chart-svg .chart-event text { font-size: 10px; font-weight: 650; fill: var(--event); }
.window-chart-svg .event-guide { stroke: var(--event); stroke-width: 1; stroke-dasharray: 1 3; opacity: .45; }
.window-chart-svg .chart-event.sport rect { fill: #7c5cc433; stroke: #7c5cc4; stroke-width: 1; }
.window-chart-svg .handle-line { stroke: var(--handle); stroke-width: 2; }
.window-chart-svg .handle-dot { fill: #f4c042; stroke: #fff; stroke-width: 2; }
.window-chart-svg .handle-dot[data-tone="in-range"] { fill: #6fbf73; }
.window-chart-svg .handle-dot[data-tone="low"] { fill: #e2463c; }
.window-chart-svg .handle-dot[data-tone="high"] { fill: #f08a2c; }
.window-chart-svg .handle-dot[data-tone="neutral"] { fill: #c9d3cd; }
.meal-chart-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; color: var(--muted); }
.meal-chart-foot b { color: var(--amber); font-weight: 700; }
.meal-chart-foot button { font-size: 12px; padding: 7px 11px !important; }
.manual-badge { display: inline-block; margin-left: 7px; padding: 3px 6px; border-radius: 5px; background: #ece7f8; color: #5a3f9c; font-size: 11px; font-weight: 750; white-space: nowrap; }

#window-dialog { width: min(760px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); overflow-y: auto; border: 1px solid var(--line); border-radius: 15px; padding: 20px; color: var(--ink); box-shadow: 0 18px 70px #10281840; }
#window-dialog::backdrop { background: #0c2419a8; }
#window-dialog .section-head { align-items: start; margin-bottom: 12px; }
#window-dialog .section-head h2 { margin-top: 4px; }
#window-dialog .section-head button { font-size: 22px; line-height: 1; padding: 3px 9px; }
.window-readout { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 14px 10px; border-radius: 12px 12px 0 0; background: #2b3530; color: #fff; text-align: center; }
.window-readout[data-tone="outside"] { background: #f4c042; color: #1d1708; }
.window-readout[data-tone="in-range"] { background: #4e8c4f; }
.window-readout[data-tone="low"] { background: #c8362e; }
.window-readout[data-tone="high"] { background: #e07a22; color: #1d1104; }
.readout-label { font-size: 12px; font-weight: 650; opacity: .85; }
.readout-value { display: inline-flex; align-items: baseline; gap: 6px; }
.readout-value strong { font-size: 52px; line-height: 1; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.readout-trend { font-size: 34px; font-weight: 700; }
.readout-value small { font-size: 14px; font-weight: 600; }
.window-handle-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0; background: #111614; padding: 8px 8px 0; }
.window-handle-switch button { border: 0 !important; border-radius: 8px 8px 0 0 !important; background: transparent !important; color: #9fb0a8 !important; min-height: 40px; }
.window-handle-switch button[aria-pressed="true"] { background: #232b27 !important; color: #fff !important; }
.window-chart { background: #111614; border-radius: 0 0 12px 12px; padding: 4px 6px 6px; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.window-chart .window-chart-svg { --plot: #111614; --grid: #2f3833; --label: #b9c6bf; --curve: #fff; --band: #3e5a2e; --shade: #ffffff12; --handle: #e9efe9; --event: #c9d3cd; }
.window-chart .chart-event.carbs path { stroke: #f1b04f; }
.window-chart .chart-event.insulin path { stroke: #7cc5f0; }
.window-chart .window-handle { cursor: ew-resize; outline: none; }
.window-chart .handle-hit { fill: transparent; touch-action: none; }
.window-chart .handle-line { opacity: .7; }
.window-chart .window-handle.is-active .handle-line { opacity: 1; stroke-width: 2.5; }
.window-chart .handle-knob rect { fill: #3a4540; stroke: #8b9a93; stroke-width: 1.5; }
.window-chart .handle-knob path { stroke: #e9efe9; stroke-width: 1.6; stroke-linecap: round; }
.window-chart .window-handle.is-active .handle-knob rect { fill: #f4c042; stroke: #f4c042; }
.window-chart .window-handle.is-active .handle-knob path { stroke: #1d1708; }
.window-chart .window-handle.is-snapped .handle-line { stroke: #f4c042; }
.window-chart .window-handle:focus-visible .handle-knob rect { stroke: #7bb995; stroke-width: 3; }
.window-chart .is-dragging, .window-chart.is-dragging { cursor: ew-resize; }
.window-nudge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.window-nudge button { min-height: 44px; font-size: 13px; padding: 6px !important; }
.window-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.window-facts > div { min-width: 0; padding: 9px 10px; border-radius: 8px; background: var(--canvas); }
.window-facts span, .window-facts small { display: block; color: var(--muted); font-size: 11px; }
.window-facts span small { display: inline; }
.window-facts strong { display: block; margin: 2px 0; font-size: 18px; color: var(--green-dark); letter-spacing: -.02em; }
.window-state { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.window-state b { color: var(--amber); }
.window-warning { color: #9b3c33; }
#window-dialog .form-actions { flex-wrap: wrap; }
@media (max-width: 650px) {
  #window-dialog { padding: 14px; width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  .window-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .readout-value strong { font-size: 44px; }
  .window-chart { padding: 2px 0 4px; }
  #window-dialog .form-actions .primary { flex-basis: 100%; }
  #window-dialog .form-actions button.quiet { flex: 1; }
}

/* Compact entry: chips for time, sport and note; tappable dose suggestions; one save button. */
.entry-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -4px 0 14px; }
.entry-chips[hidden] { display: none; }
#entry-carbs-field { margin-bottom: 10px; }
/* Entry cards: meal, outside factors, dose. Number and time inputs stay narrow under their label. */
#entry-form input[type=number], #entry-form input[type=time] { width: 120px; }
.entry-card { margin: 0 0 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.entry-card[hidden] { display: none; }
.entry-card > label:last-child, .entry-card > :last-child { margin-bottom: 0; }
.entry-card-title { margin: 0 0 8px; color: var(--green-dark); font-size: 12px; font-weight: 750; }
.entry-dose-card { border-color: #bddac6; background: #f9fdf9; }
.entry-dose-card .help-result:not(:empty) { margin: 0 0 12px; padding: 0; border: 0; background: none; }
.entry-quality-row { margin: 0; }
.entry-chips button.chip.quiet-chip { background: none; border-style: dashed; color: var(--muted); }
.entry-chips button.chip, .entry-chips label.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; margin: 0; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--canvas); color: var(--ink); font-size: 12px; font-weight: 650; cursor: pointer; }
.entry-chips button.chip:disabled { cursor: default; color: var(--muted); }
label.chip span { color: inherit; font-weight: inherit; }
label.chip input { width: 16px; height: 16px; min-height: 16px; margin: 0; accent-color: var(--green); }
.entry-chips label.chip:has(input:checked) { background: var(--amber-light); border-color: #e0c27a; color: var(--amber); }
.entry-chips button.chip[aria-pressed="true"] { background: var(--amber-light); border-color: #e0c27a; color: var(--amber); }
.entry-switch { margin-bottom: 14px; }
.entry-switch button.entry-mode { min-height: 38px; }
.entry-day-type .entry-switch button.day-type-option { min-height: 36px; }
.help-result:not(:empty) { margin: 0 0 14px; padding: 11px; border: 1px solid #bddac6; border-radius: 10px; background: #f9fdf9; font-size: 12px; }
.help-result[aria-busy="true"] { opacity: .65; }
.dose-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; }
.dose-heading { color: var(--green-dark); font-weight: 750; }
.dose-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 7px; margin-top: 10px; }
.help-result .dose-option { display: grid; justify-items: center; gap: 2px; min-width: 0; padding: 8px 4px; border: 1.5px solid var(--line); border-radius: 10px; background: white; color: var(--ink); text-align: center; font-weight: 600; }
.dose-option .dose-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.dose-option strong { color: var(--green-dark); font-size: 21px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.dose-option strong small { font-size: 12px; font-weight: 650; }
.dose-option .dose-expected { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.help-result .dose-option[aria-pressed="true"] { border-color: var(--green); background: var(--green-light); box-shadow: inset 0 0 0 1px var(--green); }
/* Dose slider (user request 2026-11-15): dose, where glucose likely ends, recommendation. */
.ds { margin-top: 8px; }
.ds-read { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 12px; }
.ds-dose strong { display: block; font-size: 40px; line-height: 1; color: var(--green-dark); font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.ds-dose strong small { font-size: 16px; margin-left: 3px; }
.ds-split { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 650; }
.ds-land { text-align: right; }
.ds-land span { display: block; font-size: 11.5px; color: var(--muted); font-weight: 650; margin-bottom: 3px; }
.ds-pill { display: inline-block; padding: 6px 11px; border-radius: 999px; font-weight: 750; font-size: 17px; font-variant-numeric: tabular-nums; }
.ds-pill small { font-size: 11px; font-weight: 650; margin-left: 3px; opacity: .8; }
.ds-land .ds-iqr { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; }
.ds-pill.is-ok { background: #dff0e6; color: #14603f; }
.ds-pill.is-high { background: #fbefd5; color: #8a5a00; }
.ds-pill.is-low { background: #f8dddd; color: #a12f2f; }
.ds-cor { margin: 0 0 6px; }
.ds-cor-axis { position: relative; height: 28px; border-radius: 7px; background: #f0f2f1; overflow: hidden; }
.ds-cor-low, .ds-cor-zone { position: absolute; top: 0; bottom: 0; }
.ds-cor-low { left: 0; background: #f7e1e1; }
.ds-cor-zone { background: #dcefe3; }
.ds-cor-w { position: absolute; top: 13px; height: 2px; background: #7a8a83; }
.ds-cor-iqr { position: absolute; top: 7px; height: 14px; border-radius: 7px; background: #3c7f5d; opacity: .85; }
.ds-cor-med { position: absolute; top: 4px; width: 4px; height: 20px; border-radius: 2px; background: #123d2a; transform: translateX(-50%); }
.ds-cor-scale { position: relative; height: 14px; margin-top: 3px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ds-cor-scale span { position: absolute; transform: translateX(-50%); }
.ds-rail { position: relative; padding-top: 28px; }
.ds-flag { position: absolute; top: 0; white-space: nowrap; }
.ds-flag b { display: block; font-size: 11.5px; font-weight: 750; color: #2f6fb0; background: #e6effa; border-radius: 6px; padding: 2px 7px; }
.ds-stem { position: absolute; top: 20px; width: 2px; height: 10px; background: #2f6fb0; transform: translateX(-50%); }
.help-result input.ds-range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 36px; min-height: 0; margin: 0; padding: 0; border: 0; background: transparent; box-shadow: none; }
.ds-range::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--ds-track, #e3e7e5); }
.ds-range::-moz-range-track { height: 10px; border-radius: 5px; background: var(--ds-track, #e3e7e5); }
.ds-range::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -9px; border-radius: 50%; background: #fff; border: 3px solid var(--green-dark); box-shadow: 0 2px 6px rgba(0,0,0,.22); }
.ds-range::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--green-dark); box-shadow: 0 2px 6px rgba(0,0,0,.22); }
.ds-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; }
.help-result .dose-option.is-suggested:not([aria-pressed="true"]):not(.is-changed) { border-color: #2f6fb0; background: #eaf2fb; box-shadow: inset 0 0 0 1px #2f6fb0; }
.help-result .dose-option.is-changed { border-color: #c27a00; background: #fff6e0; box-shadow: inset 0 0 0 1px #c27a00; animation: dose-changed 1.2s ease-out; }
.dose-option .dose-was { color: #8a5600; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dose-changed { display: flex; align-items: flex-start; gap: 6px; margin: 8px 0 0; padding: 7px 9px; border-radius: 8px; background: #fff6e0; color: #6b4300; font-size: 13px; font-weight: 650; }
.dose-changed .ui-icon { flex: none; width: 16px; height: 16px; margin-top: 1px; }
@keyframes dose-changed { 0% { background: #ffd98a; } 100% { background: #fff6e0; } }
@media (prefers-reduced-motion: reduce) { .help-result .dose-option.is-changed { animation: none; } }
.dose-factor { margin: 9px 0 0; color: var(--ink); }
.help-result .hint { margin: 9px 0 0; }
.entry-actions { border-radius: 0 0 15px 15px; position: sticky; bottom: 0; z-index: 5; margin: 0 -24px -24px; padding: 10px 24px calc(14px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 30%); }

/* Diary head and recent context */
.refresh-label { margin-left: 6px; }
.active-card { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0 4px; }
.active-item { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--canvas); min-width: 0; }
.active-item span, .active-item small { display: block; color: var(--muted); font-size: 11px; font-weight: 650; }
.active-item strong { display: block; margin: 1px 0 2px; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.active-item strong small { display: inline; font-size: 11px; font-weight: 600; }
.active-item.expected { background: var(--green-light); border-color: #b9d8c5; }
.active-item.expected strong { color: var(--green-dark); }
.active-card .hint { grid-column: 1 / -1; margin: 0; }
.overview-recent { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 6px 0 2px; }
.overview-recent:empty { display: none; }
.recent-label { color: var(--muted); font-size: 11px; font-weight: 650; margin-right: 2px; }
.recent-chip { padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--canvas); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.recent-chip time { color: var(--muted); font-weight: 650; }
.day-overview p.hint:empty { display: none; }
@media (max-width: 650px) {
  .brand-mark { width: 32px; height: 32px; }
  .topbar { min-height: 0; padding: 8px 0; gap: 8px; }
  #diary-view.view { padding-top: 14px; }
  .diary-head { margin-bottom: 14px; }
  .diary-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .diary-head .day-nav { margin-top: 0; flex-wrap: nowrap; }
  .diary-head .day-nav input { flex: 1; min-width: 0; }
  .refresh-label { display: none; }
  .panel { padding: 18px; }
  .entry-actions { margin: 0 -18px -18px; padding: 10px 18px calc(12px + env(safe-area-inset-bottom, 0px)); }
  /* Full width and lifted above the sticky "In Nightscout speichern" bar so neither hides the other. */
  #toast { left: 12px; right: 12px; max-width: none; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}

/* Diary modes: "Heute" (entry) and "Verlauf" (review); side by side on wide screens. */
@media (max-width: 950px) {
  #diary-view[data-mode="now"] .review-panel { display: none; }
  #diary-view[data-mode="review"] .entry-panel { display: none; }
}
.review-summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.review-summary:empty { display: none; }
.review-chip { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--canvas); color: var(--ink); font-size: 12px; font-weight: 650; text-decoration: none; }
.review-chip.needs-check { background: var(--amber-light); border-color: #e0c27a; color: var(--amber); }
.day-list { display: grid; gap: 10px; }
.day-meal { padding: 4px 13px 10px; border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 11px; background: var(--surface); scroll-margin-top: 170px; }
.day-meal.needs-check { border-left-color: #d9a441; }
.day-meal-window { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.day-meal-factor { color: var(--green-dark); font-size: 18px; font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }
.day-meal-factor small { font-size: 11px; font-weight: 600; }
.day-meal .timeline-item:first-of-type { border-top: 1px solid var(--line); }
.day-meal-details { margin-top: 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.day-meal-details summary { cursor: pointer; color: var(--green-dark); font-size: 12px; font-weight: 700; padding: 2px 0 4px; }
.day-meal-details[open] summary { margin-bottom: 8px; }
@media (max-width: 650px) { .records .night-values { grid-template-columns: 1fr 1fr; } .records .night-card .section-head { display: block; } }

/* Factor facts in the analysis summary cards */
.factor-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 13px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.factor-facts > div { min-width: 0; }
.factor-facts dt { color: var(--muted); font-size: 11px; }
.factor-facts dd { margin: 1px 0 0; font-size: 17px; font-weight: 700; color: var(--green-dark); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.factor-facts .key dd { color: var(--green); }
.factor-facts.compact { grid-template-columns: 1fr; gap: 4px; margin-top: 8px; padding-top: 7px; }
.factor-facts.compact dd { font-size: 14px; white-space: nowrap; }
/* KH-Sicherheit: three-stop slider with its current label, on one line with the fat mark. */
.certainty-slider { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; min-width: 0; }
/* Colour-coded scale: red unsure, yellow roughly known, green weighed; thumb and label take the chosen colour. */
.certainty-slider { --certainty: #b98a00; --certainty-text: #8a6700; }
.certainty-slider[data-level="unsure"] { --certainty: #c0392b; --certainty-text: #a8322a; }
.certainty-slider[data-level="weighed"] { --certainty: var(--green); --certainty-text: var(--green); }
.certainty-slider input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; min-width: 60px; min-height: 0; height: 28px; margin: 0; padding: 0; border: 0; background: none; }
.certainty-slider input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, #e5786d 0 33.3%, #ecc94b 33.3% 66.6%, #4fa36f 66.6%); }
.certainty-slider input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, #e5786d 0 33.3%, #ecc94b 33.3% 66.6%, #4fa36f 66.6%); }
.certainty-slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border: 3px solid #fff; border-radius: 50%; background: var(--certainty); box-shadow: 0 0 0 1px rgba(24, 50, 41, .25), 0 1px 3px rgba(24, 50, 41, .2); }
.certainty-slider input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 3px solid #fff; border-radius: 50%; background: var(--certainty); box-shadow: 0 0 0 1px rgba(24, 50, 41, .25), 0 1px 3px rgba(24, 50, 41, .2); }
.certainty-label { min-width: 82px; font-size: 12px; font-weight: 650; color: var(--certainty-text); white-space: nowrap; }
.outlier-badge.certainty-unsure { background: #fdecea; color: #a8322a; }
.outlier-badge.certainty-weighed { background: var(--green-light); color: var(--green); }
.entry-quality-row { flex-wrap: nowrap; }
.entry-card .entry-chips { margin: 0 0 10px; }
.entry-card .entry-day-type { margin: 0; }
.entry-card > .entry-chips:last-child { margin-bottom: 0; }

/* Analysis sub-pages: Werte | Automatik */
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.segmented button[role="tab"] { border: 0; border-radius: 999px; padding: 7px 18px; background: none; color: var(--muted); font-size: 13px; font-weight: 650; }
.segmented button[role="tab"][aria-selected="true"] { background: var(--green); color: #fff; }
.automatik-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.automatik-chips .chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--canvas); font-size: 13px; }
.automatik-chips b { font-weight: 650; }
.automatik-steps { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 4px; font-size: 13px; line-height: 1.5; max-width: 820px; }
.analysis-details > summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; cursor: pointer; list-style: none; }
.analysis-details > summary::-webkit-details-marker { display: none; }
.analysis-details > summary h2::before { content: "▸ "; color: var(--muted); }
.analysis-details[open] > summary h2::before { content: "▾ "; }
.analysis-details[open] > summary { margin-bottom: 14px; }
.tradeoff-layout { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 22px; align-items: start; }
.tradeoff-plot { width: 100%; height: auto; }
.tradeoff-plot text { fill: var(--muted); font-size: 10px; }
.tradeoff-plot .axis { stroke: var(--line); }
.tradeoff-plot .cloud { fill: var(--line); }
.tradeoff-plot .line { fill: none; stroke: var(--green); stroke-width: 1.5; }
.tradeoff-plot .on-line { fill: var(--green); }
.tradeoff-plot .current { fill: none; stroke: var(--ink); stroke-width: 2; }
.tradeoff-list, .tuning-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.tradeoff { display: grid; grid-template-columns: minmax(0, 1fr) 100px 112px 96px; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.tradeoff:first-child { border-top: 0; }
.tradeoff-head { display: grid; gap: 2px; min-width: 0; }
.tradeoff-head small { color: var(--muted); font-size: 12px; }
.tradeoff.is-current .tradeoff-head b::after { content: " ○"; }
#analysis-automatik .apply-button { justify-self: end; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--green-dark); font-size: 12px; font-weight: 650; }
#analysis-automatik .apply-button:hover { border-color: var(--green); }
.tuning-row { border-top: 1px solid var(--line); padding: 10px 0; }
.tuning-row:first-child { border-top: 0; padding-top: 0; }
.tuning-row > summary { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.tuning-row > summary small { margin-left: auto; color: var(--muted); font-size: 12px; }
.tuning-row > .hint { margin: 6px 0 8px; }
.verdict { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; background: #edf1ee; color: var(--muted); }
.verdict-shift { background: var(--amber-light); color: var(--amber); }
.verdict-better { background: var(--green-light); color: var(--green); }
.tuning-options li { display: grid; grid-template-columns: 110px minmax(0, 1fr) 112px 96px; gap: 12px; align-items: center; padding: 4px 0; font-size: 13px; }
.tuning-options li.is-active .tuning-label { font-weight: 700; }
.tuning-options li.is-best .range-nums b::after { content: " ★"; }
.tradeoff .range-bar, .tuning-options .range-bar { width: 100%; height: 10px; }
@media (max-width: 700px) {
  .tradeoff-layout { grid-template-columns: 1fr; }
  .tradeoff { grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; }
  .tradeoff-head { grid-column: 1 / -1; }
  .tradeoff .range-bar { grid-column: 1 / -1; }
  .tuning-options li { grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 4px; padding: 6px 0; }
  .tuning-options .range-bar { grid-column: 1 / -1; grid-row: 2; }
}
.tradeoff .range-nums, .tuning-options .range-nums { white-space: nowrap; }
.tradeoff-delta { font-size: 12px; font-weight: 650; color: var(--muted); }
.delta-good { color: var(--green); }
.delta-bad { color: #b23a33; }
.range-nums .range-median { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }

/* Meal factors: one icon each, drawn in the current text colour. */
.factor-icon { display: inline-block; width: 15px; height: 15px; flex: none; background: currentColor; vertical-align: -2px;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.factor-alcohol { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 2h10l-.6 6.5a4.4 4.4 0 0 1-8.8 0z'/%3E%3Cpath d='M7.4 7h9.2' /%3E%3Cpath d='M12 13v8M8 21h8'/%3E%3C/svg%3E"); }
.factor-fat_protein { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 10.5a8 6 0 0 1 16 0z'/%3E%3Cpath d='M3 14.5c1.5-1.2 3-1.2 4.5 0s3 1.2 4.5 0 3-1.2 4.5 0 3 1.2 4.5 0'/%3E%3Cpath d='M4.5 18h15a0 0 0 0 1 0 0 2.5 2.5 0 0 1-2.5 2.5H7A2.5 2.5 0 0 1 4.5 18z'/%3E%3C/svg%3E"); }
.factor-fast { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='13' r='8'/%3E%3Cpath d='M12 9v4l2.5 2.5'/%3E%3Cpath d='M10 2h4'/%3E%3Cpath d='M12 2v3'/%3E%3C/svg%3E"); }
.factor-icons { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.factor-icons .factor-alcohol, .entry-chips label.factor-chip:has(input[name="alcohol"]:checked) { color: #7a3b8f; }
.factor-icons .factor-fat_protein { color: var(--amber); }
.factor-icons .factor-fast, .entry-chips label.factor-chip:has(input[name="fast"]:checked) { color: #1f5f9e; }
.entry-chips label.factor-chip { position: relative; gap: 5px; }
.entry-chips label.factor-chip input { position: absolute; opacity: 0; pointer-events: none; }
.entry-chips label.factor-chip:has(input:focus-visible) { outline: 2px solid var(--green); outline-offset: 2px; }
.entry-chips label.factor-chip:has(input[name="alcohol"]:checked) { background: #f4eaf7; border-color: #d4b3df; }
.entry-chips label.factor-chip:has(input[name="fast"]:checked) { background: #e8f0f9; border-color: #b3c9e3; }
.entry-chips label.factor-chip:not(:has(input:checked)) .factor-icon { opacity: .55; }

/* "Tag durchgehen" as the day's cockpit: day type, check list, exclusion on each meal. */
.review-day-type { margin: 0 0 12px; }
.review-day-type .entry-switch { margin-bottom: 4px; max-width: 360px; }
.review-day-type .hint { margin: 0; }
.review-chip.is-clean { display: inline-flex; align-items: center; gap: 4px; background: var(--green-light); border-color: #bdd8c5; color: var(--green-dark); }
.review-chip .ui-icon { width: 14px; height: 14px; }
.analysis-table button.review-chip { cursor: pointer; min-height: 0; padding: 4px 10px; background: var(--amber-light); border-color: #e0c27a; color: var(--amber); font-size: 12px; white-space: nowrap; }
.day-meal .exclude-meal, .analysis-table .exclude-meal { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 8px; border-color: #bdd8c5; background: var(--green-light); color: var(--green-dark); font-size: 11px; white-space: nowrap; }
.day-meal .exclude-meal.is-excluded { background: #f3f4f1; border-color: var(--line); color: var(--muted); }
.day-meal.is-excluded .day-meal-factor { color: var(--muted); text-decoration: line-through; }
.sport-review .sport-none, .sport-review .sport-auto { min-height: 32px; padding: 5px 10px; font-size: 12px; }

/* Places: chips in the entry form, a badge on meals and entries, management in settings. */
.entry-place { margin-top: 10px; }
.entry-place .hint { margin: 4px 0 0; }
.entry-chips button.place-chip[aria-pressed="true"] { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.place-badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; font-weight: 600; vertical-align: middle; }
.place-badge::before { content: "⌖ "; }
.dish-badge::before { content: "◍ "; }
.vacation-badge::before { content: "☀ "; }
.place-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.place-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.place-head .place-name { flex: 1 1 140px; min-width: 0; }
.place-spots { list-style: none; margin: 6px 0; padding: 0; }
.place-spot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 3px 0; font-size: 13px; }
.place-new, .place-coords { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.place-new input, .place-coords input { flex: 1 1 140px; min-width: 0; }
.place-coords { align-items: center; margin-top: 6px; }
.place-coords button { padding: 6px 10px; font-size: 13px; }
.settings-subhead { margin: 14px 0 6px; font-size: 14px; letter-spacing: 0; }
.place-spot button { padding: 5px 10px; }
.place-head .place-quick { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; font-weight: 600; }
.place-head .place-quick input { width: 18px; height: 18px; min-height: 18px; margin: 0; accent-color: var(--green); }
.entry-chips select.place-more { width: auto; min-height: 0; padding: 7px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; }

/* Carbs input with the meal factors beside it. */
.entry-carbs-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.entry-carbs-row #entry-carbs-field { margin: 0; }
.entry-carbs-row { flex-wrap: nowrap; gap: 8px; }
#entry-form .entry-carbs-row input[name=carbs] { width: 92px; }
.entry-card .entry-carbs-row .entry-factor-chips { margin: 0; flex-wrap: nowrap; gap: 5px; min-width: 0; }
.entry-carbs-row .factor-chip { min-height: 42px; padding: 5px 9px; }
/* On the narrowest phones the factor chips show their icon only; the title still names them. */
@media (max-width: 359px) { .entry-carbs-row .factor-chip > span:last-child { display: none; } }
.entry-carbs-row #entry-carbs-field { flex: none; width: 92px; white-space: nowrap; }

/* Tag durchgehen: one grid for every row. Time, title and button sit in the same columns inside
   and outside a meal (the loose rows get the meal's inset), chips wrap below the title. */
.day-list .timeline-item { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px 0; }
.day-list > .timeline-item { padding: 8px 14px 8px 17px; border-top: 0; }
.day-list .timeline-item time { padding-top: 0; font-variant-numeric: tabular-nums; }
.day-list .timeline-item p { margin: 3px 0 0; }
.day-list .timeline-item p span { white-space: nowrap; }
.day-list .timeline-actions { grid-column: auto; }
.day-list .timeline-actions button { min-width: 88px; justify-content: center; }
.entry-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.entry-title .factor-icons, .entry-title .place-badge, .entry-title .outlier-badge, .day-meal-tags .place-badge, .day-meal-tags .outlier-badge, .day-meal-title .factor-icons { margin: 0; }
.day-meal-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 6px; align-items: center; padding: 11px 0 9px; }
.day-meal-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.day-meal-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; grid-column: 1; }
.day-meal-result { display: flex; align-items: center; justify-content: flex-end; gap: 10px; grid-column: 2; grid-row: 1 / span 2; }
.day-meal-status { color: var(--amber); font-size: 12px; font-weight: 650; }
.sport-review { display: grid; gap: 8px; margin: 10px 0 8px; padding: 10px 11px; border-radius: 9px; background: var(--canvas); font-size: 12px; }
.sport-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 28px; }
.sport-state { flex-wrap: wrap; gap: 4px 6px; }
.sport-source { flex-basis: 100%; color: var(--muted); font-weight: 500; }
.sport-state:has(> .ui-icon) .sport-source { padding-left: 22px; }
.sport-session { margin-top: 6px; }
.sport-actions { display: flex; flex-wrap: wrap; gap: 7px; }
@media (max-width: 650px) {
  /* On the phone the head stacks: name and window, place and certainty, then factor and switch on one line. */
  .day-meal-head { grid-template-columns: minmax(0, 1fr); }
  .day-meal-title { justify-content: space-between; }
  .day-meal-tags { grid-column: 1; }
  .day-meal-result { grid-column: 1; grid-row: auto; justify-content: space-between; }
}

.day-meal.is-target { box-shadow: 0 0 0 3px #e0c27a; transition: box-shadow .3s; }
/* iOS Safari zooms into any focused field below 16px and stays zoomed. Only iOS matches this @supports, so Android and desktop keep the compact sizes; pinch zoom stays available. */
@supports (-webkit-touch-callout: none) {
  input, select, textarea { font-size: 16px !important; }
}

/* Meal agent: the chat (web/ui/agent-chat.js) with photos, bubbles and, at the end, the carbs to take over. */
#agent-dialog { width: min(520px, calc(100vw - 28px)); height: min(760px, calc(100vh - 32px)); height: min(760px, calc(100dvh - 32px)); max-height: none; overflow: hidden; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 15px; padding: 0; color: var(--ink); background: var(--canvas); box-shadow: 0 18px 70px #10281840; }
#agent-dialog::backdrop { background: #0c2419a8; }
/* The description is the entry's content: room for several lines, growing with the text where the browser can. */
label textarea { display: block; margin-top: 7px; background: white; color: var(--ink); border: 1px solid #cddbd2; border-radius: 8px; padding: 9px 11px; font-weight: 400; line-height: 1.45; }
.agent-entry { align-items: center; }
.agent-chip::before { content: "✦ "; }
.agent-summary { font-size: 12px; color: var(--muted); }
.meal-chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { align-items: center; margin: 0; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.chat-head h2 { margin: 0; }
.chat-head button.quiet { font-size: 22px; line-height: 1; padding: 3px 9px; }
.chat-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-photos figure { position: relative; margin: 0; }
.chat-photos img { display: block; width: 92px; height: 92px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.chat-photos.small img { width: 52px; height: 52px; border-radius: 8px; }
.chat-photos figure button.quiet { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; min-width: 0; min-height: 0; padding: 0; font-size: 15px; line-height: 1; border-radius: 999px; background: var(--surface); }
.chat-bubbles { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 88%; padding: 9px 12px; border-radius: 15px; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.bubble.me { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.ai.latest { border-color: #9cc9ae; box-shadow: 0 0 0 2px var(--green-light); }
.bubble.ai > b { font-size: 16px; }
.bubble .muted, .chat-note, .chat-dish small { color: var(--muted); }
.bubble p { margin: 5px 0 0; }
.chat-question { font-weight: 650; }
.bubble details { margin-top: 6px; font-size: 13px; }
.bubble summary { cursor: pointer; color: var(--muted); }
.chat-items, .chat-lookups { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }
.chat-items li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px dashed var(--line); }
.chat-items small, .chat-lookups { color: var(--muted); }
.chat-note { font-size: 13px; }
.chat-note a { color: inherit; }
.chat-typing { align-self: flex-start; margin: 0; color: var(--muted); font-size: 13px; }
.chat-foot { display: flex; flex-direction: column; gap: 10px; padding: 12px 18px max(14px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.carb-pick .entry-chips { margin-left: auto; gap: 6px; }
.carb-pick .factor-chip { background: #fff; }
@media (max-width: 400px) { .carb-pick .factor-chip > span:last-child { display: none; } }
.chat-input { display: flex; align-items: flex-end; gap: 6px; }
.chat-input textarea { flex: 1; min-width: 0; min-height: 42px; max-height: 140px; field-sizing: content; resize: none; padding: 9px 11px; border: 1px solid #cddbd2; border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-size: 15px; line-height: 1.4; }
.chat-input .round-button { flex: none; display: grid; place-items: center; width: 42px; height: 42px; min-height: 0; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); cursor: pointer; }
.chat-input .round-button.send { background: var(--green); border-color: var(--green); color: #fff; }
.chat-input .round-button[aria-pressed="true"] { border-color: #b3261e; color: #b3261e; }
.ui-icon { width: 19px; height: 19px; }
.chat-voice { margin: -4px 0 0; }
.chat-apply { width: 100%; }
/* The carbs to take over: big number, slider over the agent's range with low, estimate and high as stops. */
.carb-pick { padding: 10px 14px 4px; border: 1px solid #cfe3d6; border-radius: 13px; background: #eef5f0; }
.carb-pick-value { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.carb-pick-value strong { font-size: 30px; letter-spacing: -.04em; white-space: nowrap; }
.carb-note { color: var(--muted); font-size: 12px; }
.portion-values { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.carb-range { position: relative; padding: 4px 0 24px; }
.carb-range input[type=range] { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 30px; min-height: 0; margin: 0; padding: 0; border: 0; background: none; }
.carb-range input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(to right, var(--green) 0 var(--fill, 50%), #d4e6da var(--fill, 50%)); }
.carb-range input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: linear-gradient(to right, var(--green) 0 var(--fill, 50%), #d4e6da var(--fill, 50%)); }
.carb-range input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: #fff; border: 3px solid var(--green); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.carb-range input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid var(--green); }
.carb-range button.carb-tick { position: absolute; bottom: 0; min-height: 0; padding: 2px 4px; border: 0; background: none; color: var(--muted); font-size: 11px; white-space: nowrap; transform: translateX(-50%); }
.carb-range .carb-tick b { color: var(--ink); }
.carb-range button.carb-tick.start { left: 0; transform: none; padding-left: 0; }
.carb-range button.carb-tick.end { right: 0; transform: none; padding-right: 0; }
@media (max-width: 650px) {
  #agent-dialog { width: 100vw; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0; padding-top: env(safe-area-inset-top, 0px); }
}
.agent-panel input[type="text"] { width: 100%; }
.dish-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.dish-item summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.dish-hint { flex-basis: 100%; }
.dish-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.dish-edit input[type="text"] { flex: 1 1 140px; min-width: 0; }

/* Phones: analysis tables as cards (concept 2026-11-18). Each row is a card, the first cell its title,
   the other cells label (from data-label, set in app.js) over value in three columns. */
@media (max-width: 650px) {
  .table-wrap { overflow: visible; }
  .analysis-table, .analysis-table.compact { display: block; min-width: 0; }
  .analysis-table thead { display: none; }
  .analysis-table tbody { display: block; }
  .analysis-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; margin: 0 0 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
  .analysis-table td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; font-size: 13px; }
  .analysis-table td.surcharge-cell { min-width: 0; }
  .analysis-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 1px; color: var(--muted); font-size: 11px; font-weight: 650; }
  .analysis-table td:not([data-label]) { align-self: end; justify-self: end; }
  .analysis-table td[colspan] { grid-column: 1 / -1; justify-self: stretch; }
  .analysis-table.matrix tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analysis-table:not(.matrix) td:first-child { grid-column: 1 / -1; font-size: 14.5px; font-weight: 650; }
  .analysis-table:not(.matrix) td:first-child::before { display: none; }
  .analysis-table td:empty { display: none; }
  .analysis-table tr.analysis-day-row { display: block; margin: 16px 0 6px; padding: 0 2px; border: 0; background: none; }
  .analysis-table tr.analysis-day-row th { display: block; padding: 0; border: 0; white-space: normal; color: var(--ink); font-size: 13px; }
  .analysis-table .analysis-excluded { background: #f4f5f2; }
  .matrix .matrix-cell { min-width: 0; padding: 6px; border-radius: 8px; }
  .analysis-table .glucose-change { padding: 2px 5px; font-size: 12px; }
  .analysis-table td:first-child > small, .analysis-table td:first-child > .summary-unavailable { display: block; margin-top: 2px; font-size: 12px; font-weight: 500; }
  .analysis-table tr.matrix-group td { border-top: 0; }
}

/* App navigation (concept 2026-11-18): tab bar at the bottom up to 950px, a rail on the left above.
   It replaced the old top tabs and the "Jetzt / Tag durchgehen" switch. */
.appnav { position: fixed; z-index: 30; background: var(--surface); border-color: var(--line); border-style: solid; border-width: 0; }
.appnav-item, .appnav button.appnav-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 650; text-decoration: none; }
.appnav .ui-icon { width: 24px; height: 24px; }
.appnav-item.active { color: var(--green-dark); }
.appnav-item.active .ui-icon { stroke-width: 2.4; }
.appnav button.appnav-add { border: 0; border-radius: 0; background: none; padding: 0; color: var(--green-dark); }
.appnav button.appnav-add .ui-icon { box-sizing: content-box; width: 26px; height: 26px; padding: 11px; border-radius: 50%; background: var(--green); color: #fff; box-shadow: 0 6px 16px #17674655; }
.appnav button.appnav-add:hover .ui-icon { background: var(--green-dark); }
@media (max-width: 950px) {
  .appnav { left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; height: calc(63px + env(safe-area-inset-bottom, 0px)); padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); border-top-width: 1px; }
  .appnav-item { height: 62px; }
  .appnav button.appnav-add { height: 62px; justify-content: flex-end; padding-bottom: 7px; }
  .appnav button.appnav-add .ui-icon { margin-top: -22px; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
  #toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
@media (min-width: 951px) {
  .appnav { top: 0; bottom: 0; left: 0; width: 88px; display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 92px 0 20px; border-right-width: 1px; }
  .appnav-item { min-height: 62px; margin: 0 8px; border-radius: 12px; }
  .appnav-item:hover { background: var(--canvas); color: var(--ink); }
  .appnav-item.active { background: var(--green-light); }
  .appnav button.appnav-add { order: -1; min-height: 78px; margin-bottom: 10px; }
  body { padding-left: calc(88px + env(safe-area-inset-left, 0px)); }
}

/* The entry: on phones and tablets a full-screen sheet opened from "+", in the page on wide screens. */
.entry-drawer-nav { display: none; }
@media (max-width: 950px) {
  .entry-drawer { display: none; }
  body.entry-open { overflow: hidden; }
  body.entry-open .entry-drawer { display: block; position: fixed; inset: 0; z-index: 60; overflow-y: auto; overscroll-behavior: contain; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); background: var(--canvas); }
  .entry-drawer-head { position: sticky; top: 0; z-index: 6; align-items: center; margin: 0 -16px 14px; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
  .entry-drawer-head h2 { flex: 1; text-align: center; }
  .entry-drawer .entry-drawer-nav { display: inline-block; }
  .entry-drawer-head button#entry-close { font-size: 22px; line-height: 1; padding: 3px 11px; }
  .entry-drawer .entry-actions { margin: 0 -16px; border-radius: 0; padding-left: 16px; padding-right: 16px; background: linear-gradient(to bottom, rgba(246,248,244,0), var(--canvas) 30%); }
}

/* "+": what to enter, as a sheet from the bottom (web/ui/quick-add.js). */
#add-dialog { width: min(460px, calc(100vw - 28px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 18px; padding: 0; color: var(--ink); background: var(--surface); box-shadow: 0 18px 70px #10281840; }
#add-dialog::backdrop { background: #0c2419a8; }
.quick-add { padding: 8px 18px 18px; }
.quick-add-head { display: grid; grid-template-columns: 1fr auto; align-items: center; position: relative; padding-top: 12px; margin-bottom: 14px; }
.quick-add-head h2 { margin: 0; }
.quick-add-head button.quiet { font-size: 22px; line-height: 1; padding: 3px 10px; }
.grab { display: none; position: absolute; top: 0; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices button.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 72px; padding: 13px 14px; border-radius: 13px; text-align: left; }
.choices button.choice b { font-size: 15px; }
.choices button.choice small { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.35; }
.choices button.choice.main { grid-column: 1 / -1; min-height: 84px; border-color: var(--green); background: var(--green); color: #fff; }
.choices button.choice.main b { font-size: 18px; }
.choices button.choice.main small { color: #e4f1e9; }
.choices button.choice:hover { border-color: var(--green); }
.choices button.choice.main:hover { background: var(--green-dark); }
@media (max-width: 650px) {
  #add-dialog { width: 100vw; max-width: none; margin: auto 0 0; border: 0; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .grab { display: block; }
}

/* Settings: on phones and tablets a list of pages, one page at a time (app.js setupSettingsPages). */
.settings-index, .settings-back { display: none; }
@media (max-width: 950px) {
  #settings-view:not([data-page]) .settings-index { display: block; }
  #settings-view:not([data-page]) .settings-grid, #settings-view:not([data-page]) .settings-heading, #settings-view:not([data-page]) .settings-save { display: none; }
  #settings-view[data-page] .settings-back:not([hidden]) { display: inline-block; margin-bottom: 14px; }
  #settings-view[data-page] [data-settings-page]:not(.is-current) { display: none; }
  #settings-view[data-page] .settings-heading, #settings-view[data-page] .page-head { display: none; }
  #settings-view[data-page]:not(.page-in-form) .settings-save { display: none; }
  #settings-view[data-page] .settings-grid { margin-bottom: 0; }
  #settings-view[data-page] .settings-save { margin-top: 14px; }
  .settings-index-group { margin-bottom: 22px; }
  .settings-index-group h2 { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
  .settings-index-group { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
  .settings-index-group h2 { padding: 12px 16px 0; }
  .settings-index button.settings-index-item { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 50px; padding: 0 16px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; text-align: left; font-weight: 600; }
  .settings-index button.settings-index-item:first-of-type { border-top: 0; }
  .settings-index button.settings-index-item::after { content: "›"; color: var(--muted); font-size: 20px; }
}
.entry-drawer { scroll-margin-top: 90px; }
/* In the sheet the kind was chosen behind "+" ("‹ Auswahl" goes back), so the switch is not repeated. */
@media (max-width: 950px) { .entry-drawer .entry-mode-switch { display: none; } }

/* The current glucose in full-screen views (meal chat, entry sheet): a dose decision needs it in sight. */
.glucose-badge { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 10px; border: 1px solid #cddbd2; border-radius: 999px; background: #edf1ee; color: #44564d; white-space: nowrap; }
.glucose-badge strong { font-size: 15px; letter-spacing: -.02em; }
.glucose-badge small { font-size: 11px; font-weight: 650; }
.glucose-badge[data-status="in_range"] { background: #e0f3e7; border-color: #acd9ba; color: #145c38; }
.glucose-badge[data-status="outside"] { background: #fff3ce; border-color: #e9d782; color: #70510b; }
.glucose-badge[data-status="low"] { background: #fde8e7; border-color: #edb4b1; color: #9a2925; }
.glucose-badge[data-status="high"] { background: #ffeddb; border-color: #edc09b; color: #9b4d11; }
.chat-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.chat-empty { margin: auto 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
/* Entry sheet head on one line: back, title, glucose, close. */
@media (max-width: 950px) {
  .entry-drawer-head { justify-content: flex-start; gap: 8px; }
  .entry-drawer-head h2 { flex: 1; min-width: 0; text-align: left; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .entry-drawer-head button#entry-back { font-size: 26px; line-height: 1; padding: 2px 12px 5px; }
}

/* Chat input row: the camera is a label and the mic a button, so both need selectors that beat the global
   label margin and button radius; all three controls share one height and sit on one line. */
.chat-input { align-items: center; }
.chat-input label.round-button, .chat-input button.round-button { margin: 0; width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; }
.chat-input textarea { min-height: 44px; }

/* One header on every page (user request 2026-11-18): on phones the top bar is a single line with the
   logo and the glucose; the entry sheet and the meal chat open below it, so the value stays in sight. */
@media (max-width: 650px) {
  .topbar { flex-wrap: nowrap; min-height: 0; gap: 8px; padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px; }
  .brand strong { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .glucose-widget { order: 0; flex: 1 1 auto; min-width: 0; padding: 5px 10px; }
  .glucose-main { flex-wrap: nowrap; gap: 8px; }
  .glucose-main strong { font-size: 19px; }
  .glucose-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
  .topbar-actions { flex-direction: row; flex: none; }
  .glucose-main span { font-size: 12px; }
  /* The meal chat covers the whole screen with one head that shows the glucose itself, the same from the
     entry form and from a saved meal's card (Philipp 2026-11-19: no second head or close button above it). */
  #agent-dialog { top: 0; height: 100dvh; margin: 0; padding-top: env(safe-area-inset-top, 0px); }
}
@media (max-width: 950px) {
  body.entry-open .entry-drawer { top: var(--topbar-h, 0px); z-index: 40; }
  .entry-drawer-head { padding-top: 10px; }
}
#entry-drawer[data-quick="manual"] .agent-entry { display: none; }

/* "Heute": today's meals in short, a tap opens the meal's card (web/ui/today.js MealsToday). */
.meals-today { min-width: 0; margin: 10px 0 4px; }
.meals-today ul { list-style: none; margin: 5px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.meals-today li + li { border-top: 1px solid var(--line); }
/* Two lines so a long row never widens the page (iPhone report 2026-11-18): time, meal and factor on top,
   carbs and insulin below. */
.meals-today button.meal-today, .meals-today button.meal-today-entry { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto 12px; align-items: baseline; gap: 2px 8px; width: 100%; min-width: 0; min-height: 0; padding: 10px 12px; line-height: 1.3; border: 0; border-radius: 0; background: none; color: var(--ink); text-align: left; font-size: 13px; font-variant-numeric: tabular-nums; }
.meal-today time, .meal-today-entry > time { color: var(--muted); font-weight: 650; }
.meal-today b, .meal-today-entry > b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-today span { grid-column: 2 / 4; grid-row: 2; min-width: 0; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.meal-today small { grid-column: 3; grid-row: 1; color: var(--muted); font-size: 12px; white-space: nowrap; }
.meals-today button.meal-today:hover, .meals-today button.meal-today-entry:hover:not(:disabled) { background: var(--canvas); }
/* A meal unfolds to its single entries (user request 2026-11-20); each opens its card to correct it. */
.meal-today-toggle { grid-column: 4; grid-row: 1 / 3; align-self: center; color: var(--muted); font-style: normal; font-size: 18px; line-height: 1; transition: transform .15s; }
.meal-today[aria-expanded="true"] .meal-today-toggle { transform: rotate(90deg); }
.meals-today ul.meal-today-entries { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: var(--canvas); }
.meals-today ul.meal-today-entries[hidden] { display: none; }
.meals-today button.meal-today-entry { padding: 8px 12px 8px 24px; grid-template-columns: 44px minmax(0, 1fr) auto 12px; }
.meals-today button.meal-today-entry::after { content: "›"; grid-column: 4; grid-row: 1; color: var(--muted); }
.meals-today button.meal-today-entry:disabled { opacity: 1; cursor: default; }
.meals-today button.meal-today-entry:disabled::after { content: none; }
.meal-today-entry > b { font-weight: 600; }
.meal-today-entry > span { grid-column: 3; grid-row: 1; font-weight: 600; white-space: nowrap; }
.meal-today-entry > small { grid-column: 2 / 4; grid-row: 2; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* "Wirkt noch" inside the manual entry: only where the sheet covers "Heute". */
.entry-active { display: none; }
@media (max-width: 950px) { .entry-active { display: block; margin-bottom: 12px; } .entry-active:empty { display: none; } }

/* "+" is a 2 × 2 grid of four tiles (user request 2026-11-18); Essen keeps its green. */
.choices button.choice.main { grid-column: auto; min-height: 96px; }
.choices button.choice { min-height: 96px; }

/* Meal chat, calmer (user report 2026-11-19): photos sit in the message they came with and a sent
   message shows at once; older answers show only their grams. */
.chat-turn { align-self: flex-end; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: 88%; }
.chat-turn .bubble.me { max-width: 100%; }
.chat-turn.pending { opacity: .65; }
.chat-turn-photos { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.chat-turn-photos img { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.bubble.ai.earlier { padding: 6px 12px; font-size: 13px; }
.bubble.ai.earlier > b { font-size: 14px; }
.chat-foot .chat-photos img { width: 56px; height: 56px; border-radius: 8px; }
.chat-head button.chat-close { flex: none; }
@media (max-width: 650px) {
  .chat-title { flex-wrap: nowrap; }
  .chat-head { padding: 10px 16px 8px; }
  .chat-head h2 { font-size: 19px; }
}
.chat-pick { display: flex; flex-direction: column; gap: 10px; }

/* ---- Verlauf (user request 2026-11-23, design B): week strip, meal cards with their curve, sport cards.
   The same quiet cards, chips and rows as "Heute"; sport keeps the chart's violet. ---- */
.history { --sport: #6a4bb3; --sport-light: #f1edfa; --sport-line: #d4c8ee; }
.history-head { margin-bottom: 10px; align-items: center; }
.history-head h2 { font-size: 20px; letter-spacing: -.03em; }
.history button.history-refresh { min-height: 34px; padding: 4px 11px; font-size: 16px; }
.week-strip { display: grid; gap: 6px; margin: 0 0 14px; }
.week-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 700; }
.history .week-head button { min-height: 30px; padding: 2px 12px; font-size: 18px; line-height: 1; }
.week-track { display: flex; margin: 0 -2.5px; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none; }
.week-track::-webkit-scrollbar { display: none; }
.week-panel { flex: 0 0 100%; min-width: 0; padding: 0 2.5px; scroll-snap-align: start; scroll-snap-stop: always; }
.week-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.week-day.is-empty { min-height: 62px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.history button.week-day { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; min-height: 0; padding: 6px 0 5px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--muted); font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; }
.week-day b { color: var(--ink); font-size: 16px; line-height: 1.2; }
.week-day em { font-style: normal; font-size: 9.5px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; min-height: 12px; }
.week-dot { width: 7px; height: 7px; margin: 2px 0 1px; border-radius: 50%; background: transparent; border: 1.5px solid #b9c6bf; }
.week-day[data-state="done"] .week-dot { background: var(--green); border-color: var(--green); }
.week-day[data-state="open"] .week-dot { background: #d9a441; border-color: #d9a441; }
.week-day[data-state="none"] .week-dot { border-color: transparent; }
.week-sport { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 2px; background: var(--sport); text-decoration: none; }
.history button.week-day[aria-current="date"] { border-color: var(--green); background: var(--green-light); }
.history button.week-day:disabled { opacity: .45; cursor: default; }
.history-day-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 10px; }
.history-day-head h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.history-day-head #record-count { flex: 1; }
.history .chip { display: inline-flex; align-items: center; gap: 4px; min-height: 0; padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--canvas); color: var(--ink); font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.history .chip .ui-icon { width: 13px; height: 13px; }
.history .chip.is-ok { background: var(--green-light); border-color: #b9d8c5; color: var(--green-dark); }
.history-day-type { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.history .history-day-type button { min-height: 30px; padding: 3px 12px; border: 0; border-radius: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 700; }
.history .history-day-type button[aria-pressed="true"] { background: var(--green); color: #fff; }
.history-tasks { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.history-tasks a { display: grid; gap: 1px; padding: 8px 12px 8px 28px; position: relative; border: 1px solid #e0c27a; border-radius: 11px; background: var(--amber-light); color: var(--amber); font-size: 12px; text-decoration: none; }
.history-tasks a::before { content: ""; position: absolute; left: 12px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.history-tasks b { color: var(--ink); font-size: 13px; }
.history-previous-sport { margin: 0 0 10px; padding: 7px 12px; border: 1px solid var(--sport-line); border-radius: 11px; background: var(--sport-light); color: var(--sport); font-size: 12px; font-weight: 650; }
.history-list { gap: 10px; }
.history-meal { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 11px 13px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); scroll-margin-top: 90px; }
.history-meal.needs-check { border-color: #e0c27a; box-shadow: inset 3px 0 0 #d9a441; }
.history-meal-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline; }
.history-meal-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
.history-meal-title .meal-type { font-size: 15px; letter-spacing: -.01em; text-transform: none; color: var(--ink); }
.history-meal-title time { color: var(--muted); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.history-factor { color: var(--green-dark); font-size: 17px; font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-factor small { font-size: 10.5px; font-weight: 650; }
.history-factor.is-missing { color: var(--amber); }
.history-meal.is-excluded .history-factor { color: var(--muted); text-decoration: line-through; }
/* Dish names and descriptions can be long (Philipp 2026-11-23): two lines at most, the entry list shows them in full. */
.history-meal-name { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.35; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-meal-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.history-meal-meta > span:first-child { color: var(--ink); font-weight: 600; }
.history .chip.sport-chip { background: var(--sport-light); border-color: var(--sport-line); color: var(--sport); white-space: normal; text-align: left; }
.history button.chip.sport-chip { cursor: pointer; }
.history-task { margin: 0; padding: 6px 10px; border-radius: 9px; background: var(--amber-light); color: var(--amber); font-size: 12px; overflow-wrap: anywhere; }
.history-chart { margin: 0; }
.history-chart .meal-chart-plot { margin: 0 -4px; }
/* One row on every phone (Philipp 2026-11-23: a wrapped "Einträge" looked unaligned); narrow screens say only "Zeitraum". */
.history-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 480px) { .history-actions .wide-only { display: none; } }
.history .history-actions button { min-height: 36px; padding: 6px 8px; font-size: 13px; white-space: nowrap; min-width: 0; justify-content: center; }
.history .history-actions button.history-more-entries { grid-column: 3; }
.history .history-actions button.primary { width: auto; }
.history .history-actions button.window-check.is-checked { display: inline-flex; align-items: center; gap: 5px; background: var(--green-light); border-color: #b9d8c5; color: var(--green-dark); }
.history-actions .ui-icon { width: 15px; height: 15px; }
.history-meal-details { border-top: 1px solid var(--line); padding-top: 6px; display: grid; gap: 6px; }
.history-meal-details[hidden] { display: none; }
.history-entries { list-style: none; margin: 0; padding: 0; }
.history-entries li + li { border-top: 1px solid var(--line); }
.history .history-entry-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: baseline; gap: 2px 8px; width: 100%; min-height: 0; padding: 8px 2px; border: 0; border-radius: 0; background: none; color: var(--ink); text-align: left; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.history .history-entry-row:hover:not(:disabled) { background: var(--canvas); }
.history .history-entry-row:disabled { opacity: 1; cursor: default; }
.history-entry-row time { color: var(--muted); font-weight: 650; }
.history-entry-row b { min-width: 0; font-weight: 650; overflow-wrap: anywhere; }
.history-entry-row > span { font-weight: 650; white-space: nowrap; }
.history-entry-row small { grid-column: 2 / -1; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.history .history-entry-row .delete-treatment { min-height: 30px; padding: 3px 9px; font-size: 12px; }
.history-loose { padding: 2px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.history-calc { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.history-exclude .exclude-meal { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 10px; border-color: #bdd8c5; background: var(--green-light); color: var(--green-dark); font-size: 12px; }
.history-exclude .exclude-meal.is-excluded { background: #f3f4f1; border-color: var(--line); color: var(--muted); }
.history button.history-sport { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: baseline; gap: 4px 8px; width: 100%; min-height: 0; padding: 10px 13px; border: 1px solid var(--sport-line); border-radius: 14px; background: var(--sport-light); color: var(--ink); text-align: left; font-size: 13px; }
.history-sport time { color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; }
.history-sport b { min-width: 0; overflow-wrap: anywhere; }
.history-sport-effect { color: var(--sport); font-weight: 750; white-space: nowrap; }
.history-sport-parts { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 4px; }
.history-sport-parts span { padding: 1px 8px; border: 1px solid var(--sport-line); border-radius: 999px; background: var(--surface); color: var(--sport); font-size: 11.5px; font-weight: 650; }
.history-sport-parts span.is-rest { color: var(--muted); }
.window-chart-svg .sport-band rect { fill: #6a4bb326; }
.window-chart-svg .sport-band rect.is-inside { fill: #6a4bb399; }
@media (max-width: 950px) {
  /* Verlauf picks its day in the week strip; the date row above belongs to "Heute". */
  #diary-view[data-mode="review"] .diary-head { display: none; }
}
@media (max-width: 650px) {
  .history.panel { padding: 14px 12px; }
  .history-meal { padding: 10px 11px 11px; }
}

/* Sport sessions in "Heute" and the shared sport fields (web/ui/sport.js). */
.meals-today button.sport-today small { color: #6a4bb3; font-weight: 700; }
.meals-today button.sport-today span { color: var(--muted); font-weight: 600; }
.sport-shares ul { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
.sport-shares li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; font-size: 13px; }
.sport-shares li + li { border-top: 1px solid var(--line); }
.sport-shares li b { color: #6a4bb3; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sport-shares li.is-rest { color: var(--muted); }
.sport-shares li.is-total { font-weight: 750; }
.sport-shares .hint { margin: 0; }
#entry-sport-effect-field { margin-bottom: 16px; }

/* "Zeitraum anpassen" in the app's light look (Philipp 2026-11-23: the editor works well, it only has to
   match): same events on the time axis, same snapping, the chart on the light plot of the meal cards. */
.window-readout { border-radius: 12px; background: var(--canvas); color: var(--ink); border: 1px solid var(--line); }
.window-readout[data-tone="in-range"] { background: var(--green-light); border-color: #b9d8c5; color: var(--green-dark); }
.window-readout[data-tone="outside"] { background: #fff3ce; border-color: #e9d782; color: #70510b; }
.window-readout[data-tone="low"] { background: #fde8e7; border-color: #edb4b1; color: #9a2925; }
.window-readout[data-tone="high"] { background: #ffeddb; border-color: #edc09b; color: #9b4d11; }
.window-readout .readout-value strong { font-size: 40px; }
.window-readout .readout-trend { font-size: 26px; }
.window-handle-switch { display: flex; gap: 4px; margin: 10px 0 6px; padding: 3px; border-radius: 11px; background: #edf2ee; }
.window-handle-switch button { flex: 1; min-height: 36px; border-radius: 8px !important; color: var(--muted) !important; font-weight: 700; }
.window-handle-switch button[aria-pressed="true"] { background: var(--surface) !important; color: var(--ink) !important; box-shadow: 0 1px 3px #18322922; }
.window-chart { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.window-chart .window-chart-svg { --plot: #fbfcfa; --grid: #e3ebe5; --label: var(--muted); --curve: #267855; --band: #dff0e5; --shade: #17674614; --handle: #0e4b32; --event: #50645b; }
.window-chart .chart-event.carbs path { stroke: #b7791f; }
.window-chart .chart-event.insulin path { stroke: #2f6fa8; }
.window-chart .handle-knob rect { fill: var(--surface); stroke: #8fa69a; }
.window-chart .handle-knob path { stroke: var(--green-dark); }
.window-chart .window-handle.is-active .handle-knob rect { fill: var(--green); stroke: var(--green); }
.window-chart .window-handle.is-active .handle-knob path { stroke: #fff; }
.window-chart .window-handle.is-snapped .handle-line { stroke: #d9a441; }
.window-nudge button { border-radius: 999px !important; }
