/* Meal Mate styles */

:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #17181c;
    --muted: #64707e;
    --line: #e7e9ee;
    --radius: 12px;
    --danger: #dc2626;
    --warn: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(23, 24, 28, 0.05);
    --shadow-md: 0 10px 30px rgba(23, 24, 28, 0.07), 0 2px 6px rgba(23, 24, 28, 0.04);
    font-size: 16px;

    /* Accent system — repainted per active profile via body[data-user].
       Alex = burgundy, Kris = purple (both palette-validated). */
    --accent: #9b2242;
    --accent-strong: #851d39;
    --accent-bright: #d4577c;
    --accent-soft: rgba(155, 34, 66, 0.08);
    --accent-glow: rgba(155, 34, 66, 0.16);
    --ring-track: #f2e7eb;
    --ring-inner: #fdfafb;
}

body[data-user="kris"] {
    --accent: #7c3aed;
    --accent-strong: #6d28d9;
    --accent-bright: #a78bfa;
    --accent-soft: rgba(124, 58, 237, 0.08);
    --accent-glow: rgba(124, 58, 237, 0.17);
    --ring-track: #ece7f6;
    --ring-inner: #fbfaff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    line-height: 1.45;
}

.hidden { display: none !important; }

/* -- Header ---------------------------------------------------------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.82);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand-logo { height: 30px; width: auto; display: block; }
@media (max-width: 560px) { .brand-logo { height: 26px; } }

#user-select {
    font-size: 0.95rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 650;
    transition: background 0.25s ease, color 0.25s ease;
}

.tabs, .subtabs { display: flex; gap: 0.25rem; }

.tab-btn, .subtab-btn {
    border: none;
    background: transparent;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--muted);
    cursor: pointer;
}

.tab-btn.active, .subtab-btn.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.subtabs { margin-bottom: 1rem; }

.foods-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.foods-toolbar .subtabs { margin-bottom: 0; }
.foods-toolbar { margin-bottom: 1rem; }
#foods-filter {
    flex: 1;
    min-width: 180px;
    max-width: 340px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
}
#foods-filter:focus { outline: none; border-color: var(--accent); }
.subtab-btn.active { background: var(--accent-soft); color: var(--accent); }

/* -- Layout ------------------------------------------------------------ */

.tab-panel {
    max-width: 760px;
    margin: 0 auto;
    padding: 1rem;
}

#home-tab {
    max-width: 1100px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}
.section-head h2 { margin: 0.25rem 0 0.75rem; font-size: 1.1rem; }

.state {
    background: var(--panel);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
    color: var(--muted);
    text-align: center;
}

/* -- Home grid ----------------------------------------------------------- */

.home-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.home-box {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background: linear-gradient(150deg, #ffffff 0%, #fafafc 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 156px;
    padding: 1rem 1.1rem;
    display: grid;
    grid-template-columns: minmax(92px, 34%) 1fr;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: var(--ink);
    box-shadow: 0 10px 26px rgba(23, 24, 28, 0.1);
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.home-box::after {
    content: "";
    position: absolute;
    inset: auto -32px -54px auto;
    width: 150px;
    height: 150px;
    border-radius: 999px;
    background: var(--accent-soft);
    z-index: -1;
}

.home-box:hover,
.home-box:focus-visible {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    outline: none;
}

.home-box.active-slot {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--accent-soft) 0%, #ffffff 78%);
    box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-md);
}

.home-box-art {
    display: block;
    width: 100%;
    aspect-ratio: 11 / 8;
    min-width: 92px;
    max-width: 150px;
    justify-self: center;
}

.home-box-art img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 8px 18px rgba(23, 24, 28, 0.1);
}

