:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --soft: #f2f4f7;
    --soft-blue: #eef4ff;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --radius: 10px;
    --shadow: 0 5px 18px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
    min-height: 100%;
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }
.icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}
.icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 58px;
    padding: 8px max(18px, calc((100vw - 1240px) / 2));
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-weight: 900;
    letter-spacing: -.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #111827;
    color: #fff;
}
.brand-mark .icon { width: 19px; height: 19px; }
.brand-text { font-size: 18px; }
.top-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.logout { margin: 0; }

.icon-btn {
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
}
.icon-btn:hover { background: var(--soft); text-decoration: none; }
.icon-btn.filled { background: var(--primary); border-color: var(--primary); color: #fff; }
.icon-btn.filled:hover { background: var(--primary-dark); }
.icon-btn.active { background: var(--soft-blue); border-color: #bfdbfe; }
.danger-icon { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }

.nav-dropdown { position: relative; }
.nav-toggle { list-style: none; user-select: none; }
.nav-toggle::-webkit-details-marker { display: none; }
.nav-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 230px;
    padding: 8px;
    display: grid;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .14);
}
.nav-menu a {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 9px 10px;
    border-radius: 13px;
    color: var(--text);
}
.nav-menu a:hover { background: var(--soft); text-decoration: none; }
.nav-icon {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--soft);
    color: var(--text);
}
.nav-icon .icon { width: 16px; height: 16px; }
.nav-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 1;
}
.nav-menu .nav-badge { position: static; }
.hidden { display: none !important; }
.user-chip {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 8px 10px;
    border-radius: 999px;
    background: var(--soft);
    color: #374151;
    font-weight: 800;
    font-size: 13px;
}

.container {
    width: min(1240px, 100%);
    margin: 0 auto;
    padding: 22px 14px 52px;
}

h1 { margin: 0; font-size: 30px; letter-spacing: 0; line-height: 1.12; }
h2 { margin: 0; font-size: 18px; letter-spacing: 0; line-height: 1.25; }
h3 { margin: 0; font-size: 17px; }
p { line-height: 1.5; }
pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    line-height: 1.55;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.compact-head { align-items: center; }
.subline { color: var(--muted); font-size: 14px; margin-top: 4px; }
.section-title {
    margin: 22px 0 10px;
    color: #374151;
    font-weight: 900;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.card, .auth-card, .list-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 16px; }
.card.slim { padding: 12px 14px; }
.content-card { min-height: 180px; }
.auth-card {
    max-width: 420px;
    margin: 52px auto;
    padding: 24px;
}
.hover-card { transition: border-color .15s ease, box-shadow .15s ease; }
.hover-card:hover { transform: none; border-color: #cbd5e1; box-shadow: 0 8px 22px rgba(15, 23, 42, .08); }
.mini-card { position: relative; min-height: 112px; }
.stretch-link { position: absolute; inset: 0; border-radius: inherit; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin: 16px 0 26px; }
.grid.compact { grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; margin: 0 0 16px; }

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
.actions, .row-actions, .chips {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.nowrap { flex-wrap: nowrap; }
.card-actions { margin-top: 12px; justify-content: flex-end; }

.meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta span, .pill, .chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--soft);
    color: #374151;
    font-size: 13px;
    font-weight: 850;
    white-space: nowrap;
}
.chip { background: var(--soft-blue); color: #1d4ed8; }
.chip:hover { background: #dbeafe; text-decoration: none; }

.dashboard-actions .btn {
    min-height: 38px;
    padding-inline: 13px;
}
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 14px;
}
.dashboard-metric {
    display: grid;
    gap: 5px;
    padding: 14px;
    color: var(--text);
    text-decoration: none;
}
.dashboard-metric:hover {
    text-decoration: none;
    transform: translateY(-1px);
}
.dashboard-metric span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}
.dashboard-metric b {
    font-size: 28px;
    line-height: 1;
    letter-spacing: -.02em;
}
.dashboard-grid .content-card {
    min-height: 210px;
}
.limit-summary-grid {
    margin-bottom: 14px;
}
.limit-overview,
.limit-total-box {
    margin-top: 12px;
}
.total-limit-track div {
    background: #16a34a;
}
.expense-period-settings {
    margin-bottom: 14px;
}
.period-start-form {
    max-width: 420px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-top: 12px;
}

