:root {
    --accent: #0d9488;
    --accent-dark: #0f766e;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --danger: #dc2626;
    --radius: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --surface: #141b2d;
        --border: #263148;
        --text: #e2e8f0;
        --text-muted: #8a97ad;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 560px;
    margin: 0 auto;
    background: var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px calc(10px + env(safe-area-inset-top, 0px));
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand { font-weight: 700; font-size: 1.05rem; }
.topbar-user { color: var(--text-muted); font-size: 0.85rem; }

.content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px calc(16px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.bottom-nav {
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding-bottom: var(--safe-bottom);
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 0 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 500;
}

.bottom-nav a.active { color: var(--accent); }
.bottom-nav .icon { font-size: 1.3rem; }

h1 { font-size: 1.25rem; margin: 0 0 14px; }
h2 { font-size: 1.02rem; margin: 0; }
.muted { color: var(--text-muted); font-size: 0.88rem; }
.empty-state { color: var(--text-muted); font-size: 0.9rem; padding: 24px 4px; text-align: center; }
.error-msg { color: var(--danger); font-size: 0.88rem; margin: 6px 0 0; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

button { font-family: inherit; cursor: pointer; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 600;
    font-size: 0.92rem;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.5; }

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    font-size: 0.85rem;
}

.btn-small { padding: 6px 12px; font-size: 0.8rem; }

/* ---- Login ---- */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}
.login-card h1 { margin-bottom: 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; text-align: left; }
.login-form label { font-size: 0.82rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.login-form input {
    font-size: 1rem;
    padding: 10px 12px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

/* ---- Chat ---- */
.chat-page { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 8px;
}
.msg { display: flex; flex-direction: column; max-width: 84%; }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; align-items: flex-start; }
.msg-tag { font-size: 0.68rem; color: var(--text-muted); margin-bottom: 2px; }
.msg-bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 0.93rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.msg-user .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant .msg-bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.typing-indicator { font-size: 0.78rem; color: var(--text-muted); padding: 2px 4px 8px; font-style: italic; }

.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 14px;
    margin-top: 6px;
}
.chat-input-bar input[type=text] {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--text);
    outline: none;
}
.icon-btn {
    border: none;
    background: transparent;
    font-size: 1.15rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn-small {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 2px 6px;
}

/* ---- Shopping ---- */
.shop-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 14px;
}
.shop-list.done { opacity: 0.6; }
.shop-list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.badge {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 9px;
}
.shop-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.shop-items li { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.shop-items li.checked .item-name { text-decoration: line-through; color: var(--text-muted); }
.check-form { margin: 0; }
.checkbox {
    width: 24px; height: 24px;
    border-radius: 7px;
    border: 2px solid var(--border);
    background: transparent;
    color: #fff;
    font-size: 0.85rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.shop-items li.checked .checkbox { background: var(--accent); border-color: var(--accent); }
.item-name { font-size: 0.92rem; }
.pill {
    font-size: 0.68rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 8px;
    margin-left: 4px;
}
.shop-list-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.shop-list-foot > form.inline-form { flex: 1 1 100%; }
.shop-list-foot > form:not(.inline-form) { flex: none; margin-left: auto; }
.inline-form { display: flex; gap: 6px; min-width: 0; }
.inline-form input[type=text] {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.86rem;
}
.qty-input { flex: none !important; width: 56px; }
.new-list summary { list-style: none; }
.new-list summary::-webkit-details-marker { display: none; }
.new-list[open] .inline-form { margin-top: 8px; }

/* ---- Recipes ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}
.fridge-list { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.fridge-list li { display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; padding: 4px 0; }
.recipe-card .recipe-head { display: flex; align-items: center; justify-content: space-between; }
.recipe-body {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.5;
    margin: 10px 0 0;
}

/* ---- Home / dashboard ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.stat-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 4px;
}
.stat-value { font-size: 1.15rem; font-weight: 700; }
.stat-label { font-size: 0.66rem; color: var(--text-muted); text-align: center; }
.readiness-line { font-size: 0.85rem; margin: 12px 0 0; }
.today-workout {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.88rem;
}
.workout-pill {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    flex-shrink: 0;
}

.quick-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.quick-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text);
}
.quick-icon { font-size: 1.3rem; }
.quick-value { font-weight: 700; font-size: 1rem; }
.quick-label { font-size: 0.68rem; color: var(--text-muted); text-align: center; }

.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar-nav h2 { font-size: 0.95rem; }
.calendar-nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    padding: 0 10px;
    line-height: 1;
}
.cal-weekdays, .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}
.cal-weekdays span {
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-muted);
    padding-bottom: 4px;
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-radius: 8px;
    font-size: 0.8rem;
}
.cal-day.out { opacity: 0.3; }
.cal-day.today .cal-daynum {
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cal-dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 5px; height: 5px; border-radius: 50%; }
.dot-done { background: var(--accent); }
.dot-scheduled { background: #f59e0b; }
.cal-legend {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.cal-legend span { display: flex; align-items: center; gap: 5px; }