.home-box-copy {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.home-box .home-box-title {
    display: block;
    font-size: 1.18rem;
    font-weight: 750;
    line-height: 1.12;
}

.home-box .home-box-sub {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.home-box.today-box {
    grid-column: 1 / -1;
    grid-template-columns: minmax(116px, 20%) 1fr;
    background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 62%, var(--accent-bright) 135%);
    border-color: transparent;
    color: #fff;
}

.home-box.today-box::after {
    background: rgba(255, 255, 255, 0.14);
    width: 220px;
    height: 220px;
}

.home-box.today-box .home-box-art {
    max-width: 176px;
}

.home-box.today-box .home-box-title {
    color: #fff;
}

.home-box.today-box .home-box-sub {
    color: rgba(255, 255, 255, 0.86);
}

.label-row { gap: 0.4rem 0.9rem; }
.label-row label {
    flex-direction: row !important;
    align-items: center;
    gap: 0.3rem !important;
    font-size: 0.85rem !important;
    color: var(--ink) !important;
}

.label-chip {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 5px;
    padding: 0.1rem 0.4rem;
    margin-right: 0.25rem;
}

/* -- Mood cartoon (Today) ----------------------------------------------------- */

.calorie-hero-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.mood-cartoon {
    width: clamp(78px, 22vw, 124px);
    height: auto;
    flex-shrink: 0;
    animation: mood-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes mood-pop {
    0% { opacity: 0; transform: scale(0.8) translateY(6px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
/* Beside the cartoon the ring shrinks a touch so both fit on a phone. */
.calorie-hero-row .calorie-ring-wrap { width: min(190px, 46vw); }

.mood-toggle {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 26px;
    height: 26px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    font-size: 0.8rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s ease, border-color 0.15s ease;
    z-index: 2;
}
.mood-toggle:hover { opacity: 1; border-color: var(--accent); }

/* -- Date nav / totals -------------------------------------------------- */

.date-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.date-nav button {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 50%;
    width: 2.1rem;
    height: 2.1rem;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--ink);
}

.date-nav > div { display: flex; align-items: center; gap: 0.5rem; }
#day-input { border: none; background: transparent; font-size: 1rem; color: var(--ink); }
#day-label { color: var(--muted); font-size: 0.9rem; }

.totals-bar {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.95rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1.35rem 1.25rem 1.2rem;
    margin-bottom: 1.15rem;
    box-shadow: 0 14px 34px rgba(23, 24, 28, 0.1);
}

.totals-bar::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 50%;
    width: min(420px, 80%);
    height: 170px;
    border-radius: 0 0 999px 999px;
    background: linear-gradient(180deg, var(--accent-soft), transparent);
    transform: translateX(-50%);
    pointer-events: none;
}

.calorie-hero,
.macro-totals,
.micro-totals {
    position: relative;
}

.calorie-hero {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    color: var(--ink);
}

.calorie-value {
    font-family: "SF Pro Display", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: clamp(3.8rem, 11vw, 6.4rem);
    font-weight: 800;
    letter-spacing: 0;
    line-height: 0.92;
    font-variant-numeric: tabular-nums;
}

.calorie-label {
    color: var(--accent);
    font-size: clamp(1rem, 2.2vw, 1.25rem);
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.macro-totals {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(620px, 100%);
    gap: 0.65rem;
}

.macro-total.clickable { cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease; }
.macro-total.clickable:hover { border-color: var(--accent); background: var(--accent-soft); }

.nutrient-breakdown { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.6rem; }
.nb-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "head head" "bar pct"; column-gap: 0.6rem; row-gap: 0.25rem; align-items: center; }
.nb-head { grid-area: head; display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.95rem; }
.nb-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-value { font-weight: 700; white-space: nowrap; }
.nb-bar { grid-area: bar; height: 8px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.nb-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.nb-pct { grid-area: pct; color: var(--muted); font-size: 0.82rem; min-width: 34px; text-align: right; }

.macro-total {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 72px;
    padding: 0.7rem 0.85rem;
    border: 1px solid rgba(221, 228, 222, 0.8);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.macro-value {
    color: var(--ink);
    font-size: 1.42rem;
    font-weight: 780;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.macro-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.micro-totals {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 650;
    text-align: center;
}

.total-cell { text-align: center; }
.total-cell .value { font-size: 1.15rem; font-weight: 700; }
.total-cell .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* -- Calorie ring / targets ------------------------------------------------ */

.icon-btn { padding: 0.35rem 0.55rem; font-size: 0.95rem; }

.calorie-ring-wrap {
    position: relative;
    width: min(250px, 66vw);
    aspect-ratio: 1;
    margin: 0.25rem auto 0.5rem;
}
.kcal-ring { position: absolute; inset: 0; width: 100%; height: 100%; }

.ring-inner { fill: var(--ring-inner); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 13; }

.ring-fill {
    fill: none;
    stroke-width: 13;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.9s cubic-bezier(0.33, 1, 0.68, 1);
    filter: drop-shadow(0 1px 3px var(--accent-glow));
}
.ring-over { filter: drop-shadow(0 1px 3px rgba(220, 38, 38, 0.25)); }

.ring-dot {
    stroke: var(--panel);
    stroke-width: 3;
    opacity: 0;
    transition: opacity 0.35s ease 0.75s;
    filter: drop-shadow(0 1px 3px rgba(20, 40, 30, 0.25));
}
.ring-dot-in { opacity: 1; }

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    text-align: center;
    padding: 0 18%;
}
.ringed-value {
    font-size: clamp(2.4rem, 8vw, 3.3rem) !important;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--ink);
}
.ring-unit {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}
.calorie-ring-wrap .target-note {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}
.over-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--warn), var(--danger));
    flex-shrink: 0;
}

.targets-form .row label { flex: 1; }
.targets-form input { width: 100%; margin-top: 0.2rem; }

/* -- Collapsible slots ------------------------------------------------------- */

.slot-header { cursor: pointer; user-select: none; }
.slot-header .slot-right { display: flex; align-items: center; gap: 0.6rem; }
.slot-header .chevron { color: var(--muted); font-size: 0.72rem; }
.slot.collapsed .entry { display: none; }
.slot.collapsed .entry-breakdown { display: none; }
.slot.collapsed .slot-header { border-bottom: none; }

/* -- Food focus flash ---------------------------------------------------------- */

@keyframes flash-highlight {
    0% { box-shadow: 0 0 0 3px var(--accent); }
    100% { box-shadow: 0 0 0 3px transparent; }
}
.flash-highlight { animation: flash-highlight 1.6s ease-out 1; }

/* -- Search / quick add ------------------------------------------------- */

.add-entry { display: flex; gap: 0.5rem; align-items: flex-start; margin-bottom: 0.75rem; }
.search-box { position: relative; flex: 1; }

#food-search {
    width: 100%;
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.search-filter {
    display: flex;
    flex: 0 0 auto;
    gap: 0.2rem;
    padding: 0.18rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.68);
}

.search-filter-btn {
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.62rem 0.72rem;
    white-space: nowrap;
}

.search-filter-btn:hover,
.search-filter-btn:focus-visible {
    color: var(--accent);
    outline: none;
}

.search-filter-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 5px 12px var(--accent-glow);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 22px rgba(20, 40, 30, 0.12);
    max-height: 310px;
    overflow-y: auto;
    z-index: 30;
}

.search-result {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: none;
    border-bottom: 1px solid var(--line);
    background: transparent;
    text-align: left;
    font-size: 0.95rem;
    cursor: pointer;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:focus { background: var(--accent-soft); }
.search-result .meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.search-result .kind { color: var(--accent); font-size: 0.75rem; text-transform: uppercase; margin-right: 0.35rem; }

/* -- Forms --------------------------------------------------------------- */

.inline-form {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.9rem;
    margin-bottom: 1rem;
}

.inline-form-title { font-weight: 600; margin-bottom: 0.6rem; }
.inline-form-title.small { font-size: 0.85rem; color: var(--muted); margin-top: 0.4rem; }

.log-form-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}
.log-details-toggle { display: none; flex-shrink: 0; }

.row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.6rem; align-items: flex-end; }
.row:last-child { margin-bottom: 0; }
.row label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.row label.grow { flex: 1; }

.row input, .row select {
    padding: 0.45rem 0.55rem;
    font-size: 0.95rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    min-width: 0;
}

.nutrient-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.nutrient-grid label, .nutrient-grid input { min-width: 0; width: 100%; }