.form { display: flex; flex-direction: column; gap: 12px; }
.form.wide { max-width: 900px; }
.compact-form { gap: 9px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 800; color: #374151; }
input, textarea, select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
    outline: 3px solid rgba(37, 99, 235, .14);
    border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form-row.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.inline-form { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 9px; }
.inline-form.three { grid-template-columns: 1fr 1fr auto; }
.expense-add-form { display: grid; grid-template-columns: 1.1fr 1.2fr .8fr auto; align-items: center; gap: 9px; }
.rename-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 12px 0 6px; }
.search { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.compact-search { max-width: 560px; }

.btn {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
    gap: 8px;
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary, .btn.ghost { background: var(--soft); border-color: var(--line); color: var(--text); }
.btn.secondary:hover, .btn.ghost:hover { background: #e9edf3; }
.btn.danger, .danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.full { width: 100%; }

.list-card { overflow: hidden; }
.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 54px;
    padding: 14px 16px;
    color: var(--text);
    border-bottom: 1px solid var(--line);
    font-weight: 900;
}
.title-row:last-child { border-bottom: none; }
.title-row:hover { background: #fafafa; text-decoration: none; }
.title-row small { color: var(--muted); font-weight: 800; }
.list { display: flex; flex-direction: column; gap: 2px; }
.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }

.action-panel summary {
    cursor: pointer;
    list-style: none;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.action-panel summary .icon {
    width: 18px;
    height: 18px;
}
.action-panel summary::-webkit-details-marker { display: none; }
.action-panel summary::after { content: '⌄'; color: var(--muted); }
.action-panel[open] summary { margin-bottom: 12px; }
.action-panel[open] summary::after { transform: rotate(180deg); }
.share-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.share-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 6px 5px 10px;
    border-radius: 999px;
    background: var(--soft);
    font-weight: 850;
    font-size: 13px;
}
.share-chip form { margin: 0; }
.share-chip button {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    color: var(--danger);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.share-chip button:hover { background: var(--danger-soft); }

.mini-danger {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 11px;
    background: var(--danger-soft);
    color: #b91c1c;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}
.mini-danger:hover { background: #fecaca; }
.category-card h2 { margin-bottom: 6px; }
.wish-card { position: relative; }
.wish-card p { margin: 10px 0 0; }
.done { opacity: .62; }
.done h2 { text-decoration: line-through; }

.empty {
    padding: 16px;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, .55);
}
.empty.small { padding: 10px; font-size: 14px; }
.alert {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    font-weight: 800;
}
.success-alert {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}
.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 100;
    max-width: min(360px, calc(100vw - 32px));
    padding: 12px 14px;
    border-radius: 16px;
    background: #111827;
    color: #fff;
    box-shadow: 0 18px 44px rgba(0,0,0,.18);
    transform: translateY(14px);
    opacity: 0;
    transition: .2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* Chat */
.chat-screen { height: 100dvh; overflow: hidden; }
.chat-screen .container {
    width: min(920px, 100%);
    height: calc(100dvh - 62px);
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-layout {
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
}
.chat-top {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);
}
.chat-title { min-width: 0; }
.chat-title h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 22px;
}
.chat-settings { position: relative; }
.chat-settings summary { list-style: none; }
.chat-settings summary::-webkit-details-marker { display: none; }
.settings-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 10;
    width: min(320px, calc(100vw - 24px));
    display: grid;
    gap: 10px;
}
.chat-feed {
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 8px 6px;
    scroll-behavior: smooth;
}
.bubble {
    max-width: min(76%, 690px);
    padding: 10px 12px;
    border-radius: 17px;
    background: #fff;
    border: 1px solid var(--line);
    word-break: break-word;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .04);
}
.bubble.me {
    align-self: flex-end;
    background: #dbeafe;
    border-color: #93c5fd;
    color: #0f172a;
}
.bubble.other { align-self: flex-start; }
.bubble-meta { font-size: 11px; opacity: .7; margin-bottom: 4px; }
.bubble-text { line-height: 1.45; }
.bubble a { color: var(--primary-dark); font-weight: 800; text-decoration: underline; text-underline-offset: 2px; }
.bubble.me a { color: #075985; }
.bubble.me .bubble-meta { color: #334155; opacity: .85; }
.chat-composer {
    display: grid;
    grid-template-columns: 1fr 46px;
    gap: 8px;
    align-items: end;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 14px 32px rgba(15, 23, 42, .08);
}
.chat-composer textarea {
    min-height: 46px;
    max-height: 130px;
    resize: none;
    border-radius: 16px;
    overflow-y: auto;
}
.send-btn {
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 16px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 900;
}
.send-btn:hover { background: var(--primary-dark); }

@media (max-width: 1100px) {
    .menu-week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .grid.two { grid-template-columns: 1fr; }
    .expense-add-form { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .topbar { min-height: 56px; padding: 8px 10px; }
    .brand-text { display: none; }
    .top-right { gap: 6px; }
    .user-chip { max-width: 94px; padding: 8px; }
    .icon-btn { width: 38px; height: 38px; border-radius: 13px; }
    .nav-menu { right: 0; width: min(240px, calc(100vw - 20px)); }
    .container { padding: 16px 10px 42px; }
    .page-head { gap: 10px; }
    .page-head .actions { width: auto; }
    h1 { font-size: 28px; }
    .grid, .grid.compact, .action-grid { grid-template-columns: 1fr; }
    .form-row, .form-row.two-cols, .inline-form, .inline-form.three, .search, .rename-form { grid-template-columns: 1fr; }
    .compact-form .btn, .search .icon-btn { width: 100%; }
    .card { padding: 14px; }
    .title-row { min-height: 54px; padding: 13px 14px; }
    .title-row small { white-space: nowrap; }
    .bubble { max-width: 90%; }
    .chat-screen .container { height: calc(100dvh - 56px); padding: 8px; }
    .chat-top { padding: 8px; }
    .chat-title h1 { font-size: 19px; }
    .settings-menu { right: -4px; }
    .chat-feed { padding: 10px 4px 4px; }
    .chat-composer { padding: 6px; grid-template-columns: 1fr 44px; }
    .chat-composer textarea, .send-btn { min-height: 44px; height: 44px; }
}

/* v5 polish */
.nav-menu {
    position: fixed;
    top: 58px;
    right: 12px;
    width: min(260px, calc(100vw - 24px));
    max-height: calc(100dvh - 74px);
    overflow-y: auto;
}
.search.auto-search { grid-template-columns: 1fr 44px; }
.search-submit { opacity: .9; }
.recipe-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.editor-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.steps-editor { display: grid; gap: 10px; }
.step-edit-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 92px 34px;
    gap: 8px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fafafa;
}
.step-number {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #111827;
    color: #fff;
    font-weight: 900;
    font-size: 13px;
}
.step-edit-row textarea { min-height: 86px; }
.step-edit-row input { min-height: 42px; text-align: center; }
.steps-view { display: grid; gap: 10px; margin-top: 12px; }
.step-view-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fafafa;
}
.cook-mode { margin: 14px 0; }
.cook-progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--soft);
    margin-bottom: 14px;
}
.cook-progress div {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width .2s ease;
}
.cook-card {
    min-height: 210px;
    display: grid;
    align-content: start;
    gap: 10px;
}
.cook-card pre { font-size: 17px; line-height: 1.6; }
.cook-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 14px;
}
.cook-actions .btn { min-width: 140px; }
.recipe-cost-card {
    display: grid;
    gap: 12px;
}
.price-match-list {
    display: grid;
    gap: 6px;
}
.price-match-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
}
.price-match-row:last-child { border-bottom: none; }
.price-match-row span { min-width: 0; overflow-wrap: anywhere; }
.price-match-row small { color: var(--muted); font-weight: 800; }
.watch-card {
    display: grid;
    gap: 12px;
}
.watch-title {
    min-width: 0;
    display: grid;
    gap: 8px;
}
.watch-title h2 {
    overflow-wrap: anywhere;
}
.watch-edit-panel {
    padding-top: 8px;
    border-top: 1px solid var(--line);
}
.watch-form {
    margin-top: 10px;
}
.search-results-grid .card {
    min-width: 0;
}
.search-user-row form {
    margin: 0;
}
.search-user-row .btn {
    min-height: 34px;
    padding: 7px 12px;
}
.watch-grid {
    align-items: start;
}
.watch-card .card-head {
    align-items: start;
}

.recent-expenses-section {
    margin: 18px 0 22px;
}
.recent-expenses-head {
    margin-bottom: 8px;
}
.recent-expenses-head h2 {
    font-size: 16px;
    letter-spacing: 0;
}
.recent-expenses-panel {
    display: grid;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--card) 82%, var(--soft));
}
.recent-expense-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    min-height: 54px;
    padding: 8px 10px;
    color: inherit;
    text-decoration: none;
    border-radius: 8px;
}
.recent-expense-row:hover {
    background: var(--card);
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .06);
}
.recent-expense-main {
    min-width: 0;
    display: grid;
    gap: 3px;
}
.recent-expense-main b {
    overflow-wrap: anywhere;
    line-height: 1.2;
}
.recent-expense-main span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}
.recent-expense-side {
    display: grid;
    justify-items: end;
    gap: 3px;
}
.recent-expense-side strong {
    white-space: nowrap;
    font-size: 16px;
}
.recent-expense-side time {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.analytics-filter {
    display: grid;
    grid-template-columns: 1.2fr .8fr .8fr auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.stat-card { padding: 14px; }
.stat-card span {
    display: block;
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
    margin-bottom: 4px;
}
.stat-card b { font-size: clamp(22px, 3vw, 30px); letter-spacing: -.03em; }
.analytics-card { margin-bottom: 14px; }
.analytics-card h2 {
    line-height: 1.2;
}
.analytics-head { align-items: flex-start; gap: 12px; }
.chart-legend {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px 12px;
    flex-wrap: wrap;
}
.compact-legend { max-width: 70%; }
.chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}
.chart-legend i, .category-dot {
    width: 10px;
    height: 10px;
    display: inline-block;
    flex: 0 0 10px;
    border-radius: 999px;
}
.category-dot { margin-right: 7px; vertical-align: -1px; }
.date-chart {
    height: 230px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(22px, 1fr);
    align-items: end;
    gap: 6px;
    padding-top: 14px;
    overflow-x: auto;
}
.date-bar-wrap {
    min-width: 24px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: end;
    gap: 7px;
}
.date-bar, .date-bar-stack {
    width: 100%;
    min-height: 2px;
    border-radius: 8px 8px 3px 3px;
    background: var(--primary);
    opacity: .94;
}
.date-bar-stack {
    height: calc(100% - 38px);
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-start;
    overflow: hidden;
    background: var(--soft);
}
.date-bar-segment { width: 100%; min-height: 2px; }
.date-bar-wrap span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}
.bar-list { display: grid; gap: 13px; margin-top: 12px; }
.bar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
    margin-bottom: 6px;
}
.bar-title span { color: var(--muted); font-weight: 900; white-space: nowrap; }
.analytics-split .list-row > div:first-child,
.analytics-split .bar-title b {
    min-width: 0;
    overflow-wrap: anywhere;
}
.bar-track {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--soft);
}
.bar-track div {
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}
.compact-row { align-items: flex-start; }

.menu-page-head { align-items: flex-start; }
.week-actions { align-items: center; }
.week-jump-form {
    display: grid;
    grid-template-columns: minmax(190px, 260px) auto;
    align-items: end;
    gap: 10px;
    margin-bottom: 12px;
}
.menu-add-form {
    display: grid;
    grid-template-columns: .8fr .9fr 1.3fr 1fr auto;
    align-items: end;
    gap: 10px;
    margin-bottom: 14px;
}
.menu-week {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
    padding-bottom: 4px;
}
.menu-day { min-width: 0; padding: 12px; }
.menu-day.today { border-color: #bfdbfe; background: #fbfdff; box-shadow: 0 0 0 1px #bfdbfe inset; }
.menu-day-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.menu-day-head b { font-size: 18px; }
.menu-day-head span { color: var(--muted); font-weight: 900; }
.menu-items { display: grid; gap: 8px; }
.menu-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 30px;
    gap: 8px;
    align-items: start;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fff;
}
.menu-item .pill { margin-bottom: 7px; min-height: 26px; padding: 4px 8px; }

.rename-form { grid-template-columns: minmax(0, 1fr) 42px; }
.rename-form .icon-btn { width: 42px; height: 42px; flex: 0 0 42px; }
.row-actions { flex-wrap: nowrap; flex-shrink: 0; }
.list-row > div:first-child { min-width: 0; }

