/* Mobile-first calm medical palette: soft surface, ample whitespace, accessible
   contrast. Base styles target small screens; min-width media queries layer on
   refinements for larger viewports. */
:root {
    --bg: #f7f9fb;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #475569;
    --primary: #1e6b8a;
    --primary-hover: #155571;
    --primary-tint: #e6f1f6;
    --warn-bg: #fff7ed;
    --warn-border: #fdba74;
    --warn-text: #7c2d12;
    --error: #b91c1c;

    --cat-vegfruit: #22a06b;
    --cat-fats: #d4a017;
    --cat-protein: #c0392b;
    --cat-grains: #b86b2a;
    --cat-drinks: #2563eb;
    --cat-vitamin: #7c3aed;
    --cat-mixed: #475569;

    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tap-min: 44px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.9375rem; }

/* ---- Top bar (mobile-first) ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-weight: 600; color: inherit; text-decoration: none;
    flex: 0 0 auto;
    min-width: 0;
}
.brand-mark {
    width: 22px; height: 22px;
    color: var(--primary);
    flex-shrink: 0;
}
.brand-name {
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0 6px;
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
}
.topbar-link {
    border: 0;
    background: transparent;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}
.topbar-link:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 519px) {
    .brand-name { display: none; }
}
@media (max-width: 379px) {
    .topbar-nav { display: none; }
}

.lang-switch { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.lang-btn {
    border: 0; background: transparent;
    padding: 8px 14px; border-radius: 999px;
    font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); cursor: pointer;
    min-height: 36px;
}
.lang-btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---- Layout (mobile-first) ---- */
.container {
    max-width: 880px;
    margin: 0 auto;
    padding: 18px 14px 84px;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 18px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card h2 {
    margin: 0 0 12px;
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.disclaimer { background: var(--primary-tint); border-color: #cfe3ec; }
.disclaimer h2 { color: var(--primary); }
.disclaimer p { margin: 0; color: #234a5a; font-size: 0.9375rem; }

/* ---- Forms (mobile-first single column) ---- */
.profile-fields, .deviation-form {
    display: grid;
    gap: 14px;
    grid-template-columns: 1fr;
}
.profile-fields .field, .deviation-form .field { display: flex; flex-direction: column; gap: 6px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#profile-form .form-actions { margin-top: 14px; }
.deviation-form .grow { /* grid column irrelevant in single-column mobile */ }

/* Collapsible "Jouw gegevens" using <details> */
.profile-collapse > summary {
    list-style: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    user-select: none;
    min-height: 36px;
}
.profile-collapse > summary::-webkit-details-marker,
.profile-collapse > summary::marker { display: none; }
.profile-summary-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.profile-collapse .chevron {
    color: var(--text-muted);
    transition: transform 0.2s ease-out;
    font-size: 0.875rem;
    line-height: 1;
}
.profile-collapse[open] .chevron { transform: rotate(180deg); }
.profile-collapse[open] > summary { margin-bottom: 14px; }

/* Weight field: masked by default, with a reveal link beside the label. */
.field-label-row {
    display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.reveal-link {
    border: 0; background: transparent;
    color: var(--primary); font: inherit; font-size: 0.8125rem; font-weight: 600;
    cursor: pointer; padding: 4px 6px;
    text-decoration: underline;
    border-radius: 6px;
}
.reveal-link:hover { background: var(--primary-tint); }
.input-masked { -webkit-text-security: disc; text-security: disc; }

label, legend {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
}

input[type="text"], input[type="number"], input[type="date"], input[type="time"], select {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    padding: 12px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    min-height: var(--tap-min);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 107, 138, 0.15);
}

.toggle-group {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    margin: 0;
    display: flex; gap: 6px; flex-wrap: wrap;
}
.toggle-group legend {
    padding: 0 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.toggle-option {
    flex: 1 1 80px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 10px;
    min-height: var(--tap-min);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9375rem;
    transition: background 0.15s, border-color 0.15s;
}
.toggle-option:has(input:checked) {
    background: var(--primary-tint);
    border-color: #cfe3ec;
    color: var(--primary);
    font-weight: 600;
}
.toggle-option input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-option.is-disabled { opacity: 0.5; cursor: not-allowed; background: var(--surface-2); }

.btn {
    border: 0;
    border-radius: 10px;
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-min);
    transition: background 0.15s, color 0.15s, transform 0.05s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-with-icon { padding-left: 14px; }
.btn-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* On mobile, primary form actions go full-width for thumb-reachable taps. */
#profile-form .form-actions .btn,
.deviation-form .form-actions .btn,
.schedule-actions .btn { width: 100%; }

/* ---- Phase summary ---- */
.phase-summary { display: grid; gap: 12px; }
.phase-summary .phase-row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: baseline; }
.phase-pill {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--primary-tint); color: var(--primary);
    padding: 4px 10px; border-radius: 999px; font-size: 0.8125rem; font-weight: 600;
}
.phase-summary dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.phase-summary dt { color: var(--text-muted); font-size: 0.875rem; }
.phase-summary dd { margin: 0; font-size: 0.9375rem; }

/* ---- Warnings ---- */
.warnings { display: flex; flex-direction: column; gap: 10px; }
.warning {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    color: var(--warn-text);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.9375rem;
    display: flex; gap: 10px;
}
.warning::before { content: "⚠"; font-size: 1.1em; }

/* ---- Schedule header ---- */
.schedule-header {
    display: flex; flex-direction: column; align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
}
.schedule-actions { display: flex; gap: 8px; }

/* ---- Date header above the calendar (Maandag, 4 mei 2026) ---- */
.cal-date-header {
    margin: 0 0 12px;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.cal-date-header:empty { display: none; }

/* ---- Calendar (Outlook-style hour grid) ----
   Two-column layout: time gutter on the left, events area on the right.
   Events absolutely positioned within the events area; height proportional
   to duration. Supplements (calcium / multivit) pinned to a thin right rail
   so they don't fight drink windows for horizontal space. */
.calendar {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    overflow: hidden;
    position: relative;
}
.cal-grid {
    display: grid;
    grid-template-columns: 44px 1fr;
    position: relative;
}
.cal-hours {
    position: relative;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.cal-hour {
    position: absolute;
    left: 0; right: 0;
    transform: translateY(-50%);
    text-align: right;
    padding-right: 6px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
    font-weight: 600;
    pointer-events: none;
}
.cal-hour:first-child { transform: translateY(0); }
.cal-hour-line {
    position: absolute;
    left: 0; right: -1px; height: 0;
    border-top: 1px solid var(--border);
    pointer-events: none;
}
.cal-hour-half { border-top-style: dashed; opacity: 0.55; }
.cal-events {
    position: relative;
    background:
        linear-gradient(to bottom, var(--surface) 0, var(--surface) 100%);
    overflow: hidden;
}
.cal-now {
    position: absolute;
    left: 0; right: 0; height: 0;
    border-top: 2px solid var(--error);
    z-index: 5;
    pointer-events: none;
}
.cal-now::before {
    content: "";
    position: absolute;
    left: -4px; top: -5px;
    width: 8px; height: 8px;
    background: var(--error);
    border-radius: 50%;
}
.cal-help { margin: 8px 12px 10px; font-size: 0.8125rem; }

/* Event blocks */
.cal-event {
    position: absolute;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--cat-mixed);
}
.cal-event[data-lane="primary"]    { left: 4px;  right: 44px; }
.cal-event[data-lane="supplement"] { right: 4px; width: 36px; left: auto; }

.cal-event.cat-vegfruit { border-left-color: var(--cat-vegfruit); }
.cal-event.cat-fats     { border-left-color: var(--cat-fats); }
.cal-event.cat-protein  { border-left-color: var(--cat-protein); }
.cal-event.cat-grains   { border-left-color: var(--cat-grains); }
.cal-event.cat-drinks   { border-left-color: var(--cat-drinks); background: rgba(37, 99, 235, 0.06); }
.cal-event.cat-vitamin  { border-left-color: var(--cat-vitamin); }

.cal-event.kind-drink   { background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(37, 99, 235, 0.04)); border-style: dashed; border-left-style: solid; }
.cal-event.is-completed { opacity: 0.55; background: var(--surface-2); }
.cal-event.is-completed .cal-title,
.cal-event.is-completed .cal-time { text-decoration: line-through; }
.cal-event.is-warn      { background: var(--warn-bg); border-color: var(--warn-border); }
.cal-event.is-selected  { box-shadow: 0 0 0 2px var(--primary), 0 1px 2px rgba(15,23,42,0.06); }

.cal-action {
    position: absolute;
    top: 0; bottom: 0;
    display: flex; align-items: center;
    padding: 0 10px;
    color: #fff;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}
.cal-action-right { right: 0; background: var(--primary); justify-content: flex-end; width: 60%; }
.cal-action-left  { left: 0;  background: var(--error);   justify-content: flex-start; width: 60%; }
.cal-event.show-right .cal-action-right { opacity: 1; }
.cal-event.show-left  .cal-action-left  { opacity: 1; }

.cal-event-card {
    position: relative;
    z-index: 1;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    transition: transform 0.2s ease-out;
    will-change: transform;
    touch-action: pan-y;
    user-select: none;
    cursor: pointer;
}
.cal-event-card.is-swiping { transition: none; }

.cal-event-meta {
    position: relative;
    display: flex; flex-direction: column; gap: 2px;
    min-width: 0; flex: 1 1 auto;
    height: 100%;
    justify-content: center;
}
/* Drink moments are short (15 min). Compact the meta so the block stays
   readable at its smaller height. */
.cal-event.kind-drink .cal-event-meta { gap: 0; justify-content: flex-start; padding-top: 2px; }
.cal-event.kind-drink .cal-line-1 { font-size: 0.8125rem; }
.cal-event.kind-drink .cal-time { font-size: 0.75rem; }
.cal-event.kind-drink .cal-title { font-size: 0.8125rem; }
.cal-event.kind-drink .cal-checkbox-box { width: 16px; height: 16px; }
.cal-event.kind-drink .cal-checkbox:checked + .cal-checkbox-box::after { left: 3px; top: 0; width: 4px; height: 9px; }
.cal-line-1 { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.cal-line-2 { font-size: 0.875rem; color: var(--text); font-weight: 600; }
.cal-time   { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.875rem; color: var(--text-muted); flex-shrink: 0; }
.cal-title  { font-weight: 600; font-size: 1rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-portion { font-size: 0.875rem; color: var(--text); font-weight: 600; }

/* Supplement chips (calcium / multivit) */
.cal-event[data-lane="supplement"] .cal-event-card {
    flex-direction: column; align-items: center; padding: 2px;
    justify-content: center;
}
.cal-supp-chip {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--cat-vitamin); color: #fff;
    width: 28px; height: 20px; border-radius: 6px;
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
}
.cal-event.kind-calcium .cal-supp-chip { background: #2563eb; }
.cal-supp-time { font-size: 0.6875rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Checkbox inside calendar block */
.cal-checkbox-wrap {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex: 0 0 auto;
}
.cal-checkbox { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.cal-checkbox-box {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}
.cal-checkbox:checked + .cal-checkbox-box {
    background: var(--primary);
    border-color: var(--primary);
}
.cal-checkbox:checked + .cal-checkbox-box::after {
    content: "";
    position: absolute;
    left: 4px; top: 0;
    width: 5px; height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.cal-checkbox:focus-visible + .cal-checkbox-box {
    box-shadow: 0 0 0 3px rgba(30, 107, 138, 0.25);
}

/* ---- Details popup (rendered inside the details modal body) ---- */
.cal-details-card {
    background: var(--surface);
    border-left: 4px solid var(--cat-mixed);
    padding: 4px 4px 4px 14px;
}
.cal-details-card.cat-vegfruit { border-left-color: var(--cat-vegfruit); }
.cal-details-card.cat-fats     { border-left-color: var(--cat-fats); }
.cal-details-card.cat-protein  { border-left-color: var(--cat-protein); }
.cal-details-card.cat-grains   { border-left-color: var(--cat-grains); }
.cal-details-card.cat-drinks   { border-left-color: var(--cat-drinks); }
.cal-details-card.cat-vitamin  { border-left-color: var(--cat-vitamin); }
.cal-details-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 8px;
}

/* tags + portion + suggestion + note (reused inside details) */
.t-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); font-size: 0.9375rem; }
.t-title { font-weight: 600; font-size: 1rem; }
.t-tags { display: flex; gap: 6px; margin-left: auto; }
.t-tag {
    font-size: 0.6875rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.t-tag.is-liquid { background: #dbeafe; color: #1d4ed8; }
.t-tag.is-solid  { background: #fef3c7; color: #92400e; }
.t-portion { margin-top: 4px; font-size: 0.9375rem; color: var(--text); font-weight: 600; }
.t-suggest { margin-top: 4px; font-size: 0.875rem; color: var(--text-muted); }
.t-note    { margin-top: 6px; font-size: 0.875rem; color: var(--text-muted); font-style: italic; }

/* ---- Deviation log ---- */
.deviation-list {
    list-style: none; padding: 0; margin: 14px 0 0;
    display: flex; flex-direction: column; gap: 6px;
}
.deviation-list li {
    display: flex; gap: 10px; align-items: baseline;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 0.9375rem;
    flex-wrap: wrap;
}
.deviation-list time { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; min-width: 70px; }
.deviation-list .dev-remove {
    margin-left: auto;
    border: 0; background: transparent; cursor: pointer;
    color: var(--text-muted); font-size: 1.125rem; padding: 4px 8px;
    min-width: var(--tap-min); min-height: var(--tap-min);
}
.deviation-list .dev-remove:hover { color: var(--error); }
.deviation-list li.is-dumping { background: #fef2f2; border: 1px solid #fecaca; }
.dev-tag {
    font-size: 0.6875rem;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.dev-tag.is-dumping { background: var(--error); color: #fff; }

.footnote { color: var(--text-muted); font-size: 0.8125rem; text-align: center; padding: 12px; }
.footnote p { margin: 0; }

/* ---- Modal overlay + iOS-style minute scrollwheel ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.modal-overlay[hidden] { display: none; }
body.modal-open { overflow: hidden; }

.modal-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
    padding: 20px;
    display: flex; flex-direction: column; gap: 14px;
    animation: modal-in 0.18s ease-out;
    position: relative;
}
.details-modal-card {
    max-width: 480px;
    max-height: calc(100vh - 32px);
}
.modal-body {
    overflow-y: auto;
    margin: 0 -4px;
    padding: 0 4px;
    flex: 1 1 auto;
}
.modal-close {
    position: absolute;
    top: 8px; right: 8px;
    width: 36px; height: 36px;
    border: 0; background: transparent;
    color: var(--text-muted);
    font-size: 1.5rem; line-height: 1; cursor: pointer;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
@keyframes modal-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-title { margin: 0; font-size: 1.125rem; font-weight: 600; }
.modal-subtitle { margin: 0; }
.modal-actions {
    display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 4px;
}
.modal-actions .btn { min-width: 110px; }

.wheel-frame {
    position: relative;
    height: 220px;
    border-radius: 12px;
    background: var(--surface-2);
    overflow: hidden;
}
.wheel {
    height: 100%;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* top / bottom padding so the first and last items can scroll into the
       center band (band sits at y = 88..132 in a 220px frame). */
    padding: 88px 0;
    box-sizing: border-box;
    text-align: center;
    outline: none;
}
.wheel::-webkit-scrollbar { display: none; }
.wheel-item {
    height: 44px;
    line-height: 44px;
    scroll-snap-align: center;
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-weight: 600;
    transition: color 0.15s, transform 0.15s;
}
.wheel-item.is-active {
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
    transform: scale(1.05);
}

/* Highlighted band in the middle of the wheel */
.wheel-band {
    position: absolute;
    left: 8px; right: 8px;
    top: 50%;
    transform: translateY(-50%);
    height: 44px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    pointer-events: none;
}

/* Top and bottom fades so off-band items recede visually */
.wheel-fade {
    position: absolute;
    left: 0; right: 0; height: 60px;
    pointer-events: none;
    z-index: 2;
}
.wheel-fade-top    { top: 0;    background: linear-gradient(to bottom, var(--surface-2), rgba(241, 245, 249, 0)); }
.wheel-fade-bottom { bottom: 0; background: linear-gradient(to top,    var(--surface-2), rgba(241, 245, 249, 0)); }

.wheel-unit {
    position: absolute;
    top: 50%;
    right: 18px;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 3;
}

/* ---- Details modal: stacked header / body / swipe footer / meds footer ---- */
.details-modal-card {
    max-width: 480px;
    max-height: calc(100vh - 32px);
    padding: 0;
    gap: 0;
    overflow: hidden;
}
.details-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--cat-mixed);
    color: #fff;
}
.details-header.cat-vegfruit { background: var(--cat-vegfruit); }
.details-header.cat-fats     { background: var(--cat-fats); }
.details-header.cat-protein  { background: var(--cat-protein); }
.details-header.cat-grains   { background: var(--cat-grains); }
.details-header.cat-drinks   { background: var(--cat-drinks); }
.details-header.cat-vitamin  { background: var(--cat-vitamin); }
.details-header-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}
.details-header-time {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.8125rem;
}
.details-header-title {
    font-weight: 600;
    font-size: 1.0625rem;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.details-header-close {
    width: 36px; height: 36px;
    border: 0; background: transparent;
    color: #fff;
    font-size: 1.5rem; line-height: 1;
    cursor: pointer;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.details-header-close:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.details-body {
    padding: 14px 16px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
}
.details-footer {
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    background: var(--surface);
}
.details-footer[hidden] { display: none; }
.details-footer-swipe {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.details-swipe {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 12px;
    min-height: var(--tap-min);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.details-swipe.is-left:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--error);
}
.details-swipe.is-right:hover {
    background: var(--primary-tint);
    border-color: #cfe3ec;
    color: var(--primary);
}
.details-swipe-arrow { font-size: 1rem; line-height: 1; }
.details-footer-meds { background: var(--surface-2); }
.details-footer-meds:empty { display: none; }

.t-section-head {
    margin: 14px 0 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.cal-details-card .t-section-head:first-child { margin-top: 0; }
.cal-details-card .t-tags { margin-left: 0; margin-bottom: 8px; }
.cal-details-card .t-portion { margin-bottom: 4px; }

.details-meds-empty { margin: 0; font-size: 0.875rem; }
.details-meds-list {
    list-style: none; padding: 0; margin: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.details-meds-row {
    display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.875rem;
}
.details-meds-row.kind-calcium { border-left-color: #2563eb; }
.details-meds-row.kind-vitamin { border-left-color: var(--cat-vitamin); }
.details-meds-time { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; }
.details-meds-title { font-weight: 600; }
.details-meds-portion { font-weight: 600; color: var(--text); }
.details-meds-note { color: var(--text-muted); font-size: 0.8125rem; flex-basis: 100%; }

/* ---- Macros bar (per-meal recommended split) ---- */
.macros { margin-top: 4px; }
.macros-bar {
    display: flex;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-2);
    margin-bottom: 8px;
}
.macros-seg { display: block; height: 100%; min-width: 4px; }
.macros-seg.is-protein { background: var(--cat-protein); }
.macros-seg.is-carbs   { background: var(--cat-grains); }
.macros-seg.is-fats    { background: var(--cat-fats); }
.macros-legend {
    list-style: none;
    padding: 0; margin: 0;
    display: flex; flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.macros-legend li { display: inline-flex; align-items: center; gap: 6px; }
.macros-legend strong { color: var(--text); font-weight: 700; }
.macros-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.macros-dot.is-protein { background: var(--cat-protein); }
.macros-dot.is-carbs   { background: var(--cat-grains); }
.macros-dot.is-fats    { background: var(--cat-fats); }

/* ---- Cookie consent banner ---- */
.cookie-banner {
    position: fixed;
    left: 12px; right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 90;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: modal-in 0.18s ease-out;
}
.cookie-banner[hidden] { display: none; }
.cookie-text { margin: 0; font-size: 0.9375rem; color: var(--text); }
.cookie-actions {
    display: flex; gap: 8px; justify-content: flex-end;
}
.cookie-actions .btn { min-width: 110px; }

/* ---- Tour walkthrough (highlight-and-explain overlay) ----
   The overlay dims the page; the active step's target is lifted above the
   dim via z-index + outline so it stands out. The card sits at the bottom
   on phones (highlighted target stays visible above), centered on desktop. */
.tour {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.tour[hidden] { display: none; }
.tour-card {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: 16px;
    padding: 18px 20px 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
    animation: modal-in 0.18s ease-out;
    position: relative;
    z-index: 202;
}
.tour-step {
    margin: 0 0 4px;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}
.tour-title {
    margin: 0 0 6px;
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.tour-text {
    margin: 0 0 14px;
    font-size: 0.9375rem;
    color: var(--text-muted);
}
.tour-actions { display: flex; gap: 8px; }
.tour-actions #tour-skip { margin-right: auto; }
.tour-actions .btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tour-highlight {
    position: relative;
    z-index: 201;
    outline: 3px solid var(--primary);
    outline-offset: 4px;
    border-radius: 12px;
    box-shadow: 0 0 0 4px rgba(30, 107, 138, 0.18);
    transition: outline 0.18s, box-shadow 0.18s;
}

/* Wide viewports: dock the card to the right gutter alongside the centered
   container (Word-style "Comments" pane). The right offset is computed so
   the card always sits 20px to the right of the 920px-wide container outer
   edge — `calc(50vw - 720px)` = (viewport/2 + 460 [container right edge])
   plus 20px gap plus 240px card width, expressed as a `right` value. The
   1480px @media threshold guarantees the offset never falls below the 20px
   minimum, so the card never overlaps any section inside .container. */
@media (min-width: 1480px) {
    .tour {
        align-items: stretch;
        justify-content: flex-end;
        padding: 0;
    }
    .tour-card {
        position: fixed;
        top: 80px;
        bottom: 24px;
        right: max(20px, calc(50vw - 720px));
        width: 240px;
        max-width: 240px;
        max-height: calc(100vh - 104px);
        margin: 0;
        padding: 16px 18px;
        border-radius: 14px;
        border: 1px solid var(--border);
        overflow-y: auto;
        animation: tour-slide-in 0.22s ease-out;
    }
    .tour-card::before {
        content: "";
        position: absolute;
        left: -10px;
        top: 22px;
        width: 0; height: 0;
        border-top: 8px solid transparent;
        border-bottom: 8px solid transparent;
        border-right: 10px solid var(--surface);
        filter: drop-shadow(-1px 0 0 var(--border));
    }
    .tour-step { font-size: 0.625rem; }
    .tour-title { font-size: 1rem; }
    .tour-text { font-size: 0.875rem; }
    .tour-actions { flex-wrap: wrap; gap: 6px; }
    .tour-actions .btn { padding: 8px 12px; font-size: 0.8125rem; min-width: 0; }
}

@keyframes tour-slide-in {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---- Tablet / desktop progressive enhancements ---- */
@media (min-width: 640px) {
    .container { padding: 24px 20px 72px; gap: 22px; }
    .card { padding: 26px; border-radius: 14px; }
    .card h2 { margin: 0 0 16px; font-size: 1.125rem; }
    .topbar { padding: 14px 20px; }

    .profile-fields, .deviation-form { grid-template-columns: 1fr 1fr; }
    .deviation-form .grow { grid-column: 1 / -1; }
    .profile-fields .field-portion-group { grid-column: 1 / -1; }

    /* Buttons size to content again on wider viewports */
    #profile-form .form-actions .btn,
    .deviation-form .form-actions .btn,
    .schedule-actions .btn { width: auto; }

    .schedule-header {
        flex-direction: row; align-items: center; justify-content: space-between;
        gap: 12px; flex-wrap: wrap;
    }

    /* Wider calendar gutters and supplement rail */
    .cal-grid { grid-template-columns: 56px 1fr; }
    .cal-event[data-lane="primary"]    { left: 6px;  right: 56px; }
    .cal-event[data-lane="supplement"] { right: 6px; width: 44px; }
    .cal-supp-chip { width: 32px; height: 22px; }

    .cal-title  { font-size: 1rem; }
    .cal-time   { font-size: 0.875rem; }

    .cookie-banner {
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        max-width: 560px;
        width: calc(100% - 32px);
        flex-direction: row;
        align-items: center;
    }
    .cookie-text { flex: 1 1 auto; }
    .cookie-actions { justify-content: flex-end; flex-shrink: 0; }

    .tour {
        align-items: center;
    }
}

@media (min-width: 960px) {
    .container { padding: 24px 20px 72px; }
    .cal-grid { grid-template-columns: 64px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