button.primary {
    background: var(--accent-strong);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.55rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm), 0 0 0 0 var(--accent-glow);
    transition: box-shadow 0.2s ease, transform 0.15s ease, background 0.2s ease;
}
button.primary:hover { background: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-md); }
button.primary:active { transform: translateY(0); }
button.primary.logged-ok { background: #16a34a; box-shadow: var(--shadow-sm); }
button.primary.logged-ok:hover { background: #16a34a; transform: none; }

button.ghost {
    background: var(--panel);
    color: var(--accent);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.2s ease, background 0.2s ease;
}
button.ghost:hover { border-color: var(--accent); background: var(--accent-soft); }

button.ghost.small {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
}

button.danger { color: var(--danger); }

/* -- Slots / entries ------------------------------------------------------ */

.slot {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.slot-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.55rem 0.9rem;
    background: #fafafc;
    border-bottom: 1px solid var(--line);
}

.slot-header h3 { margin: 0; font-size: 0.95rem; }
.slot-header .slot-kcal { color: var(--muted); font-size: 0.85rem; }
.slot.empty .slot-header { border-bottom: none; }

.entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.92rem;
}
.entry:last-child { border-bottom: none; }

.entry .entry-main { flex: 1; min-width: 0; }
.entry .entry-name { font-weight: 500; }
.entry .entry-name.clickable-title { display: inline-block; width: fit-content; max-width: 100%; }
.entry .entry-meta { color: var(--muted); font-size: 0.8rem; }
.entry .entry-kcal { font-weight: 600; white-space: nowrap; }

.entry-actions { display: flex; gap: 0.25rem; }
.entry-actions button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--muted);
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
}
.entry-actions button:hover { background: var(--accent-soft); color: var(--accent); }
.entry-actions button.delete:hover { background: rgba(220, 38, 38, 0.08); color: var(--danger); }
.entry-actions button.copy-today { font-size: 1rem; line-height: 1; }
.entry-actions button.copied { color: #16a34a; background: rgba(22, 163, 74, 0.10); }

.entry-breakdown {
    padding: 0.25rem 0.9rem 0.6rem 2rem;
    border-bottom: 1px solid var(--line);
    background: #fafafc;
}
.entry-breakdown:last-child { border-bottom: none; }
.entry-breakdown .breakdown-line {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: var(--muted);
    padding: 0.12rem 0;
}
.entry-breakdown .breakdown-line .bname { color: var(--ink); }
.entry.expandable { cursor: pointer; }

/* -- Cards (history, foods) ----------------------------------------------- */

.card-list { display: flex; flex-direction: column; gap: 0.6rem; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    box-shadow: var(--shadow-sm);
}

.form-toggle { margin-bottom: 0.75rem; }

.thumb-gallery { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.thumb-wrap { position: relative; }

.thumb {
    width: 64px;
    height: 64px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: block;
}

.thumb-cover-badge,
.thumb-make-cover {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--panel);
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.thumb-cover-badge { color: var(--accent); border-color: var(--accent); }

.nutrition-source { margin: 0.65rem 0; font-size: 0.9rem; font-weight: 600; }
.nutrition-warning { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem;
    margin: 0.65rem 0; padding: 0.7rem; border: 1px solid var(--warn);
    border-radius: 0.5rem; background: #fff8e6; color: #463400; }
.nutrition-review-link { display: inline-block; margin: 0.4rem 0.4rem 0 0; }
.thumb-make-cover { color: var(--muted); cursor: pointer; }
.thumb-make-cover:hover { color: var(--accent); border-color: var(--accent); }

.thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--danger);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.card .card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.card .card-title { font-weight: 600; }
.card .card-sub { color: var(--muted); font-size: 0.82rem; }
.card .macro-line { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.card .card-actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }
.card .card-actions button { font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--accent); }
.card.archived { opacity: 0.6; }

.history-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--accent-soft);
    margin-top: 0.45rem;
    overflow: hidden;
}
.history-bar > div { height: 100%; background: var(--accent); }

/* -- Food grid (Foods tab) ---------------------------------------------------- */

.food-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 0.6rem;
}
.food-grid .state { grid-column: 1 / -1; }

.food-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.food-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}
.food-card.archived { opacity: 0.55; }

.food-cover {
    aspect-ratio: 1;
    background: linear-gradient(150deg, var(--accent-soft), #fafafc);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.food-cover img {
    width: 100%;
    height: 100%;
    /* Never crop product shots; letterbox on white instead. */
    object-fit: contain;
    background: #fff;
    display: block;
}
.food-cover-placeholder {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    opacity: 0.55;
}

.food-card-body { padding: 0.45rem 0.55rem 0.55rem; }
.food-card-name {
    font-size: 0.78rem;
    font-weight: 650;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2em;
}
.food-kcal { font-size: 0.82rem; font-weight: 700; margin-top: 0.2rem; }
.food-pcf { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.food-card-unit {
    font-size: 0.58rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 0.2rem;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1.1rem;
}
/* Secondary actions share the row evenly and wrap cleanly. */
.detail-actions > button,
.detail-actions > label {
    flex: 1 1 auto;
    min-width: 96px;
    text-align: center;
    justify-content: center;
}
/* The primary "Log to today" is the hero action: full-width own row. */
.detail-actions > .primary {
    flex-basis: 100%;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    margin-bottom: 0.15rem;
}

.detail-list-panel {
    margin-top: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    background: #fafafc;
}
.detail-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.3rem 0.1rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.9rem;
}
.detail-list-row:last-of-type { border-bottom: none; }
.detail-list-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-list-in { color: var(--accent); font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.ghost.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.detail-list-new { margin-top: 0.5rem; width: 100%; }
.detail-list-empty, .detail-list-loading { color: var(--muted); font-size: 0.85rem; padding: 0.3rem 0.1rem; }

/* Compact variant: home-slot quick-entry suggestions. */
.food-card.mini .food-card-name { min-height: auto; }

/* Items inside an expanded list: nested mini grid with corner remove. */
.list-item-grid { margin-bottom: 0.75rem; }
.food-card { position: relative; }
.tile-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    color: var(--danger);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.tile-remove:hover { border-color: var(--danger); }

/* Lists as a grid: expanded list spans the full row. */
/* List tiles run ~25% larger than food tiles (the nested list-item-grid
   keeps the compact food sizing). */
.list-grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 0.75rem; }
.list-grid > .food-card .food-card-name { font-size: 0.92rem; }
.list-grid > .food-card .food-pcf { font-size: 0.78rem; }
.list-grid .food-card .food-cover { aspect-ratio: 4 / 3; }
.list-grid .list-expanded {
    grid-column: 1 / -1;
    cursor: default;
}
.list-grid .list-expanded:hover { transform: none; border-color: var(--line); box-shadow: var(--shadow-sm); }

/* -- Dish composer ---------------------------------------------------------- */

.component-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    padding: 0.25rem 0;
}
.component-line .meta { color: var(--muted); font-size: 0.8rem; }
.composer-row { display: flex; gap: 0.4rem; margin-top: 0.5rem; align-items: center; flex-wrap: wrap; }
.composer-row select, .composer-row input {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.85rem;
}
.composer-row input { width: 5.5rem; }