@media (max-width: 1100px) {
    .menu-week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .analytics-filter { grid-template-columns: 1fr 1fr; }
    .analytics-filter .btn { grid-column: 1 / -1; }
    .dashboard-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .menu-add-form { grid-template-columns: 1fr 1fr; }
    .menu-add-form .btn { grid-column: 1 / -1; }
    .week-jump-form { grid-template-columns: 1fr auto; }
    .menu-week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
    .nav-menu {
        top: 54px;
        right: 8px;
        left: auto;
        width: min(270px, calc(100vw - 16px));
        max-height: calc(100dvh - 66px);
    }
    .top-right { min-width: 0; }
    .user-chip { display: none; }
    .search.auto-search { grid-template-columns: 1fr; }
    .search-submit { display: none; }
    .recipe-toolbar { align-items: stretch; }
    .recipe-toolbar .btn { width: 100%; }
    .step-edit-row { grid-template-columns: 30px minmax(0, 1fr) 72px 30px; gap: 6px; padding: 8px; }
    .step-number { width: 28px; height: 28px; }
    .steps-view .step-view-row { grid-template-columns: 30px minmax(0, 1fr); }
    .cook-card { min-height: 190px; }
    .cook-card pre { font-size: 16px; }
    .analytics-filter { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .dashboard-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
    .dashboard-metric { padding: 12px; }
    .dashboard-metric b { font-size: 24px; }
    .dashboard-actions { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .dashboard-actions .btn { width: 100%; padding-inline: 8px; }
    .period-start-form { grid-template-columns: 1fr; max-width: none; }
    .period-start-form .btn { width: 100%; }
    .recent-expense-row { grid-template-columns: 1fr; align-items: start; gap: 6px; }
    .recent-expense-side { justify-items: start; grid-auto-flow: column; justify-content: space-between; width: 100%; }
    .date-chart { height: 210px; grid-auto-columns: minmax(26px, 34px); }
    .compact-legend { max-width: 100%; justify-content: flex-start; }
    .analytics-split { grid-template-columns: 1fr; }
    .week-jump-form, .menu-add-form { grid-template-columns: 1fr; }
    .week-jump-form .btn, .menu-add-form .btn { width: 100%; }
    .menu-page-head { gap: 10px; }
    .week-actions { width: 100%; justify-content: space-between; }
    .menu-week { grid-template-columns: 1fr; }
    .rename-form { grid-template-columns: minmax(0, 1fr) 42px !important; }
    .inline-form.rename-form { grid-template-columns: minmax(0, 1fr) 42px !important; }
    .list-row { align-items: flex-start; }
    .list-row .row-actions { align-items: center; }
}

@media (max-width: 430px) {
    .step-edit-row {
        grid-template-columns: 30px minmax(0, 1fr) 30px;
    }
    .step-edit-row input {
        grid-column: 2 / 4;
        text-align: left;
    }
    .step-edit-row .mini-danger { grid-column: 3; grid-row: 1; }
}

/* v6 user theme */
html[data-theme="dark"] {
    --bg: #0b1120;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --line: #263244;
    --soft: #1f2937;
    --soft-blue: #172554;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 14px 34px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] .topbar {
    background: rgba(11, 17, 32, .92);
}

html[data-theme="dark"] .brand-mark {
    background: #e5e7eb;
    color: #111827;
}

html[data-theme="dark"] .nav-icon {
    background: #1f2937;
    color: #e5e7eb;
}

html[data-theme="dark"] .nav-menu,
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .card,
html[data-theme="dark"] .list-card,
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .chat-top,
html[data-theme="dark"] .chat-composer,
html[data-theme="dark"] .bubble,
html[data-theme="dark"] .menu-item,
html[data-theme="dark"] .step-edit-row,
html[data-theme="dark"] .step-view-row {
    background: var(--card);
    color: var(--text);
    border-color: var(--line);
}

html[data-theme="dark"] .icon-btn:hover,
html[data-theme="dark"] .nav-menu a:hover,
html[data-theme="dark"] .title-row:hover,
html[data-theme="dark"] .share-chip button,
html[data-theme="dark"] .menu-day.today,
html[data-theme="dark"] .empty {
    background: var(--soft);
}

html[data-theme="dark"] .brand,
html[data-theme="dark"] .nav-menu a,
html[data-theme="dark"] .title-row,
html[data-theme="dark"] label,
html[data-theme="dark"] .section-title,
html[data-theme="dark"] .meta span,
html[data-theme="dark"] .pill,
html[data-theme="dark"] .user-chip,
html[data-theme="dark"] .share-chip {
    color: var(--text);
}

html[data-theme="dark"] .brand-mark,
html[data-theme="dark"] .step-number {
    background: #e5e7eb;
    color: #0b1120;
}

html[data-theme="dark"] .chip {
    background: #172554;
    color: #bfdbfe;
}

html[data-theme="dark"] .chip:hover {
    background: #1e3a8a;
}

html[data-theme="dark"] .empty {
    border-color: #334155;
    color: var(--muted);
}

html[data-theme="dark"] .alert {
    background: rgba(127, 29, 29, .28);
    border-color: rgba(248, 113, 113, .45);
    color: #fecaca;
}

html[data-theme="dark"] .toast {
    background: #e5e7eb;
    color: #0b1120;
}

html[data-theme="dark"] .bubble.me,
html[data-theme="dark"] .btn,
html[data-theme="dark"] .send-btn,
html[data-theme="dark"] .date-bar,
html[data-theme="dark"] .bar-track div,
html[data-theme="dark"] .cook-progress div {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

html[data-theme="dark"] .btn:hover,
html[data-theme="dark"] .send-btn:hover {
    background: var(--primary-dark);
}

html[data-theme="dark"] .danger,
html[data-theme="dark"] .btn.danger {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

html[data-theme="dark"] .danger-icon,
html[data-theme="dark"] .mini-danger {
    background: rgba(248, 113, 113, .14);
    color: #fecaca;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: #64748b;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus {
    outline-color: rgba(96, 165, 250, .22);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]):not([data-theme="dark"]) {
        color-scheme: dark;
    }
}

html[data-theme="dark"] .btn.secondary,
html[data-theme="dark"] .btn.ghost {
    background: var(--soft);
    border-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] .btn.secondary:hover,
html[data-theme="dark"] .btn.ghost:hover,
html[data-theme="dark"] .date-bar-stack {
    background: #1f2937;
}

.import-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
    gap: 14px;
    align-items: start;
}
.recipe-json-card { min-height: 560px; }
.import-side {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.code-textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre;
    tab-size: 2;
}
.readonly-box {
    min-height: 220px;
    background: var(--soft);
}
.copy-btn { margin-top: 10px; }

@media (max-width: 820px) {
    .import-layout { grid-template-columns: 1fr; }
    .recipe-json-card { min-height: auto; }
    .code-textarea { font-size: 12px; }
}

/* v9 recipe photos + cleaner JSON import */
.photo-upload-block {
    display: grid;
    grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
    gap: 12px;
    align-items: end;
}
.recipe-photo-preview {
    display: grid;
    gap: 8px;
}
.recipe-photo-preview img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--soft);
}
.check-row {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    color: var(--muted);
}
.check-row input {
    width: auto;
    min-height: auto;
}
.compact-check {
    font-size: 13px;
}
.recipe-photo-hero {
    margin-bottom: 14px;
    overflow: hidden;
    border-radius: 24px;
    border: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--shadow);
}
.recipe-photo-hero img {
    display: block;
    width: 100%;
    max-height: 460px;
    object-fit: cover;
}
.prompt-box {
    min-height: 420px;
}

html[data-theme="dark"] .recipe-photo-preview img,
html[data-theme="dark"] .recipe-photo-hero {
    border-color: var(--line);
    background: var(--card);
}

@media (max-width: 700px) {
    .photo-upload-block {
        grid-template-columns: 1fr;
    }
    .recipe-photo-preview img {
        max-height: 220px;
    }
    .recipe-photo-hero {
        border-radius: 18px;
    }
    .recipe-photo-hero img {
        max-height: 300px;
    }
    .prompt-box {
        min-height: 360px;
    }
}