/* -- Detail modal ---------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 25, 0.45); }
.modal-card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    max-width: 560px;
    width: calc(100vw - 2rem);
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.1rem 1.2rem;
    box-shadow: 0 16px 44px rgba(15, 30, 22, 0.25);
}
.modal-card:focus { outline: none; }
.modal-close {
    position: absolute;
    top: 0.6rem;
    right: 0.7rem;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
}
.modal-card h2 { margin: 0 0 0.15rem; font-size: 1.15rem; padding-right: 1.5rem; }
.modal-card .detail-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
.modal-card h3 { margin: 1rem 0 0.4rem; font-size: 0.9rem; }

.nutrient-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.nutrient-table td { padding: 0.3rem 0.2rem; border-bottom: 1px solid var(--line); }
.nutrient-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.nutrient-table tr.core td { font-weight: 600; }
.nutrient-table tr:last-child td { border-bottom: none; }

.detail-component {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.88rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--line);
}
.detail-component:last-child { border-bottom: none; }
.detail-component .meta { color: var(--muted); font-variant-numeric: tabular-nums; }

#detail-notes {
    width: 100%;
    min-height: 4.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    padding: 0.5rem 0.6rem;
    resize: vertical;
}
.detail-notes-row { display: flex; justify-content: flex-end; margin-top: 0.4rem; }

.clickable-title { cursor: pointer; }
.clickable-title:hover { color: var(--accent); text-decoration: underline; }

/* -- Log-form component adjusters --------------------------------------------------- */

.log-components { border-top: 1px dashed var(--line); padding-top: 0.6rem; margin-bottom: 0.6rem; }
.log-components-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.45rem;
}
.log-components-head .inline-form-title { margin-bottom: 0; }
.log-component-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    font-size: 0.88rem;
    padding: 0.2rem 0;
}
.log-component-row input {
    width: 5rem;
    padding: 0.3rem 0.45rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.88rem;
    text-align: right;
}
.log-component-row .unit { color: var(--muted); font-size: 0.8rem; min-width: 4.5rem; }
.log-component-row .comp-name { flex: 1; }
.log-component-row .comp-kcal {
    color: var(--ink);
    font-size: 0.82rem;
    font-weight: 700;
    min-width: 4.3rem;
    text-align: right;
}
.log-components.customized + .live-total {
    border-color: var(--accent-glow);
    background: var(--accent-soft);
}
#log-quantity:disabled,
#log-unit:disabled {
    background: #f2f3f5;
    color: var(--muted);
}

.live-total {
    background: var(--accent-soft);
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--accent);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 0.45rem 0.7rem;
    margin-bottom: 0.6rem;
}

/* -- Lists ----------------------------------------------------------------------- */

.list-header { display: flex; align-items: center; gap: 0.75rem; cursor: pointer; }
.list-header .list-thumb {
    width: 44px;
    height: 44px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--line);
    flex-shrink: 0;
}
.list-header .list-head-main { flex: 1; min-width: 0; }
.list-header .chevron { color: var(--muted); font-size: 0.8rem; }

.list-body { border-top: 1px solid var(--line); margin-top: 0.6rem; padding-top: 0.6rem; }

.list-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.3rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--line);
}
.list-item-row:last-of-type { border-bottom: none; }
.list-item-row .kind-chip {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 5px;
    padding: 0.1rem 0.4rem;
}
.list-item-row .meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.list-item-row .item-name { flex: 1; min-width: 0; }
.list-item-row .item-name.archived-item { opacity: 0.6; text-decoration: line-through; }

.list-add-box { position: relative; margin-top: 0.6rem; }
.list-add-box input {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.9rem;
}
.list-add-results {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 220px;
    overflow-y: auto;
}

/* -- Analytics ---------------------------------------------------------------- */

.analytics-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.analytics-controls input {
    width: 4rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: right;
    margin-left: 0.3rem;
}
.analytics-controls select {
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--panel);
}