/* v11 recipe serving scaling */
.servings-card { margin-top: -2px; margin-bottom: 14px; }
.servings-form {
    display: grid;
    grid-template-columns: minmax(150px, 220px) auto minmax(0, 1fr);
    align-items: end;
    gap: 10px;
}
.servings-form label { margin: 0; }
.servings-form input { min-height: 42px; }
.servings-note { align-self: center; padding-bottom: 10px; }
.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.section-title-row h2 { margin: 0; }
.ingredients-list { display: grid; gap: 8px; }
.ingredient-line {
    display: grid;
    gap: 3px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fafafa;
}
.ingredient-line span { font-weight: 850; line-height: 1.35; }
.ingredient-line small { color: var(--muted); font-weight: 750; line-height: 1.3; }
.ingredient-line.changed {
    border-color: #bfdbfe;
    background: #eff6ff;
}

html[data-theme="dark"] .ingredient-line {
    background: var(--card);
    border-color: var(--line);
}
html[data-theme="dark"] .ingredient-line.changed {
    background: #172554;
    border-color: #1d4ed8;
}

@media (max-width: 720px) {
    .servings-form { grid-template-columns: 1fr; }
    .servings-form .btn { width: 100%; }
    .servings-note { padding-bottom: 0; }
}

/* v12 comfort additions */
.filters-card {
    display: grid;
    grid-template-columns: 2fr 1fr 110px 110px 120px auto;
    gap: 10px;
    align-items: end;
}
.dashboard-grid .card { min-height: 220px; }
.menu-tools { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.shopping-groups .list-row { gap: 8px; align-items: center; }
.shopping-row.done .shopping-main { opacity: .55; text-decoration: line-through; }
.check-btn {
    width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--card); color: var(--text); cursor: pointer; flex: 0 0 auto;
}
.shopping-main { flex: 1; min-width: 120px; }
.price-form { display: flex; gap: 6px; align-items: center; }
.price-form input { width: 82px; }
.mini-form { display: flex; gap: 6px; align-items: center; }
.mini-form select { max-width: 130px; }
.link-block { overflow-wrap: anywhere; }
.inline-editor { margin-top: 10px; }
.wishlist-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.limit-track div { background: linear-gradient(90deg, #16a34a, #f97316, #dc2626); }
.reply-btn { border: 0; background: transparent; color: inherit; cursor: pointer; opacity: .7; }
.reply-preview, .reply-box {
    border-left: 3px solid #60a5fa;
    padding: 7px 9px;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    margin-bottom: 6px;
    font-size: 13px;
    opacity: 1;
}
.reply-preview {
    max-height: 76px;
    overflow: hidden;
    overflow-wrap: anywhere;
}
.bubble.me .reply-preview {
    background: rgba(255, 255, 255, .72);
    border-left-color: #0284c7;
}
.reply-box { display: flex; justify-content: space-between; align-items: center; margin: 0 0 6px 0; width: 100%; }
.reply-box button { border: 0; background: transparent; color: var(--text); cursor: pointer; }
.attachment-link { display: inline-flex; margin-top: 6px; }
.attach-btn {
    width: 42px; height: 42px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--card); border: 1px solid var(--line); cursor: pointer; flex: 0 0 auto;
}
.chat-composer { grid-template-columns: auto 1fr auto; }
.chat-composer .reply-box { grid-column: 1 / -1; }
.nav-menu { max-height: min(70vh, 620px); overflow-y: auto; }
.bar-track div { min-height: 100%; }

@media (max-width: 760px) {
    .filters-card { grid-template-columns: 1fr 1fr; }
    .filters-card input:first-child { grid-column: 1 / -1; }
    .wishlist-form, .split-form { grid-template-columns: 1fr; }
    .shopping-row { grid-template-columns: auto 1fr; }
    .price-form, .mini-form { grid-column: 2 / -1; }
    .mini-form select { max-width: 100%; width: 100%; }
    .menu-tools { align-items: stretch; }
    .menu-tools form { width: 100%; }
    .chat-composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* v13 shopping and wishlist refinements */
.merge-panel .form { gap: 12px; }
.merge-list {
    display: grid;
    gap: 7px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--soft);
}
.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    color: var(--text);
    font-weight: 750;
}
.check-line input { width: auto; min-width: 16px; }
.department-form {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 205px;
}
.department-form input {
    width: 130px;
    min-width: 0;
    padding: 9px 10px;
}
.remember-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 36px;
    min-width: 34px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--soft);
    font-weight: 900;
    cursor: pointer;
}
.remember-check input { width: auto; margin: 0; }
.chip.good { background: #dcfce7; color: #166534; }
html[data-theme="dark"] .chip.good { background: #064e3b; color: #bbf7d0; }

@media (max-width: 760px) {
    .department-form { grid-column: 2 / -1; width: 100%; min-width: 0; }
    .department-form input { flex: 1; width: auto; }
    .merge-list { max-height: 260px; overflow: auto; }
}


/* v15 chat readability */
html[data-theme="dark"] .bubble.me {
    background: #1d4ed8;
    border-color: #2563eb;
    color: #f8fafc;
}
html[data-theme="dark"] .bubble.me .bubble-meta { color: #dbeafe; opacity: .9; }
html[data-theme="dark"] .bubble a { color: #93c5fd; }
html[data-theme="dark"] .bubble.me a { color: #dbeafe; }
html[data-theme="dark"] .reply-preview,
html[data-theme="dark"] .reply-box {
    background: #0f172a;
    color: #e5e7eb;
    border-left-color: #60a5fa;
}
html[data-theme="dark"] .bubble.me .reply-preview {
    background: rgba(15, 23, 42, .58);
    color: #f8fafc;
    border-left-color: #bfdbfe;
}

/* v16 spacing and shopping layout fixes */
.item-text,
.shopping-main {
    min-width: 0;
}
.item-title,
.item-meta,
.list-row .subline,
.shopping-main .subline {
    display: block;
}
.item-title {
    overflow-wrap: anywhere;
    word-break: normal;
    line-height: 1.28;
}
.item-meta {
    margin-top: 4px;
    overflow-wrap: anywhere;
    line-height: 1.35;
}
.today-row {
    align-items: flex-start;
    gap: 12px;
}
.today-row .row-sum {
    flex: 0 0 auto;
    margin-top: 1px;
    white-space: nowrap;
}

.shopping-head h1 {
    overflow-wrap: anywhere;
}
.shopping-actions {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.shopping-groups {
    align-items: start;
}
.shopping-category-card {
    min-width: 0;
    overflow: hidden;
}
.shopping-list-items {
    gap: 0;
}
.shopping-row,
.shopping-groups .shopping-row {
    display: grid !important;
    grid-template-columns: 36px minmax(150px, 1fr) minmax(0, 520px);
    align-items: start;
    gap: 10px;
    padding: 12px 0;
    min-width: 0;
}
.shopping-check-form {
    margin: 0;
}
.shopping-row .shopping-main {
    min-width: 0;
    padding-top: 3px;
}
.shopping-controls {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(170px, 1.35fr) minmax(86px, .45fr) minmax(120px, .7fr) 32px;
    gap: 7px;
    align-items: center;
    justify-content: end;
}
.shopping-controls form {
    margin: 0;
    min-width: 0;
}
.shopping-controls .department-form,
.shopping-controls .price-form,
.shopping-controls .mini-form {
    width: 100%;
    min-width: 0;
}
.shopping-controls .department-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px 38px;
    gap: 6px;
    align-items: center;
}
.shopping-controls .department-form input {
    width: 100%;
    min-width: 0;
}
.shopping-controls .remember-check {
    width: 38px;
    min-width: 38px;
    padding: 0;
}
.shopping-controls .price-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 6px;
    align-items: center;
}
.shopping-controls .price-form input {
    width: 100%;
    min-width: 0;
}
.shopping-controls .mini-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 6px;
    align-items: center;
}
.shopping-controls .mini-form select {
    max-width: none;
    width: 100%;
    min-width: 0;
}
.shopping-controls .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
}
.shopping-controls .delete-form {
    display: flex;
    justify-content: flex-end;
}
.shopping-controls .mini-danger {
    width: 32px;
    height: 38px;
    border-radius: 12px;
}

@media (min-width: 901px) {
    .shopping-groups.grid.two {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1100px) and (min-width: 761px) {
    .shopping-row,
    .shopping-groups .shopping-row {
        grid-template-columns: 36px minmax(0, 1fr);
    }
    .shopping-controls {
        grid-column: 2 / -1;
        grid-template-columns: minmax(180px, 1fr) 110px minmax(140px, .8fr) 38px;
        justify-content: stretch;
    }
}

@media (max-width: 760px) {
    .shopping-actions {
        grid-template-columns: minmax(0, 1fr);
    }
    .shopping-add-form {
        grid-template-columns: 1fr !important;
    }
    .shopping-groups.grid.two,
    .shopping-groups {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 12px;
    }
    .shopping-category-card {
        padding: 12px;
        width: 100%;
    }
    .shopping-row,
    .shopping-groups .shopping-row {
        grid-template-columns: 34px minmax(0, 1fr) !important;
        gap: 8px;
        padding: 11px 0;
        align-items: start;
    }
    .shopping-row .shopping-main {
        min-width: 0;
        padding-top: 2px;
    }
    .shopping-controls {
        grid-column: 2 / -1;
        width: 100%;
        grid-template-columns: minmax(0, 1fr);
        gap: 7px;
    }
    .shopping-controls .department-form {
        grid-column: auto;
        width: 100%;
        grid-template-columns: minmax(0, 1fr) 36px 36px;
    }
    .shopping-controls .price-form,
    .shopping-controls .mini-form {
        grid-template-columns: minmax(0, 1fr) 36px;
    }
    .shopping-controls .icon-btn,
    .shopping-controls .remember-check {
        width: 36px;
        min-width: 36px;
        height: 36px;
    }
    .shopping-controls .delete-form {
        justify-content: flex-end;
    }
    .shopping-controls .mini-danger {
        width: 36px;
        height: 36px;
    }
    .today-row {
        align-items: flex-start !important;
    }
}

@media (max-width: 390px) {
    .shopping-category-card {
        padding: 10px;
    }
    .shopping-row,
    .shopping-groups .shopping-row {
        grid-template-columns: 32px minmax(0, 1fr) !important;
    }
    .check-btn {
        width: 32px;
        height: 32px;
    }
}

/* v16 final override: shopping departments stay one full-width column to avoid desktop overflow */
.shopping-groups.grid.two,
.shopping-groups {
    grid-template-columns: minmax(0, 1fr) !important;
}

/* v17 shopping hard reset: compact, no overlap on phones */
.shopping-category-card {
    overflow: visible !important;
}
.shopping-list-items {
    gap: 0 !important;
}
.shopping-row,
.shopping-groups .shopping-row {
    display: grid !important;
    grid-template-columns: 38px minmax(0, 1fr) 42px !important;
    align-items: start !important;
    gap: 10px !important;
    min-width: 0 !important;
    padding: 12px 0 !important;
    position: relative;
}
.shopping-check-form {
    grid-column: auto !important;
    margin: 0 !important;
    min-width: 0 !important;
}
.shopping-main,
.shopping-row .shopping-main {
    grid-column: auto !important;
    min-width: 0 !important;
    padding-top: 2px !important;
}
.shopping-price-chip {
    display: inline-flex;
    align-items: center;
    width: max-content;
    max-width: 100%;
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--soft-blue);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 900;
}
.shopping-item-menu {
    grid-column: auto !important;
    justify-self: end;
    position: relative;
    min-width: 0;
    margin: 0;
    z-index: 3;
}
.shopping-item-menu summary {
    list-style: none;
}
.shopping-item-menu summary::-webkit-details-marker {
    display: none;
}
.shopping-item-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 50;
    width: min(380px, calc(100vw - 28px));
    display: grid;
    gap: 9px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card);
    color: var(--text);
    box-shadow: 0 18px 44px rgba(15, 23, 42, .18);
}
.shopping-panel-form,
.shopping-item-panel form,
.shopping-item-panel .department-form,
.shopping-item-panel .price-form,
.shopping-item-panel .mini-form,
.shopping-item-panel .delete-form {
    display: grid !important;
    grid-column: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    gap: 7px !important;
    align-items: center !important;
}
.shopping-item-panel .department-form {
    grid-template-columns: 62px minmax(0, 1fr) 38px 38px !important;
}
.shopping-item-panel .price-form,
.shopping-item-panel .mini-form {
    grid-template-columns: 62px minmax(0, 1fr) 38px !important;
}
.shopping-item-panel .delete-form {
    grid-template-columns: 1fr !important;
}
.shopping-item-panel input,
.shopping-item-panel select {
    width: 100% !important;
    min-width: 0 !important;
}
.shopping-item-panel .remember-check,
.shopping-item-panel .icon-btn {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
}
.panel-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .03em;
}
html[data-theme="dark"] .shopping-price-chip {
    background: #1e3a8a;
    color: #dbeafe;
}