.chart-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.9rem 1rem 0.6rem;
    margin-bottom: 1rem;
}
.chart-card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.macro-toggle { display: inline-flex; gap: 0.3rem; margin: 0 0 0.6rem; flex-wrap: wrap; }
.macro-btn {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.macro-btn:hover { border-color: var(--accent); color: var(--accent); }
.macro-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.weight-range-control { margin: 0.1rem 0 0.45rem; }

/* -- Monthly report ------------------------------------------------------- */
.mreport-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    margin-bottom: 0.8rem;
}
.mreport-head h3 { margin: 0; min-width: 0; }
.mreport-head input[type="month"] {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    font: inherit;
    color: var(--ink);
    background: var(--panel);
}
.mreport-hero {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.9rem;
}
.mreport-score { display: flex; align-items: baseline; line-height: 1; flex: none; }
.mreport-score-num { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; }
.mreport-score-max { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.mreport-hero-meta { flex: 1; min-width: 0; }
.mreport-month-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.mreport-rating {
    display: inline-block;
    margin: 0.25rem 0 0.5rem;
    padding: 0.12rem 0.6rem;
    border-radius: 999px;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.mreport-bar {
    height: 7px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.mreport-bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.mreport-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 0.5rem;
}
.mreport-tile {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.6rem;
    text-align: center;
    background: var(--panel);
}
.mreport-tile-value { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.mreport-tile-label { font-size: 0.72rem; font-weight: 700; color: var(--ink); margin-top: 0.15rem; }
.mreport-tile-sub { font-size: 0.68rem; color: var(--muted); margin-top: 0.05rem; }
.mreport-tile.good .mreport-tile-value { color: var(--accent); }
.mreport-tile.warn .mreport-tile-value { color: var(--warn); }
.mreport-tile.bad .mreport-tile-value { color: var(--danger); }

/* Fat bank ---------------------------------------------------------------- */
.fatbank-hero { margin-bottom: 0.9rem; }
.fatbank-headline {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    min-width: 0;
    margin-bottom: 0.7rem;
}
.fatbank-jar { font-size: 2.2rem; line-height: 1; flex: none; }
.fatbank-num { display: flex; align-items: baseline; gap: 2px; line-height: 1; flex: none; }
.fatbank-kg { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.02em; }
.fatbank-kg-unit { font-size: 1rem; font-weight: 600; color: var(--muted); }
.fatbank-headline-meta {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    text-align: right;
    min-width: 0;
}
.fatbank-headline-meta .mreport-rating { margin: 0; }
.fatbank-bar-label {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.15rem 0.6rem;
    margin-top: 0.35rem;
    font-size: 0.72rem;
    font-weight: 600;
}
.fatbank-bar-label .muted { color: var(--muted); font-weight: 500; }

.chart-card { position: relative; }
.chart-card.has-chart { cursor: zoom-in; }
.chart-expand {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 8px;
    padding: 0.1rem 0.4rem;
    font-size: 0.95rem;
    line-height: 1;
    color: var(--muted);
    cursor: zoom-in;
    opacity: 0.65;
    transition: opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chart-expand:hover { opacity: 1; border-color: var(--accent); color: var(--accent); }

.chart-modal-card { width: 96vw; max-width: 1100px; }
.chart-modal-card h3 { margin: 0 2rem 0.6rem 0; font-size: 1.05rem; }
.chart-modal-plot {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    background: var(--panel);
}
.chart-modal-plot svg {
    height: min(62vh, 440px);
    width: auto;
    max-width: none;
    display: block;
    margin: 0 auto;
}
.chart-modal-plot .chart-axis-text { font-size: 9px; }
.chart-modal-hint { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.78rem; text-align: center; }
.chart-card .chart-sub { font-weight: 400; font-size: 0.78rem; color: var(--muted); }
.chart-card svg { width: 100%; height: auto; display: block; }

.chart-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
.chart-legend .swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 0.3rem;
    vertical-align: baseline;
}

.chart-axis-text { font-size: 10px; fill: var(--muted); }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-empty { color: var(--muted); font-size: 0.85rem; padding: 1.2rem 0; text-align: center; }

#chart-tooltip {
    position: fixed;
    z-index: 80;
    background: var(--ink);
    color: #fff;
    font-size: 0.75rem;
    line-height: 1.35;
    padding: 0.35rem 0.55rem;
    border-radius: 7px;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
}

.report-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin: 0.35rem 0 0.5rem;
}
.report-controls select,
.report-controls input {
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--panel);
}

/* -- Codex chat ----------------------------------------------------------------- */

.codex { display: flex; flex-direction: column; gap: 0.75rem; }

.codex-header {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
}
.codex-title { flex: 0 0 auto; }
.codex-header h2 { margin: 0 0 0.2rem; font-size: 1.1rem; }
.codex-title { display: flex; align-items: center; gap: 0.4rem; }
.codex-help {
    position: relative;
    display: inline-flex;
    color: var(--muted);
    cursor: help;
    font-size: 1rem;
    line-height: 1;
    user-select: none;
}
.codex-help:hover, .codex-help:focus-visible { color: var(--accent); outline: none; }
.codex-help::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: min(280px, 70vw);
    background: var(--ink);
    color: #fff;
    font-size: 0.78rem;
    line-height: 1.4;
    font-weight: 400;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-3px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 40;
    pointer-events: none;
}
.codex-help:hover::after, .codex-help:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.pref-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; margin: 0.3rem 0 0.2rem; cursor: pointer; }
.pref-row input { width: auto; }
.codex-header p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.codex-status-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: nowrap; justify-content: flex-end; flex: 1 1 auto; min-width: 0; }

.codex-status {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
    white-space: nowrap;
    background: var(--panel);
}
.codex-status.ready { border-color: var(--accent); color: var(--accent); }
.codex-status.error { border-color: var(--danger); color: var(--danger); }

.codex-auth {
    background: #fff8eb;
    border: 1px solid #f3dfb6;
    border-radius: var(--radius);
    font-size: 0.85rem;
    line-height: 1.45;
    padding: 0.7rem 0.9rem;
}
.codex-auth p { color: var(--muted); margin: 0.25rem 0 0; }
.codex-auth a { color: var(--accent); font-weight: 600; }
.codex-auth-code {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 700;
    padding: 1px 6px;
}

/* Budget state is permanent while it applies: a tenant who can only discover
   the daily cap by being refused by it cannot pace their own use. Levels come
   from the server so no threshold is written down twice. */