@media (min-width: 901px) {
    .shopping-groups.grid.two,
    .shopping-groups {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 900px) {
    .shopping-groups.grid.two,
    .shopping-groups {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}

@media (max-width: 760px) {
    .shopping-actions,
    .shopping-groups.grid.two,
    .shopping-groups {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .shopping-add-form {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .shopping-category-card {
        padding: 12px !important;
    }
    .shopping-row,
    .shopping-groups .shopping-row {
        grid-template-columns: 34px minmax(0, 1fr) 38px !important;
        gap: 8px !important;
        padding: 11px 0 !important;
    }
    .shopping-row .icon-btn {
        width: 38px;
        height: 38px;
    }
    .shopping-item-panel {
        right: 0;
        width: min(330px, calc(100vw - 32px));
        padding: 10px;
        border-radius: 16px;
    }
    .shopping-item-panel .department-form {
        grid-template-columns: 1fr 36px 36px !important;
    }
    .shopping-item-panel .price-form,
    .shopping-item-panel .mini-form {
        grid-template-columns: 1fr 36px !important;
    }
    .shopping-item-panel .department-form .panel-label,
    .shopping-item-panel .price-form .panel-label,
    .shopping-item-panel .mini-form .panel-label {
        grid-column: 1 / -1;
    }
    .shopping-item-panel .remember-check,
    .shopping-item-panel .icon-btn {
        width: 36px !important;
        min-width: 36px !important;
        height: 36px !important;
    }
}

@media (max-width: 390px) {
    .shopping-category-card {
        padding: 10px !important;
    }
    .shopping-row,
    .shopping-groups .shopping-row {
        grid-template-columns: 32px minmax(0, 1fr) 36px !important;
        gap: 7px !important;
    }
    .shopping-item-panel {
        width: calc(100vw - 24px);
        right: -2px;
    }
}

/* v18: сохранение позиции и нормальный выбор категорий в лимитах */
.limit-form {
    display: grid;
    grid-template-columns: minmax(180px, 1.4fr) minmax(110px, .8fr) auto;
    gap: 10px;
    align-items: start;
}

.recurring-form .category-picker,
.limit-form .category-picker {
    width: 100%;
}

.category-picker {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.category-select,
.category-custom {
    width: 100%;
    min-width: 0;
}

.category-picker .hidden {
    display: none !important;
}

@media (max-width: 720px) {
    .limit-form {
        grid-template-columns: 1fr;
    }

    .recurring-form {
        gap: 10px;
    }

    .category-select,
    .category-custom {
        min-height: 44px;
        font-size: 16px;
    }
}


/* v19 shopping: открытое меню всегда выше соседних троеточий, чекбокс запоминания без лишней плашки */
.shopping-row,
.shopping-groups .shopping-row {
    z-index: 1;
}
.shopping-row.menu-open,
.shopping-groups .shopping-row.menu-open {
    z-index: 250 !important;
}
.shopping-item-menu {
    z-index: 2;
}
.shopping-item-menu[open] {
    z-index: 300 !important;
}
.shopping-item-menu[open] .shopping-item-panel {
    z-index: 9999 !important;
}
.shopping-check-form {
    align-self: start !important;
    padding-top: 1px !important;
}
.shopping-main,
.shopping-row .shopping-main {
    padding-top: 1px !important;
}
.shopping-item-panel .remember-check {
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 5px !important;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}
.shopping-item-panel input[type="checkbox"],
.shopping-item-panel .remember-check input[type="checkbox"] {
    width: 18px !important;
    min-width: 18px !important;
    max-width: 18px !important;
    height: 18px !important;
    min-height: 18px !important;
    padding: 0 !important;
    margin: 0 !important;
    flex: 0 0 18px !important;
    accent-color: var(--primary);
}

@media (min-width: 761px) {
    .shopping-item-panel .department-form {
        grid-template-columns: 62px minmax(0, 1fr) auto 38px !important;
    }
    .shopping-item-panel .department-form .remember-check {
        justify-self: start;
    }
}

@media (max-width: 760px) {
    .shopping-item-panel .department-form {
        grid-template-columns: minmax(0, 1fr) auto 36px !important;
        align-items: center !important;
    }
    .shopping-item-panel .department-form .panel-label {
        grid-column: 1 / 2 !important;
        grid-row: 1 !important;
        align-self: center !important;
    }
    .shopping-item-panel .department-form .remember-check {
        grid-column: 2 / 3 !important;
        grid-row: 1 !important;
        justify-self: end !important;
        align-self: center !important;
    }
    .shopping-item-panel .department-form input[name="department"] {
        grid-column: 1 / 3 !important;
        grid-row: 2 !important;
    }
    .shopping-item-panel .department-form .icon-btn {
        grid-column: 3 / 4 !important;
        grid-row: 2 !important;
        align-self: center !important;
    }
}

/* v20 shopping: вместо чекбокса запоминания отдела — понятная кнопка */
.shopping-item-panel .department-update-form {
    display: grid !important;
    grid-template-columns: 62px minmax(0, 1fr) auto !important;
    gap: 8px !important;
    align-items: center !important;
}
.shopping-item-panel .department-update-form .department-update-btn {
    min-height: 38px !important;
    padding: 0 12px !important;
    white-space: nowrap !important;
    font-size: 13px !important;
    border-radius: 12px !important;
}
.shopping-item-panel .department-update-form input[name="department"] {
    grid-column: auto !important;
    grid-row: auto !important;
}
.shopping-item-panel .department-update-form .panel-label {
    grid-column: auto !important;
    grid-row: auto !important;
}

@media (max-width: 760px) {
    .shopping-item-panel .department-update-form {
        grid-template-columns: 1fr !important;
        gap: 7px !important;
    }
    .shopping-item-panel .department-update-form .panel-label,
    .shopping-item-panel .department-update-form input[name="department"],
    .shopping-item-panel .department-update-form .department-update-btn {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
        width: 100% !important;
    }
    .shopping-item-panel .department-update-form .department-update-btn {
        justify-content: center !important;
        min-height: 40px !important;
    }
}

/* v21: нормальный выбор отдела в покупках */
.department-picker {
    display: grid;
    gap: 7px;
    min-width: 0;
    width: 100%;
}
.department-select,
.department-custom {
    width: 100%;
    min-width: 0;
}
.department-picker .hidden {
    display: none !important;
}
.shopping-add-form .department-picker {
    min-width: 160px;
}
.shopping-item-panel .department-update-form .department-picker {
    grid-column: auto !important;
    grid-row: auto !important;
}
.shopping-item-panel .department-update-form .department-select,
.shopping-item-panel .department-update-form .department-custom {
    min-height: 38px;
}
@media (max-width: 760px) {
    .shopping-add-form .department-picker {
        min-width: 0;
        width: 100%;
    }
    .shopping-item-panel .department-update-form .department-picker {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
        width: 100% !important;
    }
    .shopping-item-panel .department-update-form .department-select,
    .shopping-item-panel .department-update-form .department-custom {
        min-height: 42px;
        font-size: 16px;
    }
}

/* v22 shopping: отдел исправляется галочкой справа, при нажатии правило запоминается */
.shopping-item-panel .department-update-form {
    display: grid !important;
    grid-template-columns: 62px minmax(0, 1fr) 38px !important;
    gap: 8px !important;
    align-items: center !important;
}
.shopping-item-panel .department-update-form .department-picker {
    grid-column: auto !important;
    grid-row: auto !important;
    width: 100% !important;
    min-width: 0 !important;
}
.shopping-item-panel .department-update-form .department-learn-btn {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    justify-self: end !important;
}
.shopping-item-panel .department-update-form .department-update-btn {
    display: none !important;
}
@media (max-width: 760px) {
    .shopping-item-panel .department-update-form {
        grid-template-columns: minmax(0, 1fr) 36px !important;
        gap: 7px !important;
    }
    .shopping-item-panel .department-update-form .panel-label {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
        width: auto !important;
    }
    .shopping-item-panel .department-update-form .department-picker {
        grid-column: 1 / 2 !important;
        grid-row: auto !important;
        width: 100% !important;
    }
    .shopping-item-panel .department-update-form .department-learn-btn {
        grid-column: 2 / 3 !important;
        grid-row: auto !important;
        width: 36px !important;
        min-width: 36px !important;
        height: 42px !important;
        align-self: start !important;
    }
}

/* v23 presence status */
.presence-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    vertical-align: middle;
    color: var(--muted);
    font-weight: 850;
}
.presence-inline i {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 999px;
    background: #9ca3af;
    box-shadow: 0 0 0 3px rgba(156, 163, 175, .12);
}
.presence-inline.online { color: #15803d; }
.presence-inline.online i {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, .16);
}
.presence-inline.typing { color: var(--primary); }
.presence-inline.typing i {
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .16);
}
.chat-list-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    white-space: normal !important;
    line-height: 1.35;
}
html[data-theme="dark"] .presence-inline.online { color: #86efac; }
html[data-theme="dark"] .presence-inline { color: #94a3b8; }
html[data-theme="dark"] .presence-inline.typing { color: #93c5fd; }

/* v24 PWA chat fit */
:root {
    --app-height: 100dvh;
    --topbar-height: 62px;
    --chat-gap: 8px;
}
@supports (height: 100svh) {
    :root { --app-height: 100svh; }
}
body.chat-screen {
    height: var(--app-height);
    min-height: var(--app-height);
    overflow: hidden;
    overscroll-behavior: none;
}
body.chat-screen .topbar {
    min-height: var(--topbar-height);
}
body.chat-screen .container {
    height: calc(var(--app-height) - var(--topbar-height));
    min-height: 0;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    overflow: hidden;
}
body.chat-screen .chat-layout {
    height: 100%;
    min-height: 0;
    gap: var(--chat-gap);
}
body.chat-screen .chat-top {
    flex: 0 0 auto;
    min-height: 54px;
    padding: 8px 10px;
    border-radius: 16px;
}
body.chat-screen .chat-title h1 {
    font-size: 19px;
    line-height: 1.12;
}
body.chat-screen .chat-title .subline {
    margin-top: 2px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.chat-screen .chat-feed {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 4px 2px;
    gap: 7px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
body.chat-screen .bubble {
    max-width: min(86%, 690px);
    padding: 9px 11px;
    border-radius: 16px;
}
body.chat-screen .bubble-meta {
    font-size: 10px;
    margin-bottom: 3px;
}
body.chat-screen .chat-composer {
    flex: 0 0 auto;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 7px;
    padding: 7px;
    border-radius: 18px;
    margin-bottom: 0;
}
body.chat-screen .attach-btn,
body.chat-screen .send-btn {
    width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 14px;
}
body.chat-screen .chat-composer textarea {
    min-height: 42px;
    height: 42px;
    max-height: 104px;
    padding: 10px 11px;
    border-radius: 14px;
    line-height: 20px;
}
body.chat-screen .reply-box {
    grid-column: 1 / -1;
    margin: 0;
    min-height: 34px;
    padding: 7px 9px;
    border-radius: 13px;
    overflow: hidden;
}
body.chat-screen .reply-box span {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.chat-screen .settings-menu {
    max-height: min(55vh, 420px);
    overflow-y: auto;
}
@media (display-mode: standalone), (display-mode: fullscreen) {
    body.chat-screen .topbar {
        display: none;
    }
    body.chat-screen .container {
        height: var(--app-height);
        padding-top: max(6px, env(safe-area-inset-top));
    }
}
@media (max-width: 720px) {
    :root { --topbar-height: 56px; --chat-gap: 6px; }
    body.chat-screen .container {
        width: 100%;
        padding-left: 6px;
        padding-right: 6px;
    }
    body.chat-screen .chat-top {
        grid-template-columns: 38px minmax(0, 1fr) 38px;
        gap: 7px;
        padding: 7px;
        border-radius: 15px;
        box-shadow: none;
    }
    body.chat-screen .chat-top .icon-btn {
        width: 38px;
        height: 38px;
    }
    body.chat-screen .chat-title h1 {
        font-size: 17px;
    }
    body.chat-screen .chat-feed {
        padding-left: 2px;
        padding-right: 2px;
    }
    body.chat-screen .bubble {
        max-width: 92%;
        padding: 8px 10px;
    }
    body.chat-screen .chat-composer {
        gap: 6px;
        padding: 6px;
        border-radius: 16px;
        box-shadow: 0 -8px 24px rgba(15, 23, 42, .06);
    }
    body.chat-screen .attach-btn,
    body.chat-screen .send-btn {
        width: 40px;
        height: 40px;
        min-height: 40px;
        border-radius: 13px;
    }
    body.chat-screen .chat-composer textarea {
        min-height: 40px;
        height: 40px;
        max-height: 92px;
        font-size: 16px;
    }
    body.chat-screen .settings-menu {
        position: fixed;
        top: max(52px, env(safe-area-inset-top));
        right: 8px;
        width: calc(100vw - 16px);
        max-height: min(64vh, 480px);
    }
}
@media (max-width: 380px) {
    body.chat-screen .bubble { max-width: 96%; }
    body.chat-screen .chat-title h1 { font-size: 16px; }
    body.chat-screen .chat-title .subline { font-size: 11px; }
    body.chat-screen .chat-top {
        grid-template-columns: 36px minmax(0, 1fr) 36px;
    }
    body.chat-screen .chat-top .icon-btn,
    body.chat-screen .attach-btn,
    body.chat-screen .send-btn {
        width: 36px;
        height: 36px;
        min-height: 36px;
    }
    body.chat-screen .chat-composer textarea {
        min-height: 36px;
        height: 36px;
        padding: 8px 10px;
    }
}

/* v25: push + editable limits */
.limit-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
}
.limit-summary { min-width: 0; }
.limit-editor { position: relative; margin-top: 0; }
.limit-editor > summary { list-style: none; }
.limit-editor > summary::-webkit-details-marker { display: none; }
.limit-edit-form {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: minmax(190px, 1fr) 110px 36px;
    gap: 8px;
    min-width: min(560px, calc(100vw - 28px));
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    box-shadow: 0 18px 46px rgba(15, 23, 42, .18);
}
.limit-edit-form .category-picker { gap: 6px; }
.limit-edit-form input[name="monthly_limit"] { min-width: 0; }
#enableNotifications.active { box-shadow: 0 0 0 3px rgba(34, 197, 94, .22); }

@media (max-width: 720px) {
    .limit-row { grid-template-columns: minmax(0, 1fr) auto; }
    .limit-edit-form {
        position: fixed;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: calc(env(safe-area-inset-bottom) + 12px);
        min-width: 0;
        grid-template-columns: 1fr 100px 40px;
    }
}

@media (max-width: 430px) {
    .limit-edit-form { grid-template-columns: 1fr 40px; }
    .limit-edit-form .category-picker,
    .limit-edit-form input[name="monthly_limit"] { grid-column: 1 / -1; }
    .limit-edit-form .mini-ok { grid-column: 2; }
}

/* v29: stable mobile/PWA chat viewport */
:root {
    --vvh: var(--app-height, 100dvh);
    --vv-top: 0px;
}
body.chat-screen {
    position: fixed;
    inset: 0;
    width: 100%;
    height: var(--vvh);
    min-height: 0;
    overflow: hidden;
    touch-action: manipulation;
}
body.chat-screen .container {
    position: fixed;
    left: 50%;
    right: auto;
    top: calc(var(--topbar-height) + var(--vv-top));
    transform: translateX(-50%);
    width: min(920px, 100vw);
    height: calc(var(--vvh) - var(--topbar-height));
    max-height: calc(var(--vvh) - var(--topbar-height));
    min-height: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    overflow: hidden;
}
body.chat-screen .chat-layout,
body.chat-screen .chat-feed {
    min-height: 0;
}
body.chat-screen .chat-composer {
    position: relative;
    z-index: 20;
    flex-shrink: 0;
    margin-bottom: 0;
}
body.chat-screen .chat-feed {
    padding-bottom: 4px;
}
@media (display-mode: standalone), (display-mode: fullscreen) {
    body.chat-screen {
        height: var(--vvh);
    }
    body.chat-screen .container {
        top: var(--vv-top);
        height: var(--vvh);
        max-height: var(--vvh);
        padding-top: max(6px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}
@media (max-width: 720px) {
    body.chat-screen .container {
        width: 100vw;
        padding-left: 6px;
        padding-right: 6px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    body.chat-screen .chat-feed {
        padding-bottom: 2px;
    }
    body.chat-screen .chat-composer {
        width: 100%;
        max-width: 100%;
        grid-template-columns: 40px minmax(0, 1fr) 40px;
    }
}
@media (max-width: 380px) {
    body.chat-screen .chat-composer {
        grid-template-columns: 36px minmax(0, 1fr) 36px;
    }
}

/* v30 recipe step ordering + persistent cooking timer */
.step-edit-row {
    grid-template-columns: 34px 38px minmax(0, 1fr) 92px 34px;
}
.step-move-controls {
    display: grid;
    gap: 5px;
}
.mini-btn {
    width: 34px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
    color: var(--text);
    font-weight: 950;
    cursor: pointer;
}
.mini-btn:disabled {
    opacity: .35;
    cursor: default;
}
.cook-timer-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--soft);
}
.cook-timer-value {
    font-size: 32px;
    line-height: 1;
    font-weight: 950;
    letter-spacing: -.04em;
}
.cook-timer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.timer-record-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #bfdbfe;
    border-radius: 18px;
    background: #eff6ff;
    color: #1e3a8a;
    font-weight: 850;
}
html[data-theme="dark"] .mini-btn {
    background: #0f172a;
    border-color: var(--line);
    color: var(--text);
}
html[data-theme="dark"] .cook-timer-panel {
    background: #0f172a;
    border-color: var(--line);
}
html[data-theme="dark"] .timer-record-box {
    background: #172554;
    border-color: #1d4ed8;
    color: #dbeafe;
}
html[data-theme="dark"] .success-alert {
    background: rgba(22, 101, 52, .2);
    border-color: #166534;
    color: #bbf7d0;
}

@media (max-width: 720px) {
    .step-edit-row {
        grid-template-columns: 30px 34px minmax(0, 1fr) 30px;
    }
    .step-edit-row textarea {
        grid-column: 3 / 5;
    }
    .step-edit-row input {
        grid-column: 3 / 5;
        text-align: left;
    }
    .step-edit-row .mini-danger {
        grid-column: 4;
        grid-row: 1;
    }
    .step-move-controls {
        grid-column: 2;
        grid-row: 1 / 3;
    }
    .cook-timer-panel,
    .timer-record-box {
        align-items: stretch;
        flex-direction: column;
    }
    .cook-timer-actions {
        justify-content: stretch;
        display: grid;
        grid-template-columns: 1fr 1fr 44px;
    }
    .cook-timer-actions .btn,
    .timer-record-box .btn {
        width: 100%;
    }
}

/* v31 expense item editing */
.expense-add-form.with-date {
    grid-template-columns: 1.05fr 1.2fr .75fr .85fr auto;
}
.expense-items-list { gap: 6px; }
.expense-item-card {
    border-bottom: 1px solid var(--line);
    padding: 0 0 6px;
}
.expense-item-card:last-child { border-bottom: none; }
.expense-item-card .list-row { border-bottom: none; padding-bottom: 6px; }
.expense-item-main {
    min-width: 0;
    display: grid;
    gap: 3px;
}
.expense-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.mini-edit {
    width: 34px;
    height: 34px;
    min-height: 34px;
    border-radius: 12px;
    font-size: 14px;
}
.mini-edit.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.expense-edit-form {
    display: grid;
    grid-template-columns: 1fr .72fr 1fr .65fr auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    margin: 2px 0 6px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--soft);
}
.expense-edit-form[hidden] { display: none !important; }
.expense-edit-form label {
    gap: 4px;
    font-size: 12px;
}
.expense-edit-form input,
.expense-edit-form select {
    min-height: 38px;
    border-radius: 12px;
    padding: 8px 10px;
}
.expense-edit-form .btn { min-height: 38px; padding: 8px 12px; }

@media (max-width: 900px) {
    .expense-add-form.with-date { grid-template-columns: 1fr 1fr; }
    .expense-add-form.with-date .btn { grid-column: 1 / -1; }
    .expense-edit-form { grid-template-columns: 1fr 1fr; }
    .expense-edit-form .btn { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
    .expense-add-form.with-date { grid-template-columns: 1fr; }
    .expense-list-row { align-items: flex-start; }
    .expense-row-actions { gap: 6px; }
    .expense-row-actions strong { white-space: nowrap; }
    .expense-edit-form { grid-template-columns: 1fr; }
}

/* Daily analytics chart: one layout for desktop and a compact scrollable layout for mobile. */
.analytics-card .analytics-date-chart {
    height: 290px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 48px;
    justify-content: start;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0 6px;
    scrollbar-width: thin;
}
.analytics-card .analytics-date-chart .date-bar-wrap {
    min-width: 48px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) 84px;
    gap: 6px;
}
.analytics-card .analytics-date-chart .date-bar-stack {
    width: 38px;
    justify-self: center;
    min-height: 0;
    display: flex;
    flex-direction: column-reverse;
    overflow: hidden;
    border-radius: 8px 8px 3px 3px;
}
.analytics-card .analytics-date-chart .date-axis-label {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-items: center;
    overflow: hidden;
}
.analytics-card .analytics-date-chart .date-axis-date,
.analytics-card .analytics-date-chart .date-axis-total {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    max-height: 82px;
    font-size: 10px;
    line-height: 1.1;
    white-space: nowrap;
}
.analytics-card .analytics-date-chart .date-axis-date { color: var(--muted); font-weight: 700; }
.analytics-card .analytics-date-chart .date-axis-total { color: var(--text); font-weight: 900; }

@media (max-width: 760px) {
    .analytics-card .analytics-date-chart { height: 276px; grid-auto-columns: 44px; gap: 6px; }
    .analytics-card .analytics-date-chart .date-bar-wrap { min-width: 44px; grid-template-rows: minmax(0, 1fr) 80px; }
    .analytics-card .analytics-date-chart .date-bar-stack { width: 34px; }
    .analytics-card .analytics-date-chart .date-axis-date,
    .analytics-card .analytics-date-chart .date-axis-total { max-height: 78px; font-size: 9.5px; }
}

@media (min-width: 1180px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .search-results-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .watch-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .analytics-split {
        grid-template-columns: 1.05fr .95fr;
    }
}

/* Final surface pass: dense enough for everyday use without turning pages into card walls. */
.dashboard-summary {
    gap: 10px;
}
.dashboard-metric {
    min-height: 104px;
    border-top: 3px solid var(--primary);
    box-shadow: none;
}
.dashboard-metric:nth-child(2) { border-top-color: #0f766e; }
.dashboard-metric:nth-child(3) { border-top-color: #b45309; }
.dashboard-metric:nth-child(4) { border-top-color: #7c3aed; }
.dashboard-metric b { font-size: 26px; }
.dashboard-grid .content-card { min-height: 0; }

.action-panel,
.analytics-filter,
.filters-card {
    box-shadow: none;
}
.action-panel summary {
    min-height: 28px;
    color: var(--text);
}
.action-panel[open] {
    border-color: #cbd5e1;
}
.stats-grid {
    gap: 10px;
}
.stat-card {
    border-left: 3px solid var(--primary);
    box-shadow: none;
}
.list-card,
.recent-expenses-panel,
.shopping-category-card,
.watch-card {
    box-shadow: none;
}
.chip, .pill {
    border-radius: 7px;
}
.icon-btn {
    border-radius: 8px;
}
.page-head .actions .btn.secondary {
    background: transparent;
}
.page-head .actions .btn.secondary:hover {
    background: var(--soft);
}
.recipe-row {
    border-left: 3px solid transparent;
}
.recipe-row:hover {
    border-left-color: var(--primary);
}
.watch-progress-actions { margin-top: 12px; }
.recipe-favorite-form { margin: -50px 8px 8px auto; width: max-content; position: relative; z-index: 1; }

@media (max-width: 720px) {
    h1 { font-size: 26px; }
    h2 { font-size: 17px; }
    .topbar { padding-inline: 10px; }
    .brand-text, .user-chip { display: none; }
    .top-right { gap: 6px; }
    .page-head { align-items: flex-start; }
    .page-head .actions { width: 100%; }
    .page-head .actions .btn { flex: 1 1 0; min-width: 0; }
    .dashboard-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-metric { min-height: 88px; padding: 12px; }
    .dashboard-metric b { font-size: 23px; }
    .card { padding: 14px; }
    .card-head { gap: 8px; }
    .list-row { padding-block: 10px; }
    .recipe-favorite-form { margin: -48px 6px 6px auto; }
}

/* Income and cash-flow reporting */
.income-total-card { display: grid; gap: 6px; margin-bottom: 14px; border-left: 3px solid #0f766e; box-shadow: none; }
.income-total-card span, .income-row span { color: var(--muted); font-size: 13px; font-weight: 750; }
.income-total-card b { color: #047857; font-size: 30px; }
.income-form { display: grid; grid-template-columns: 1.2fr .75fr .9fr 1fr 1.2fr auto; gap: 9px; align-items: center; }
.income-list-card { margin-top: 16px; box-shadow: none; }
.income-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 42px; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.income-row:last-child { border-bottom: 0; }
.income-row-main { min-width: 0; display: grid; gap: 4px; }
.income-row-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.income-row strong { color: #047857; white-space: nowrap; }
.income-edit-form { margin: 10px 0; }
.finance-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.finance-metric { display: grid; gap: 7px; min-height: 112px; box-shadow: none; }
.finance-metric span { color: var(--muted); font-size: 13px; font-weight: 800; }
.finance-metric b { font-size: 24px; line-height: 1.1; }
.finance-metric.income { border-top: 3px solid #0f766e; }
.finance-metric.expense { border-top: 3px solid #c2410c; }
.finance-metric.balance { border-top: 3px solid #2563eb; }
.finance-metric.negative { border-top-color: var(--danger); }
.finance-forecast-card { box-shadow: none; }
.finance-forecast-values { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.finance-forecast-values div { display: grid; gap: 5px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.finance-forecast-values span { color: var(--muted); font-size: 13px; font-weight: 750; }
.finance-forecast-values b { font-size: 20px; }
.positive-text { color: #047857; }
.negative-text { color: var(--danger); }

.cashflow-card { margin: 16px 0; box-shadow: none; }
.cashflow-head { align-items: center; }
.cashflow-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 800; }
.cashflow-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cashflow-legend i { width: 9px; height: 9px; border-radius: 2px; background: #0f766e; }
.cashflow-legend .expense i { background: #c2410c; }
.cashflow-legend .forecast i { background: repeating-linear-gradient(135deg, #fb923c 0 3px, #fed7aa 3px 6px); }
.cashflow-chart { height: 300px; display: grid; grid-auto-flow: column; grid-auto-columns: 56px; justify-content: start; gap: 7px; overflow-x: auto; padding: 16px 2px 4px; scrollbar-width: thin; }
.cashflow-day { display: grid; grid-template-rows: minmax(0, 1fr) 50px; gap: 7px; min-width: 56px; }
.cashflow-bars { min-height: 0; display: flex; align-items: end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line); }
.cashflow-bar { width: 13px; min-height: 0; border-radius: 4px 4px 0 0; transition: opacity .15s ease; }
.cashflow-bar.income { background: #0f766e; }
.cashflow-bar.expense { background: #c2410c; }
.cashflow-bar.forecast { background: repeating-linear-gradient(135deg, #fb923c 0 3px, #fed7aa 3px 6px); }
.cashflow-day:hover .cashflow-bar { opacity: .72; }
.cashflow-day.forecast-day .cashflow-bars { background: linear-gradient(90deg, transparent, rgba(251, 146, 60, .08), transparent); }
.cashflow-label { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; justify-items: center; overflow: hidden; }
.cashflow-label span, .cashflow-label b { writing-mode: vertical-rl; transform: rotate(180deg); max-height: 48px; white-space: nowrap; font-size: 10px; line-height: 1; }
.cashflow-label span { color: var(--muted); font-weight: 700; }
.cashflow-label b { font-weight: 900; }

@media (max-width: 900px) {
    .income-form { grid-template-columns: 1fr 1fr; }
    .income-form .btn { grid-column: 1 / -1; }
    .finance-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
    .income-form, .finance-summary-grid, .finance-forecast-values { grid-template-columns: 1fr; }
    .income-row { grid-template-columns: minmax(0, 1fr) auto; }
    .income-row .inline-editor { grid-column: 1 / -1; }
    .cashflow-head { align-items: flex-start; }
    .cashflow-legend { justify-content: flex-start; }
    .cashflow-chart { height: 274px; grid-auto-columns: 50px; gap: 5px; }
    .cashflow-day { min-width: 50px; grid-template-rows: minmax(0, 1fr) 46px; }
    .cashflow-bar { width: 11px; }
}