.chat-budget {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 0.85rem;
    padding: 0.55rem 0.75rem;
}
.chat-budget-warning { background: #fff8e6; border-color: #e6c766; color: #6b5200; }
.chat-budget-critical { background: #fff1e0; border-color: #e0a15f; color: #7a3d00; }
.chat-budget-exhausted { background: #fdecec; border-color: #d98b8b; color: #7a1f1f; }
.chat-budget strong { font-weight: 700; }

.chat-transcript {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    max-height: 58vh;
    min-height: 220px;
    overflow-y: auto;
    padding: 1rem;
}
.chat-empty { color: var(--muted); margin: auto; text-align: center; font-size: 0.9rem; }

.chat-msg {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    max-width: 92%;
    padding: 0.7rem 0.85rem;
    font-size: 0.92rem;
}
.chat-msg.user { align-self: flex-end; background: var(--accent-soft); }
.chat-msg.assistant { align-self: flex-start; background: #fafafc; }

/* Optimistic, browser-only user bubble shown while a submit is in flight. It is
   subdued but never relies on opacity alone: the status row carries visible
   text so the pending state is conveyed without colour or motion. */
.chat-msg-pending { opacity: 0.85; }
.chat-msg-unconfirmed {
    border-style: dashed;
    border-color: #d9a406;
    background: #fffdf5;
    opacity: 1;
}
.chat-msg-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.4rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
}
.chat-msg-unconfirmed .chat-msg-status { color: #92600a; }
.chat-msg-spinner {
    width: 0.7rem;
    height: 0.7rem;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 999px;
    display: inline-block;
    animation: chat-spin 0.8s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    /* Text feedback is authoritative; drop the animation for reduced motion. */
    .chat-msg-spinner { animation: none; }
}

/* Screen-reader-only: a concise polite live region carries pending-status
   announcements so the transcript (rebuilt in full on every poll) does not
   re-announce the whole conversation. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.chat-msg-head {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    color: var(--muted);
    font-size: 0.72rem;
    margin-bottom: 0.4rem;
}
.chat-speaker { color: var(--ink); font-weight: 700; }
/* One server-owned outcome per finished assistant turn. The label text is the
   whole message, so it reads the same without colour; the tints only sort a
   routine answer from one that changed data or did not finish. An ordinary
   answer stays deliberately quiet. */
.chat-result-status {
    background: #eef1f5;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    margin-left: 0.45rem;
    padding: 0.08rem 0.38rem;
}
.chat-result-saved {
    background: rgba(22, 122, 74, 0.1);
    border-color: rgba(22, 122, 74, 0.32);
    color: #126242;
}
.chat-result-not_saved {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.4);
    color: #92400e;
}
.chat-result-failed {
    background: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.32);
    color: var(--danger);
}

.chat-msg-body { line-height: 1.5; overflow-wrap: anywhere; }
.chat-msg-body p { margin: 0 0 0.6rem; }
.chat-msg-body p:last-child, .chat-msg-body ul:last-child,
.chat-msg-body ol:last-child, .chat-msg-body pre:last-child { margin-bottom: 0; }
.chat-msg-body ul, .chat-msg-body ol { margin: 0 0 0.6rem 1.2rem; padding: 0; }
.chat-msg-body code {
    background: #f1f2f5;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.88em;
    padding: 1px 4px;
}
.chat-msg-body pre {
    background: #1c1e24;
    border-radius: var(--radius);
    color: #e6e8ee;
    margin: 0 0 0.6rem;
    overflow-x: auto;
    padding: 0.7rem;
}
.chat-msg-body pre code { background: transparent; border: 0; color: inherit; display: block; padding: 0; white-space: pre; }

.chat-run-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    background: #fff8eb;
    border: 1px solid #f3dfb6;
    border-radius: var(--radius);
    color: #92600a;
    font-size: 0.88rem;
    padding: 0.5rem 0.75rem;
}

.chat-uploads { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.chat-context { margin: 0.1rem 0 0.2rem; }

/* -- Calorie calculator (#409) ----------------------------------------------- */
.calc-toggle { margin-bottom: 0.6rem; }
.calc-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.calc-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    padding: 0.8rem;
    margin-bottom: 0.9rem;
}
.calc-head { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.6rem; }
.calc-head h3 { margin: 0; font-size: 1rem; }
.calc-sub { color: var(--muted); font-size: 0.82rem; }
.calc-top { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.calc-target { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; color: var(--muted); }
.calc-target input { width: 90px; padding: 0.4rem 0.5rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.calc-search { position: relative; flex: 1; min-width: 160px; }
.calc-search input { width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); }
.calc-search input:focus, .calc-target input:focus { outline: none; border-color: var(--accent); }
.calc-items { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.6rem 0; }
.calc-empty { color: var(--muted); font-size: 0.85rem; padding: 0.3rem 0; }
.calc-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.calc-name { flex: 1; min-width: 120px; display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; }
.calc-kind { color: var(--accent); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
.calc-mode { padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.82rem; background: var(--panel); }
.calc-field { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.calc-num { width: 66px; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.calc-remove { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.9rem; padding: 0 0.2rem; }
.calc-remove:hover { color: var(--danger); }
.calc-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.calc-result { margin-top: 0.8rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
.calc-total { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.calc-total-kcal { font-size: 1.4rem; font-weight: 800; }
.calc-total-badge { font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; }
.calc-total.ok .calc-total-badge { background: rgba(22,163,74,0.12); color: #16a34a; }
.calc-total.over .calc-total-kcal { color: var(--danger); }
.calc-total.over .calc-total-badge { background: rgba(220,38,38,0.12); color: var(--danger); }
.calc-result-rows { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.5rem; }
.calc-result-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; }
.calc-result-row .calc-name { flex: 1; }
.calc-result-row .calc-amt { font-weight: 600; }
.calc-result-row .calc-kcal { color: var(--muted); min-width: 66px; text-align: right; }
.calc-result-row.rejected { opacity: 0.55; }
.calc-macros { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.4rem; }
.calc-warn { color: var(--warn); font-size: 0.82rem; margin-bottom: 0.25rem; }
.chat-context-search { position: relative; }
.chat-context-search input {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 0.9rem;
    background: var(--panel);
}
.chat-context-search input:focus { outline: none; border-color: var(--accent); }
.chat-food-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
}
.chat-context-foods { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.context-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.35rem 0.25rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--accent-soft);
    font-size: 0.82rem;
    color: var(--ink);
}
.context-chip .chip-kind { color: var(--accent); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
.context-chip button {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 0 0.15rem;
}
.context-chip button:hover { color: var(--danger); }
.chat-upload {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}
.chat-upload-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.1rem 0.3rem;
}
.chat-upload-preview {
    background: transparent;
    border: none;
    color: var(--ink);
    cursor: zoom-in;
    font: inherit;
    max-width: min(70vw, 360px);
    overflow: hidden;
    padding: 0.1rem 0.2rem;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-upload-preview:hover { color: var(--accent); }

.chat-form {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.8rem;
}
.chat-controls { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.chat-tool {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 34px;
    padding: 0 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.chat-tool:hover { border-color: var(--accent); color: var(--accent); }
.chat-tool.uploading { cursor: wait; opacity: 0.55; pointer-events: none; }
.chat-mode-toggle.apply { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-mode-toggle.apply:hover { color: #fff; }
.chat-spacer { flex: 1 1 0; min-width: 0; }

#chat-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-size: 0.95rem;
    padding: 0.55rem 0.7rem;
    resize: vertical;
}

.chat-send-row { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.chat-send-actions { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.chat-error { color: var(--danger); font-size: 0.82rem; }

/* -- Lightbox ------------------------------------------------------------------ */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 22, 18, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    padding: 1.5rem;
}
.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.thumb { cursor: zoom-in; }
.list-header .list-thumb { cursor: zoom-in; }

/* -- Toast ------------------------------------------------------------------- */

.toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 100;
    max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* -- Waking card -------------------------------------------------------------- */

/* Centred in the content area below the sticky header, so navigation stays
   usable and uncovered. app.js keeps --wake-safe-top at the header's bottom
   edge while the card shows (the header grows when it wraps). The card is
   inset from that edge and from the viewport bottom with auto margins, so it
   centres between them and can never extend above the header; if it is
   taller than that space, it scrolls inside it instead.
   Sized (padding and border included) so the animation is 352 x 141 px on
   desktop and about 320 x 128 on phones. */
.wake-card {
    position: fixed;
    top: calc(var(--wake-safe-top, 0px) + 0.5rem);
    bottom: 0.5rem;
    left: 0;
    right: 0;
    margin: auto;
    height: fit-content;
    max-height: calc(100% - var(--wake-safe-top, 0px) - 1rem);
    overflow-y: auto;
    width: min(calc(352px + 2rem + 2px), calc(100vw - 2rem));
    padding: 1rem;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    text-align: center;
    z-index: 90;
    opacity: 1;
    transition: opacity 0.3s ease;
}
.wake-card.wake-card-leaving { opacity: 0; }
.wake-title { margin: 0.5rem 0 0.25rem; font-weight: 600; }
.wake-subtitle { margin: 0 auto; max-width: 22rem; color: var(--muted); font-size: 0.88rem; }
.wake-elapsed { margin: 0.5rem 0 0; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
#wake-retry { margin-top: 0.75rem; }
/* The animation's box is reserved up front (600 x 240, transparent on the card)
   so nothing moves when the scene loads, falls back or changes phase. */
.wake-visual {
    position: relative;
    /* On short screens (landscape phones) the art shrinks so the whole card,
       about 11rem of text and padding plus the art, fits below the header. */
    width: min(352px, 100%, max(6rem, calc((100vh - var(--wake-safe-top, 0px) - 12rem) * 2.5)));
    width: min(352px, 100%, max(6rem, calc((100dvh - var(--wake-safe-top, 0px) - 12rem) * 2.5)));
    aspect-ratio: 600 / 240;
    margin: 0 auto;
}
.wake-art { position: absolute; inset: 0; opacity: 0; transition: opacity 0.2s ease; }
.wake-card[data-art="ready"] .wake-art { opacity: 1; }
.wake-card[data-art="ready"] .wake-progress { display: none; }
.wake-progress {
    position: absolute;
    top: 50%;
    left: 15%;
    right: 15%;
    height: 4px;
    margin-top: -2px;
    overflow: hidden;
    border-radius: 2px;
    background: var(--accent-soft);
}
.wake-progress span {
    position: absolute;
    inset: 0 auto 0 0;
    width: 40%;
    border-radius: 2px;
    background: var(--accent);
    animation: wake-indeterminate 1.4s ease-in-out infinite;
}
.wake-card[data-phase="failed"] .wake-progress { display: none; }
@keyframes wake-indeterminate {
    from { left: -40%; }
    to { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    .wake-card, .wake-art { transition: none; }
    .wake-progress span { animation: none; width: 100%; opacity: 0.6; }
}

/* -- Small screens ------------------------------------------------------------ */

@media (max-width: 560px) {
    /* Codex title + status + login all fit on one line; status ellipsizes. */
    .codex-status-actions { gap: 0.35rem; }
    .codex-status { font-size: 0.78rem; }
    #codex-login-btn { flex: 0 0 auto; }
    .codex-header h2 { font-size: 1rem; }
    /* Allow the camera control to wrap cleanly on Pixel-sized screens. */
    .chat-controls { gap: 0.35rem; flex-wrap: wrap; }
    .chat-spacer { display: none; }
    .chat-tool { padding: 0 0.6rem; font-size: 0.78rem; }
    .chat-send-row { flex-direction: column; align-items: stretch; }
    .chat-send-row .chat-error { text-align: center; }
    .chat-send-actions { flex-direction: column; align-items: stretch; width: 100%; }
    #chat-send-btn { width: 100%; padding: 0.7rem; font-size: 1rem; }
    #chat-export-btn { align-self: center; }
    .home-grid { grid-template-columns: 1fr; }
    .home-box,
    .home-box.today-box {
        grid-template-columns: 92px 1fr;
        min-height: 122px;
    }
    .home-box.today-box { grid-column: auto; }
    .nutrient-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .totals-bar {
        padding: 1.2rem 0.8rem 1rem;
        gap: 0.75rem;
    }
    .calorie-hero { gap: 0.35rem; }
    .calorie-label { font-size: 0.9rem; }
    .macro-totals { gap: 0.45rem; }
    .macro-total {
        min-height: 66px;
        padding: 0.6rem 0.35rem;
    }
    .macro-value { font-size: 1.1rem; }
    .macro-label { font-size: 0.68rem; }
    .micro-totals { font-size: 0.82rem; }
    .tabs {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 0.1rem;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab-btn { flex: 0 0 auto; }
    .add-entry { flex-direction: column; }
    .search-box,
    .search-filter { width: 100%; }
    .search-filter-btn { flex: 1; }
    .add-entry .ghost { align-self: flex-start; }

    #log-form {
        max-width: 100%;
        overflow-x: hidden;
        padding: 0.8rem;
    }
    #log-form:not(.details-open) .log-components,
    #log-form:not(.details-open) #log-live-total {
        display: none !important;
    }
    .log-form-head {
        align-items: center;
        margin-bottom: 0.55rem;
    }
    .log-form-head .inline-form-title {
        flex: 1;
        margin-bottom: 0;
        font-size: 1rem;
        line-height: 1.2;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .log-details-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.45rem;
        height: 2.45rem;
        padding: 0;
        border-radius: 999px;
        font-size: 1.15rem;
    }
    .log-main-row {
        display: grid;
        grid-template-columns: minmax(0, 0.95fr) minmax(0, 0.9fr) minmax(0, 1fr);
        gap: 0.45rem;
        margin-bottom: 0.7rem;
    }
    .log-main-row label {
        min-width: 0;
        font-size: 0.78rem;
        font-weight: 700;
    }
    .log-main-row input,
    .log-main-row select {
        width: 100%;
        min-height: 3rem;
        padding: 0.55rem 0.6rem;
        font-size: 1rem;
    }
    .log-action-row {
        display: grid;
        grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
        gap: 0.55rem;
        margin-bottom: 0;
    }
    .log-action-row button {
        min-width: 0;
        width: 100%;
        min-height: 3.6rem;
        font-size: 1.05rem;
    }
    .log-action-row .primary {
        font-size: 1.14rem;
        font-weight: 750;
    }
    .log-components {
        margin-top: 0.65rem;
    }
    .log-component-row {
        display: grid;
        grid-template-columns: minmax(0, 5.3rem) minmax(0, 1fr) minmax(0, 4.4rem);
        gap: 0.4rem 0.5rem;
        align-items: center;
        padding: 0.35rem 0;
    }
    .log-component-row .comp-name {
        grid-column: 1 / -1;
        font-weight: 600;
    }
    .log-component-row .unit { min-width: 0; overflow-wrap: anywhere; }
    .log-component-row .comp-kcal {
        grid-column: 3;
        min-width: 0;
    }

    /* Fat bank hero: keep jar + big kg + month/rating on one tidy row. */
    .fatbank-headline { gap: 0.5rem; }
    .fatbank-jar { font-size: 1.9rem; }
    .fatbank-kg { font-size: 2rem; }
    .fatbank-kg-unit { font-size: 0.9rem; }
    .fatbank-headline-meta { flex: 0 1 auto; }
    .fatbank-headline-meta .mreport-month-label { font-size: 0.72rem; }
    .fatbank-headline-meta .mreport-rating {
        font-size: 0.68rem;
        padding: 0.1rem 0.5rem;
        white-space: nowrap;
    }
}

.chat-table-scroll { overflow-x: auto; margin: 0.7rem 0; }
.chat-table-scroll table { border-collapse: collapse; font-size: 0.9em; width: 100%; }
.chat-table-scroll th, .chat-table-scroll td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.chat-table-scroll th:first-child, .chat-table-scroll td:first-child { text-align: left; white-space: normal; min-width: 10rem; }

/* The ledger table scrolls on narrow screens and follows the active theme. */
.ai-usage-table-wrap { overflow-x: auto; }
.ai-usage-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.ai-usage-table th, .ai-usage-table td { padding: 0.6rem; text-align: right; border-bottom: 1px solid var(--line); }
.ai-usage-table th:first-child, .ai-usage-table td:first-child { text-align: left; overflow-wrap: anywhere; min-width: 12rem; }

/* Collapsed by default: the summary row is the card heading and toggle. */
#ai-usage-card summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-right: 2rem;
    cursor: pointer;
    list-style: none;
    border-radius: 8px;
}
#ai-usage-card summary::-webkit-details-marker { display: none; }
#ai-usage-card summary::before {
    content: "▸";
    color: var(--muted);
    transition: transform 0.15s ease;
}
#ai-usage-card details[open] > summary::before { transform: rotate(90deg); }
#ai-usage-card summary h3 { margin: 0; }
#ai-usage-card summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#ai-usage-card details[open] > summary { margin-bottom: 0.6rem; }
#ai-usage-card:has(details:not([open])) { padding-bottom: 0.9rem; cursor: auto; }
#ai-usage-card:has(details:not([open])) .chart-expand { display: none; }
#ai-usage-card .mreport-head { padding-right: 2rem; }
#ai-usage-card .ai-budget-tiles { margin-top: 0.5rem; }
#ai-usage-card .ai-budget-tile { text-align: left; }
#ai-usage-card .ai-budget-tile .mreport-bar { margin-top: 0.45rem; }
#ai-usage-card .ai-budget-tile .mreport-bar-fill { background: var(--accent); }
/* Only the bar signals a reached limit; amber text would fail contrast. */
#ai-usage-card .ai-budget-tile.ai-budget-reached .mreport-bar-fill { background: var(--warn); }
@media (prefers-reduced-motion: reduce) {
    #ai-usage-card summary::before { transition: none; }
}
#ai-usage-card .mreport-tiles { grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); }
#ai-usage-card .mreport-tile-value { overflow-wrap: anywhere; }

/* Sharing keeps navigation and charts readable, with all mutation affordances hidden. */
.sharing-shell-header { position: sticky; top: 0; z-index: 20; }
.sharing-shell-header .topbar { position: static; }
.delegation-banner { display: flex; gap: 1rem; justify-content: center; align-items: center; padding: .75rem; background: #fff1c2; color: #4c3900; border-bottom: 2px solid #c49600; }
.sharing-grant, .sharing-form { padding: 1rem; margin: 1rem 0; border: 1px solid var(--border, #ccc); border-radius: .6rem; }
.sharing-grant button, .sharing-form input, .sharing-form select { margin: .4rem; }
.sharing-form input[readonly] { width: 95%; }
.settings-tabs { padding-right: 1.75rem; flex-wrap: wrap; }
.settings-pane .sharing-grant, .settings-pane .sharing-form { padding: .75rem; margin: .75rem 0; }
.settings-pane .sharing-form input:not([readonly]), .settings-pane .sharing-form select { max-width: calc(100% - .8rem); }
.delegated-read #targets-btn,
.delegated-read #log-form, .delegated-read #quick-form,
.delegated-read #ingredient-form, .delegated-read #dish-form, .delegated-read #list-form,
.delegated-read #ingredient-form-toggle, .delegated-read #dish-form-toggle, .delegated-read #list-form-toggle,
.delegated-read .entry-actions, .delegated-read .detail-actions, .delegated-read .detail-list-panel,
.delegated-read .thumb-remove, .delegated-read .thumb-make-cover, .delegated-read .detail-notes-row, .delegated-read .composer-row,
.delegated-read .tile-remove, .delegated-read .list-add-box, .delegated-read .list-body .card-actions,
.delegated-read #weight-save, .delegated-read #weight-kg, .delegated-read #weight-date,
.delegated-read #ai-usage-card, .delegated-read .owner-control,
.delegated-read #today-tab .search-box, .delegated-read #quick-entry-toggle { display: none !important; }

.delegated #targets-btn, .delegated #ai-usage-card, .delegated .owner-control,
.delegated #calc-ask, .delegated [data-tab="codex"] { display: none !important; }
.changed-by { color: var(--muted, #64748b); font-size: .75rem; }

.delegated.delegated-chat [data-tab="codex"], .delegated.delegated-chat #calc-ask { display: initial !important; }
