/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --green:       #16a34a;
    --green-light: #dcfce7;
    --green-dark:  #14532d;
    --blue:        #2563eb;
    --blue-light:  #dbeafe;
    --orange:      #ea580c;
    --orange-light:#ffedd5;
    --purple:      #7c3aed;
    --purple-light:#ede9fe;
    --red:         #dc2626;
    --red-light:   #fee2e2;
    --gray-50:     #f9fafb;
    --gray-100:    #f3f4f6;
    --gray-200:    #e5e7eb;
    --gray-300:    #d1d5db;
    --gray-400:    #9ca3af;
    --gray-500:    #6b7280;
    --gray-600:    #4b5563;
    --gray-700:    #374151;
    --gray-800:    #1f2937;
    --gray-900:    #111827;
    --white:       #ffffff;
    --sidebar-w:   260px;
    --topbar-h:    56px;
    --bottom-nav-h:64px;
    --radius:      12px;
    --radius-sm:   8px;
    --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:   0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --shadow-lg:   0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
    --transition:  150ms ease;
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, textarea, select { font: inherit; }
textarea { resize: vertical; }

/* ===== App Shell ===== */
.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    transition: transform var(--transition);
    z-index: 200;
}

.sidebar-header {
    padding: 20px 16px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-100);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--green);
}

.logo svg { width: 32px; height: 32px; }

.sidebar-close { display: none; color: var(--gray-500); padding: 4px; }
.sidebar-close svg { width: 20px; height: 20px; }

.nav-section { padding: 12px 8px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    font-size: .9rem;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-item.active { background: var(--green-light); color: var(--green-dark); font-weight: 600; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 190;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Topbar ===== */
.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.menu-btn {
    color: var(--gray-600);
    padding: 4px;
    display: none;
}

.menu-btn svg { width: 22px; height: 22px; }
.menu-btn:hover { color: var(--gray-900); }

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    flex: 1;
}

.topbar-actions { display: flex; gap: 8px; }

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* ===== Bottom Nav (mobile) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    height: var(--bottom-nav-h);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 150;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--gray-400);
    font-size: .7rem;
    font-weight: 500;
    flex: 1;
    transition: color var(--transition);
    padding: 8px 4px;
    float: left;
    width: 25%;
    height: 100%;
}

.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--green); }
.bottom-nav-item:active { background: var(--gray-50); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { background: #15803d; }
.btn-outline { background: transparent; border: 1.5px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { border-color: var(--gray-400); background: var(--gray-50); }
.btn-danger { color: var(--red); border-color: var(--red-light); }
.btn-danger:hover { background: var(--red-light); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-link { font-size: .85rem; color: var(--green); font-weight: 500; background: none; border: none; }
.btn-link:hover { text-decoration: underline; }

/* ===== Cards ===== */
.card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 20px;
    box-shadow: var(--shadow);
}

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

.card-header h2 { font-size: 1rem; font-weight: 600; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    color: var(--gray-800);
    background: var(--white);
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, .1);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.label-hint { font-weight: 400; color: var(--gray-500); margin-left: 6px; font-size: .8rem; }
.label-hint a { color: var(--green); text-decoration: underline; }
.field-hint { font-size: .8rem; color: var(--gray-500); margin-top: 4px; display: block; }

.input-with-btn {
    display: flex;
    gap: 8px;
}
.input-with-btn input { flex: 1; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 500;
    margin-bottom: 16px;
}
.alert-success { background: var(--green-light); color: var(--green-dark); border: 1px solid #bbf7d0; }

/* ===== Dashboard ===== */
.dashboard { max-width: 900px; margin: 0 auto; }
.dashboard-greeting { margin-bottom: 24px; }
.dashboard-greeting h1 { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); }
.dashboard-greeting p { color: var(--gray-500); margin-top: 2px; text-transform: capitalize; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }

.stat-card.green .stat-icon { background: var(--green-light); color: var(--green); }
.stat-card.blue .stat-icon  { background: var(--blue-light);  color: var(--blue); }
.stat-card.orange .stat-icon{ background: var(--orange-light); color: var(--orange); }
.stat-card.purple .stat-icon{ background: var(--purple-light); color: var(--purple); }

.stat-value { font-size: 1.5rem; font-weight: 700; display: block; line-height: 1.2; }
.stat-label { font-size: .75rem; color: var(--gray-500); font-weight: 500; }

.macro-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    text-align: center;
}

.macro-item { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.macro-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--green-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    color: var(--green-dark);
    border: 3px solid var(--green);
}
.macro-circle.blue   { background: var(--blue-light);   color: var(--blue);   border-color: var(--blue); }
.macro-circle.orange { background: var(--orange-light);  color: var(--orange); border-color: var(--orange); }
.macro-circle.purple { background: var(--purple-light);  color: var(--purple); border-color: var(--purple); }
.macro-item label { font-size: .75rem; color: var(--gray-500); font-weight: 500; }

.profile-summary { margin-bottom: 20px; }
.quick-actions { margin-bottom: 20px; }
.quick-actions h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

.actions-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: var(--radius);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all var(--transition);
    border: 2px solid transparent;
}

.action-btn svg { width: 24px; height: 24px; }
.action-btn.green  { background: var(--green-light);  color: var(--green-dark);  border-color: #bbf7d0; }
.action-btn.blue   { background: var(--blue-light);   color: #1e40af;            border-color: #bfdbfe; }
.action-btn.orange { background: var(--orange-light);  color: #9a3412;            border-color: #fed7aa; }
.action-btn.purple { background: var(--purple-light);  color: #4c1d95;            border-color: #ddd6fe; }
.action-btn:hover { filter: brightness(.96); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.today-plan { margin-bottom: 20px; }
.today-plan h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }
.meals-list { display: flex; flex-direction: column; gap: 10px; }
.meal-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.meal-row:last-child { border-bottom: none; }
.meal-type { font-size: .8rem; font-weight: 600; color: var(--gray-500); min-width: 120px; flex-shrink: 0; }
.meal-desc { flex: 1; font-size: .9rem; color: var(--gray-700); }
.meal-cal { font-size: .8rem; font-weight: 600; color: var(--green); flex-shrink: 0; }

/* ===== Chat ===== */
.chat-layout {
    display: flex;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
    overflow: hidden;
    margin: -24px;
}

.sessions-panel {
    width: 280px;
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sessions-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-100);
}

.sessions-header h2 { font-size: .9rem; font-weight: 600; color: var(--gray-700); }

.btn-new-chat {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--green-light);
    color: var(--green);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.btn-new-chat svg { width: 16px; height: 16px; }
.btn-new-chat:hover { background: #bbf7d0; }

.sessions-list { flex: 1; overflow-y: auto; padding: 8px; }

.session-item {
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    transition: background var(--transition);
    overflow: hidden;
}

.session-item:hover { background: var(--gray-100); }
.session-item.active { background: var(--green-light); }
.session-item.active .session-title { color: var(--green-dark); font-weight: 600; }

.session-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    min-width: 0;
}

.session-title {
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-date { font-size: .75rem; color: var(--gray-400); }

.session-delete {
    padding: 8px;
    color: var(--gray-400);
    opacity: 0;
    transition: opacity var(--transition);
    flex-shrink: 0;
}
.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { color: var(--red); }
.session-delete svg { width: 14px; height: 14px; }

.sessions-empty { padding: 24px 16px; text-align: center; color: var(--gray-500); font-size: .85rem; }
.sessions-empty p { margin-bottom: 12px; }

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--gray-50);
}

.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
}

.welcome-icon { margin-bottom: 20px; }
.welcome-icon svg { width: 80px; height: 80px; }
.chat-welcome h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--gray-800); }
.chat-welcome p { color: var(--gray-500); max-width: 360px; margin-bottom: 24px; }

.suggestions { margin-top: 32px; }
.suggestions p { font-size: .85rem; color: var(--gray-500); margin-bottom: 12px; }
.suggestion-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
    padding: 6px 14px;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: 20px;
    font-size: .8rem;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition);
}
.chip:hover { border-color: var(--green); color: var(--green); background: var(--green-light); }

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-empty { text-align: center; color: var(--gray-400); font-size: .9rem; padding: 40px 0; }

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.message.user { margin-left: auto; flex-direction: row-reverse; }

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}
.message-avatar svg { width: 32px; height: 32px; }

.message-bubble { display: flex; flex-direction: column; gap: 4px; }

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .9rem;
    line-height: 1.6;
    word-break: break-word;
}

.message.assistant .message-content {
    background: var(--white);
    border: 1px solid var(--gray-200);
    color: var(--gray-800);
    border-radius: 4px var(--radius) var(--radius) var(--radius);
    box-shadow: var(--shadow);
}

.message.user .message-content {
    background: var(--green);
    color: var(--white);
    border-radius: var(--radius) 4px var(--radius) var(--radius);
}

.message.error .message-content { background: var(--red-light); color: var(--red); border-color: #fecaca; }

.message-time { font-size: .7rem; color: var(--gray-400); padding: 0 4px; }
.message.user .message-time { text-align: right; }

/* Chat input */
.chat-input-area {
    padding: 12px 16px;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--gray-50);
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 8px 8px 8px 14px;
    transition: border-color var(--transition);
}
.chat-input-wrapper:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.1); }

#chatInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: .95rem;
    color: var(--gray-800);
    resize: none;
    max-height: 150px;
    line-height: 1.5;
    padding: 0;
}
#chatInput::placeholder { color: var(--gray-400); }

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--green);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}
.send-btn svg { width: 16px; height: 16px; }
.send-btn:hover { background: #15803d; }
.send-btn:disabled { background: var(--gray-300); cursor: not-allowed; }

.chat-info { padding: 6px 0 0; min-height: 20px; }
.typing-indicator { font-size: .8rem; color: var(--gray-500); font-style: italic; }
.shopping-notice { font-size: .8rem; color: var(--green); font-weight: 500; }
.hidden { display: none !important; }

/* ===== Shopping ===== */
.shopping-page { max-width: 720px; margin: 0 auto; }

.shopping-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.shopping-stats { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-600);
}
.stat-badge.green { background: var(--green-light); color: var(--green-dark); }
.stat-badge.gray  { background: var(--gray-100);    color: var(--gray-500); }

.toolbar-actions { display: flex; gap: 8px; }

.shopping-empty {
    text-align: center;
    padding: 60px 24px;
    color: var(--gray-500);
}
.shopping-empty svg { width: 64px; height: 64px; margin: 0 auto 16px; color: var(--gray-300); }
.shopping-empty h3 { font-size: 1.1rem; color: var(--gray-700); margin-bottom: 8px; }
.shopping-empty p { font-size: .9rem; max-width: 340px; margin: 0 auto 20px; }
.empty-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.shopping-list { display: flex; flex-direction: column; gap: 16px; }

.category-group {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.category-icon { font-size: 1.1rem; }
.category-name { font-size: .9rem; font-weight: 600; color: var(--gray-700); flex: 1; }
.category-count {
    background: var(--gray-200);
    color: var(--gray-600);
    font-size: .75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}

.category-items { padding: 4px 0; }

.shopping-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    transition: background var(--transition);
}
.shopping-item:last-child { border-bottom: none; }
.shopping-item:hover { background: var(--gray-50); }
.shopping-item.checked { opacity: .55; }

.item-checkbox {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 2px solid var(--gray-300);
    background: var(--white);
    flex-shrink: 0;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.item-checkbox svg { width: 14px; height: 14px; color: var(--white); display: none; }
.shopping-item.checked .item-checkbox { background: var(--green); border-color: var(--green); }
.shopping-item.checked .item-checkbox svg { display: block; }
.shopping-item.checked .item-name { text-decoration: line-through; }

.item-info { flex: 1; cursor: pointer; min-width: 0; }
.item-name { font-size: .9rem; font-weight: 500; color: var(--gray-800); display: block; }
.item-qty { font-size: .8rem; color: var(--gray-500); margin-top: 1px; display: block; }
.item-notes { font-size: .75rem; color: var(--gray-400); font-style: italic; margin-top: 1px; display: block; }

.item-delete { color: var(--gray-300); opacity: 0; transition: all var(--transition); padding: 4px; flex-shrink: 0; }
.item-delete svg { width: 16px; height: 16px; }
.shopping-item:hover .item-delete { opacity: 1; }
.item-delete:hover { color: var(--red); }

/* ===== Settings ===== */
.settings-page { max-width: 800px; margin: 0 auto; }

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--white);
    padding: 6px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-600);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.tab svg { width: 15px; height: 15px; }
.tab:hover { background: var(--gray-100); color: var(--gray-800); }
.tab.active { background: var(--green); color: var(--white); }

.settings-form { display: flex; flex-direction: column; gap: 20px; }

.settings-section {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 20px;
    box-shadow: var(--shadow);
}
.settings-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 6px; color: var(--gray-800); }
.section-desc { font-size: .85rem; color: var(--gray-500); margin-bottom: 16px; }

.macro-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

.api-test-result {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
}
.api-test-result.success { background: var(--green-light); color: var(--green-dark); }
.api-test-result.error   { background: var(--red-light);   color: var(--red); }

/* Toggle switch */
.toggle-list { display: flex; flex-direction: column; gap: 0; }

.toggle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-100);
    cursor: default;
    gap: 16px;
}
.toggle-item:last-child { border-bottom: none; }

.toggle-info { flex: 1; }
.toggle-info strong { display: block; font-size: .9rem; font-weight: 600; color: var(--gray-800); margin-bottom: 2px; }
.toggle-info span { font-size: .8rem; color: var(--gray-500); }

.toggle-switch { position: relative; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
    display: block;
    width: 44px;
    height: 24px;
    background: var(--gray-300);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition);
    position: relative;
}
.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--white);
    box-shadow: var(--shadow);
    transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::after { transform: translateX(20px); }

.rag-preview { margin-top: 12px; }
.rag-preview pre {
    background: var(--gray-900);
    color: #a3e635;
    border-radius: var(--radius-sm);
    padding: 16px;
    font-size: .8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    margin-top: 10px;
    max-height: 400px;
    overflow-y: auto;
}

/* Weekly plan */
.weekly-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.day-card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    min-width: 140px;
    box-shadow: var(--shadow);
}

.day-header {
    background: var(--green);
    color: var(--white);
    font-size: .8rem;
    font-weight: 700;
    padding: 8px 12px;
    text-align: center;
}

.day-meals { padding: 4px; display: flex; flex-direction: column; gap: 2px; }

.meal-slot {
    border-radius: var(--radius-sm);
    padding: 8px;
    background: var(--gray-50);
    border: 1.5px solid transparent;
    transition: border-color var(--transition);
    cursor: pointer;
}
.meal-slot:hover { border-color: var(--green-light); background: var(--green-light); }
.meal-slot.has-meal { background: var(--white); border-color: var(--gray-200); }

.meal-slot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.meal-label { font-size: .7rem; font-weight: 600; color: var(--gray-500); }
.meal-edit-btn { color: var(--gray-400); opacity: 0; transition: opacity var(--transition); }
.meal-edit-btn svg { width: 12px; height: 12px; }
.meal-slot:hover .meal-edit-btn { opacity: 1; }
.meal-slot.has-meal .meal-edit-btn { color: var(--green); opacity: 1; }

.meal-desc-preview { font-size: .72rem; color: var(--gray-700); margin-top: 4px; line-height: 1.3; }
.meal-cal-preview { font-size: .7rem; color: var(--green); font-weight: 600; margin-top: 2px; }
.meal-empty-hint { font-size: .7rem; color: var(--gray-400); margin-top: 4px; font-style: italic; }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { color: var(--gray-400); padding: 4px; }
.modal-close:hover { color: var(--gray-700); }
.modal-close svg { width: 18px; height: 18px; }

.modal .form-group { padding: 0 20px; margin-bottom: 14px; }
.modal .form-group:first-child { padding-top: 16px; }
.modal-body { padding: 16px 20px; }
.modal-body .form-group { padding: 0; }

.modal-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .weekly-grid { grid-template-columns: repeat(4, 1fr); }
    .stats-grid  { grid-template-columns: repeat(2, 1fr); }
    .actions-grid { grid-template-columns: repeat(2, 1fr); }
    .macro-grid  { grid-template-columns: repeat(2, 1fr); }
    .macro-inputs { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .sidebar-close { display: flex; }
    .menu-btn { display: flex; }

    .page-content {
        padding: 16px;
        padding-bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom));
    }

    .bottom-nav { display: flex; }

    .chat-layout { margin: -16px; height: calc(100dvh - var(--topbar-h)); }
    .sessions-panel { display: none; }

    .weekly-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid  { grid-template-columns: repeat(2, 1fr); }
    .actions-grid { grid-template-columns: repeat(2, 1fr); }
    .macro-grid  { grid-template-columns: repeat(2, 1fr); }
    .macro-inputs { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .tabs { gap: 2px; }
    .tab { padding: 7px 10px; font-size: .8rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .weekly-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 1.2rem; }
}

/* ===== Plans ===== */

/* Bottom nav: 5 items */
.bottom-nav-item { width: 20%; }

.plans-page { max-width: 960px; margin: 0 auto; }

.plans-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-heading { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.page-sub { color: var(--gray-500); font-size: .9rem; max-width: 540px; }

/* Season summary */
.season-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.season-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 2px solid transparent;
    background: var(--white);
    box-shadow: var(--shadow);
}

.season-badge.blue          { border-color: var(--blue-light); }
.season-badge.purple        { border-color: #ddd6fe; }
.season-badge.orange        { border-color: var(--orange-light); }
.season-badge.has-active    { box-shadow: var(--shadow-md); }
.season-badge.blue.has-active    { background: var(--blue-light); }
.season-badge.purple.has-active  { background: var(--purple-light); }
.season-badge.orange.has-active  { background: var(--orange-light); }

.season-icon { font-size: 1.5rem; flex-shrink: 0; }
.season-badge strong { display: block; font-size: .85rem; font-weight: 700; color: var(--gray-800); }
.season-badge span { font-size: .78rem; color: var(--gray-500); }
.no-active { font-style: italic; }

/* Format guide */
.format-guide {
    margin-bottom: 24px;
    padding: 0;
    overflow: hidden;
}
.format-guide summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: .9rem;
    font-weight: 600;
    color: var(--gray-700);
    list-style: none;
}
.format-guide summary svg { width: 16px; height: 16px; flex-shrink: 0; }
.format-guide summary::-webkit-details-marker { display: none; }
.format-guide[open] summary { border-bottom: 1px solid var(--gray-200); }

.format-content { padding: 16px 20px; }
.format-content p { font-size: .85rem; color: var(--gray-600); margin-bottom: 12px; }
.format-content pre {
    background: var(--gray-900);
    color: #a3e635;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: .8rem;
    overflow-x: auto;
    white-space: pre;
    margin-bottom: 12px;
}
.format-notes { font-size: .8rem !important; line-height: 1.7; }
.format-notes code { background: var(--gray-100); padding: 1px 5px; border-radius: 4px; font-family: monospace; }

/* Season section */
.season-section { margin-bottom: 32px; }

.season-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.season-icon-lg { font-size: 1.4rem; }
.season-heading h2 { font-size: 1.1rem; font-weight: 700; color: var(--gray-800); flex: 1; }
.plans-count { font-size: .8rem; color: var(--gray-500); font-weight: 500; }

.season-empty {
    background: var(--white);
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    color: var(--gray-500);
    font-size: .9rem;
}
.season-empty p { margin-bottom: 12px; }

/* Plans grid */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.plan-card {
    background: var(--white);
    border-radius: var(--radius);
    border: 2px solid var(--gray-200);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--transition);
    display: flex;
    flex-direction: column;
}
.plan-card:hover { box-shadow: var(--shadow-md); }
.plan-card.active { border-color: var(--green); }

.plan-active-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--green);
    color: var(--white);
    font-size: .7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 0 var(--radius) 0 var(--radius-sm);
}

.plan-card-body { padding: 16px 16px 10px; flex: 1; }
.plan-name { font-size: .95rem; font-weight: 700; color: var(--gray-800); margin-bottom: 4px; padding-right: 60px; }
.plan-desc { font-size: .8rem; color: var(--gray-500); margin-bottom: 8px; line-height: 1.4; }
.plan-meta { display: flex; gap: 12px; font-size: .75rem; color: var(--gray-400); }
.plan-meta span { display: flex; align-items: center; gap: 4px; }

.plan-card-actions {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
    flex-wrap: wrap;
}

.btn-danger-outline { color: var(--red); }
.btn-danger-outline:hover { background: var(--red-light); border-color: #fca5a5; }

/* Plan form */
.plan-form-page { max-width: 1100px; margin: 0 auto; }

.form-page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--gray-500);
    font-size: .85rem;
    font-weight: 500;
    padding: 6px 0;
    transition: color var(--transition);
}
.btn-back svg { width: 16px; height: 16px; }
.btn-back:hover { color: var(--gray-800); }

.plan-form { display: flex; flex-direction: column; gap: 20px; }

.form-cols {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}

.form-col-meta { display: flex; flex-direction: column; gap: 16px; }
.form-col-content { display: flex; flex-direction: column; gap: 16px; }

.season-preview-box {
    font-size: .85rem;
    color: var(--gray-600);
    padding: 8px 12px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    min-height: 36px;
    display: flex;
    align-items: center;
}

.mini-example {
    background: var(--gray-900);
    color: #a3e635;
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: .75rem;
    overflow-x: auto;
    white-space: pre;
}

.markdown-card { padding: 0; overflow: hidden; }

.markdown-tabs {
    display: flex;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.md-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    cursor: pointer;
}
.md-tab svg { width: 14px; height: 14px; }
.md-tab.active { color: var(--green); border-bottom-color: var(--green); background: var(--white); }
.md-tab:hover:not(.active) { color: var(--gray-700); background: var(--gray-100); }

.md-panel { padding: 16px; }
.md-panel textarea {
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: .82rem;
    line-height: 1.6;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--gray-800);
    background: var(--gray-900);
    color: #e5e7eb;
    outline: none;
    resize: vertical;
    min-height: 380px;
    transition: border-color var(--transition);
}
.md-panel textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.1); }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--gray-50);
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--green);
    background: var(--green-light);
}
.dropzone svg { width: 48px; height: 48px; color: var(--gray-300); margin: 0 auto 12px; display: block; }
.dropzone.dragover svg { color: var(--green); }
.dropzone p { color: var(--gray-600); font-size: .9rem; margin-bottom: 12px; }
.dropzone-hint { font-size: .75rem !important; color: var(--gray-400) !important; margin-top: 8px !important; }

.file-info {
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--green-light);
    color: var(--green-dark);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
}

.md-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.parse-status { font-size: .82rem; color: var(--green); font-weight: 500; }

/* Parse preview */
.parse-preview h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .95rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--green-dark);
}
.parse-preview h3 svg { width: 18px; height: 18px; }

.preview-days { display: flex; flex-direction: column; gap: 16px; }
.preview-day {}
.preview-day-name { font-size: .85rem; font-weight: 700; color: var(--gray-700); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
.preview-meal {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: .85rem;
}
.preview-meal:last-child { border-bottom: none; }
.preview-meal-type { min-width: 130px; font-weight: 600; color: var(--gray-500); font-size: .78rem; flex-shrink: 0; }
.preview-meal-desc { flex: 1; color: var(--gray-700); }
.preview-meal-cal { font-size: .78rem; font-weight: 600; color: var(--green); flex-shrink: 0; }

.form-submit-bar {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 8px;
}

/* Plan view */
.plan-view-page { max-width: 960px; margin: 0 auto; }

.plan-view-header { margin-bottom: 20px; }

.plan-view-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.plan-view-title h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.plan-view-desc { color: var(--gray-500); font-size: .9rem; margin-bottom: 8px; }
.plan-view-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.plan-view-actions { display: flex; gap: 10px; flex-shrink: 0; flex-wrap: wrap; }

.season-pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 600;
}
.season-pill.invernale   { background: var(--blue-light);   color: #1e40af; }
.season-pill.primaverile { background: var(--purple-light); color: #4c1d95; }
.season-pill.estiva      { background: var(--orange-light); color: #7c2d12; }
.plan-view-meta span { font-size: .8rem; color: var(--gray-500); }
.active-pill { background: var(--green-light); color: var(--green-dark); padding: 3px 10px; border-radius: 20px; font-weight: 600; font-size: .78rem !important; }

.plan-weekly-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.plan-day-card {}
.plan-day-name {
    font-size: .85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--green-dark);
    background: var(--green-light);
    padding: 8px 16px;
    margin: -20px -20px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.plan-day-meals { display: flex; flex-direction: column; gap: 10px; }

.plan-meal-row { display: flex; flex-direction: column; gap: 2px; }
.plan-meal-label { font-size: .7rem; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: .04em; }
.plan-meal-info { display: flex; align-items: baseline; gap: 8px; }
.plan-meal-desc { font-size: .85rem; color: var(--gray-700); flex: 1; }
.plan-meal-cal { font-size: .75rem; font-weight: 600; color: var(--green); flex-shrink: 0; }

.calorie-bars { display: flex; flex-direction: column; gap: 8px; }
.cal-bar-row { display: flex; align-items: center; gap: 12px; }
.cal-bar-day { font-size: .8rem; font-weight: 600; color: var(--gray-600); min-width: 36px; }
.cal-bar-track { flex: 1; height: 10px; background: var(--gray-100); border-radius: 5px; overflow: hidden; }
.cal-bar-fill { height: 100%; background: var(--green); border-radius: 5px; min-width: 4px; }
.cal-bar-val { font-size: .8rem; color: var(--gray-500); min-width: 70px; text-align: right; }

/* Settings: update weekly tab */
.settings-weekly-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-100);
}
.settings-weekly-link:last-child { border-bottom: none; }

@media (max-width: 1024px) {
    .form-cols { grid-template-columns: 1fr; }
    .season-summary { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .plans-grid { grid-template-columns: 1fr; }
    .plan-weekly-view { grid-template-columns: 1fr; }
    .season-summary { grid-template-columns: 1fr; }
    .plan-view-title { flex-direction: column; }
}

/* ===== Couple Profile & Weekly Plan ===== */

.couple-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 8px;
}

.couple-col { display: flex; flex-direction: column; gap: 0; }

.couple-col-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-weight: 700;
    font-size: .9rem;
}
.couple-col-header.person-1 { background: #dbeafe; color: #1e3a8a; }
.couple-col-header.person-2 { background: #fce7f3; color: #831843; }

.person-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 800;
    flex-shrink: 0;
    color: white;
}
.person-1 .person-avatar, .person-avatar.p1 { background: #2563eb; }
.person-2 .person-avatar, .person-avatar.p2 { background: #db2777; }
.couple-col-header.person-1 .person-avatar { background: #2563eb; }
.couple-col-header.person-2 .person-avatar { background: #db2777; }

.person-avatar.small { width: 22px; height: 22px; font-size: .7rem; }
.person-avatar.tiny  { width: 18px; height: 18px; font-size: .65rem; flex-shrink: 0; }

/* Legend */
.person-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .85rem;
    font-weight: 600;
}
.person-1-legend .person-avatar { background: #2563eb; }
.person-2-legend .person-avatar { background: #db2777; }

/* Weekly couple grid */
.weekly-couple-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.day-card-couple {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    min-width: 150px;
    box-shadow: var(--shadow);
}

.day-meals-couple { padding: 4px; display: flex; flex-direction: column; gap: 4px; }

.meal-slot-couple {
    border-radius: var(--radius-sm);
    background: var(--gray-50);
    overflow: hidden;
}

.meal-slot-label {
    font-size: .68rem;
    font-weight: 700;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 4px 8px 2px;
}

.meal-persons { display: flex; flex-direction: column; gap: 1px; }

.meal-person-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: .75rem;
    min-height: 28px;
}

.meal-person-row.person-1 { border-left: 3px solid #2563eb; background: #eff6ff; }
.meal-person-row.person-2 { border-left: 3px solid #db2777; background: #fdf2f8; }
.meal-person-row.person-1:hover { background: #dbeafe; }
.meal-person-row.person-2:hover { background: #fce7f3; }

.meal-person-row .person-avatar.tiny.p1 { background: #2563eb; }
.meal-person-row .person-avatar.tiny.p2 { background: #db2777; }
.meal-person-row.person-1 .person-avatar { background: #2563eb; }
.meal-person-row.person-2 .person-avatar { background: #db2777; }

.meal-person-desc { flex: 1; color: var(--gray-700); line-height: 1.3; font-size: .72rem; }
.meal-person-cal  { color: var(--green); font-weight: 700; font-size: .68rem; flex-shrink: 0; }
.meal-person-empty { color: var(--gray-300); font-style: italic; flex: 1; }

/* Modal subtitle (person badge) */
.modal-subtitle {
    font-size: .8rem;
    font-weight: 600;
    margin-top: 2px;
}
.person-badge-1 { color: #2563eb; }
.person-badge-2 { color: #db2777; }

@media (max-width: 1024px) {
    .couple-grid { grid-template-columns: 1fr; }
    .weekly-couple-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 768px) {
    .weekly-couple-grid { grid-template-columns: repeat(2, 1fr); }
    .couple-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .weekly-couple-grid { grid-template-columns: 1fr; }
}

/* ===== Weight Tracking ===== */

/* Bottom nav: 6 items */
.bottom-nav-item { width: 16.666%; }

.weight-page { max-width: 960px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

.weight-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

/* Quick add bar */
.quick-add-bar h3 { font-size: .95rem; font-weight: 600; margin-bottom: 16px; }

.quick-add-form { display: flex; flex-direction: column; gap: 16px; }

.quick-add-person { display: flex; flex-direction: column; gap: 8px; }

.quick-add-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    font-weight: 700;
}
.quick-add-label.person-1 { color: #2563eb; }
.quick-add-label.person-2 { color: #db2777; }
.quick-add-label.person-1 .person-avatar { background: #2563eb; }
.quick-add-label.person-2 .person-avatar { background: #db2777; }

.quick-add-inputs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.weight-number-input {
    width: 110px;
    padding: 8px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    outline: none;
    transition: border-color var(--transition);
}
.weight-number-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.1); }

.weight-date-input {
    padding: 8px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    outline: none;
    color: var(--gray-700);
    transition: border-color var(--transition);
}
.weight-date-input:focus { border-color: var(--green); }

.weight-notes-input {
    flex: 1;
    min-width: 120px;
    padding: 8px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    outline: none;
    transition: border-color var(--transition);
}
.weight-notes-input:focus { border-color: var(--green); }

.add-feedback {
    font-size: .82rem;
    font-weight: 500;
    padding: 4px 0;
}
.add-feedback.success { color: var(--green); }
.add-feedback.error   { color: var(--red); }

/* Person section */
.person-weight-section { display: flex; flex-direction: column; gap: 14px; }

.person-weight-header {
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}
.person-1-bg { background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%); border: 1px solid #bfdbfe; }
.person-2-bg { background: linear-gradient(135deg, #fce7f3 0%, #fdf2f8 100%); border: 1px solid #f9a8d4; }

.person-weight-title {
    display: flex;
    align-items: center;
    gap: 14px;
}
.person-weight-title .person-avatar {
    width: 44px; height: 44px; font-size: 1.1rem;
    box-shadow: var(--shadow-md);
}
.person-1-bg .person-avatar { background: #2563eb; }
.person-2-bg .person-avatar { background: #db2777; }

.person-weight-title h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 2px; }
.person-weight-title p  { font-size: .78rem; color: var(--gray-500); }

.current-weight-display { text-align: right; }
.current-weight-value { font-size: 2.5rem; font-weight: 800; color: var(--gray-800); line-height: 1; }
.current-weight-unit  { font-size: .9rem; font-weight: 500; color: var(--gray-500); margin-left: 4px; }

/* Stats grid */
.weight-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.weight-stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
}
.weight-stat-card.green-accent  { border-top: 3px solid var(--green); }
.weight-stat-card.red-accent    { border-top: 3px solid var(--red); }
.weight-stat-card.blue-accent   { border-top: 3px solid var(--blue); }
.weight-stat-card.orange-accent { border-top: 3px solid var(--orange); }

.wstat-label { font-size: .72rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; }
.wstat-value { font-size: 1.4rem; font-weight: 800; color: var(--gray-800); line-height: 1.2; }
.wstat-value small { font-size: .75rem; font-weight: 500; color: var(--gray-500); }
.wstat-sub { font-size: .75rem; color: var(--gray-500); }

.wstat-green  { color: var(--green); }
.wstat-red    { color: var(--red); }
.wstat-blue   { color: var(--blue); }
.wstat-orange { color: var(--orange); }

/* Goal progress */
.goal-progress { padding: 16px 20px; }
.goal-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--gray-700);
}
.goal-pct-label { color: var(--green); font-size: .9rem; }
.goal-progress-track {
    height: 10px;
    background: var(--gray-100);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 6px;
}
.goal-progress-fill {
    height: 100%;
    border-radius: 5px;
    min-width: 4px;
    transition: width .6s ease;
}
.person-1-fill { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.person-2-fill { background: linear-gradient(90deg, #db2777, #f472b6); }

.goal-progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: .72rem;
    color: var(--gray-400);
}

/* Chart */
.weight-chart-card {}
.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.chart-header h3 { font-size: .95rem; font-weight: 600; }

.chart-range-btns { display: flex; gap: 4px; }
.range-btn {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--gray-500);
    border: 1.5px solid var(--gray-200);
    background: var(--white);
    cursor: pointer;
    transition: all var(--transition);
}
.range-btn:hover  { border-color: var(--gray-400); color: var(--gray-700); }
.range-btn.active { background: var(--green); border-color: var(--green); color: var(--white); }

.chart-wrapper { position: relative; height: 240px; }

/* History */
.weight-empty {
    text-align: center;
    padding: 40px 24px;
    color: var(--gray-400);
}
.weight-empty svg { width: 48px; height: 48px; margin: 0 auto 12px; display: block; }
.weight-empty p { font-size: .9rem; color: var(--gray-500); }
.weight-empty-hint { font-size: .8rem !important; color: var(--gray-400) !important; margin-top: 4px; }

.weight-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.weight-history-header h3 { font-size: .95rem; font-weight: 600; }
.history-count { font-size: .78rem; color: var(--gray-400); font-weight: 500; }

.weight-history-list { display: flex; flex-direction: column; gap: 0; }

.history-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: .85rem;
}
.history-row:last-child { border-bottom: none; }

.history-date   { color: var(--gray-500); min-width: 80px; font-size: .8rem; }
.history-weight { font-weight: 700; color: var(--gray-800); min-width: 70px; }
.history-notes  { flex: 1; color: var(--gray-400); font-size: .78rem; font-style: italic; }
.history-delete {
    color: var(--gray-300);
    opacity: 0;
    padding: 4px;
    transition: all var(--transition);
    flex-shrink: 0;
}
.history-delete svg { width: 14px; height: 14px; }
.history-row:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--red); }

@media (max-width: 768px) {
    .quick-add-inputs { flex-direction: column; align-items: stretch; }
    .weight-number-input, .weight-date-input, .weight-notes-input { width: 100%; }
    .weight-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-wrapper { height: 200px; }
    .bottom-nav-item { width: 16.666%; font-size: .6rem; }
    .bottom-nav-item svg { width: 18px; height: 18px; }
}
@media (max-width: 480px) {
    .current-weight-value { font-size: 2rem; }
    .bottom-nav-item span { display: none; }
    .bottom-nav-item { padding-top: 16px; }
}

/* ═══════════════════════════════════════════════
   PLANS V2 — Monthly tabs + sidebar + preview
   ═══════════════════════════════════════════════ */

.plans-page-v2 { display:flex; flex-direction:column; gap:0; height:calc(100vh - 120px); overflow:hidden; }

/* Month tabs */
.month-tabs-wrap { background:var(--white); border-bottom:1px solid var(--gray-200); padding:0 16px; overflow-x:auto; flex-shrink:0; }
.month-tabs { display:flex; gap:2px; min-width:max-content; }
.month-tab { display:flex; flex-direction:column; align-items:center; gap:3px; padding:10px 14px 8px; border-bottom:3px solid transparent; color:var(--gray-500); text-decoration:none; font-size:.8rem; transition:color .15s; position:relative; }
.month-tab:hover { color:var(--primary); }
.month-tab.selected { color:var(--primary); border-bottom-color:var(--primary); font-weight:600; }
.month-tab.has-plan .month-abbr { font-weight:600; color:var(--gray-700); }
.month-tab.selected.has-plan .month-abbr { color:var(--primary); }
.month-dot { width:5px; height:5px; background:var(--primary); border-radius:50%; }
.month-abbr { font-size:.85rem; }

/* Body split */
.plans-body { display:flex; flex:1; overflow:hidden; }

/* Sidebar */
.plans-sidebar { width:280px; flex-shrink:0; border-right:1px solid var(--gray-200); background:var(--gray-50); display:flex; flex-direction:column; overflow:hidden; }
.plans-sidebar-header { display:flex; align-items:center; justify-content:space-between; padding:14px 16px; border-bottom:1px solid var(--gray-200); background:var(--white); flex-shrink:0; }
.plans-sidebar-header h2 { font-size:1rem; font-weight:700; margin:0; }
.plan-list { flex:1; overflow-y:auto; padding:10px; display:flex; flex-direction:column; gap:6px; }
.plan-list-empty { padding:24px 16px; text-align:center; color:var(--gray-500); font-size:.85rem; }
.plan-list-empty .hint { font-size:.75rem; color:var(--gray-400); margin-top:4px; }

.plan-list-item { background:var(--white); border:1px solid var(--gray-200); border-radius:8px; padding:10px 12px; cursor:pointer; transition:border-color .15s, box-shadow .15s; }
.plan-list-item:hover { border-color:var(--primary); box-shadow:0 0 0 2px rgba(37,99,235,.08); }
.plan-list-item.active { border-color:var(--primary); background:rgba(37,99,235,.03); }
.plan-list-item.template { border-style:dashed; background:var(--gray-50); cursor:default; }
.plan-list-active-badge { font-size:.65rem; font-weight:700; color:var(--primary); text-transform:uppercase; letter-spacing:.04em; margin-bottom:3px; }
.plan-list-name { font-size:.875rem; font-weight:600; color:var(--gray-800); }
.plan-list-desc { font-size:.75rem; color:var(--gray-500); margin-top:2px; }
.plan-list-meta { display:flex; gap:8px; font-size:.7rem; color:var(--gray-400); margin-top:4px; }
.plan-list-actions { display:flex; gap:4px; flex-wrap:wrap; margin-top:8px; }

.templates-divider { font-size:.7rem; text-transform:uppercase; letter-spacing:.06em; color:var(--gray-400); padding:10px 4px 4px; font-weight:600; }

/* Main content */
.plans-main { flex:1; overflow-y:auto; padding:20px; }
.plans-main-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:300px; text-align:center; color:var(--gray-400); gap:12px; }
.plans-main-empty svg { width:64px; height:64px; opacity:.3; }
.plans-main-empty h3 { color:var(--gray-600); font-size:1.1rem; margin:0; }
.plans-main-empty p { font-size:.875rem; max-width:360px; margin:0; }

/* Active plan header */
.active-plan-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
.active-plan-label { font-size:.7rem; text-transform:uppercase; letter-spacing:.06em; color:var(--gray-400); font-weight:600; }
.active-plan-name { font-size:1.2rem; font-weight:700; margin:2px 0 0; }

/* Preview grid (read-only) */
.plan-preview-panel { display:flex; flex-direction:column; gap:14px; }
.plan-preview-toolbar { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; padding:14px 16px; background:var(--white); border:1px solid var(--gray-200); border-radius:10px; }
.plan-preview-toolbar h3 { margin:0; font-size:1rem; color:var(--gray-800); }
.plan-preview-toolbar p { margin:3px 0 0; font-size:.8rem; color:var(--gray-500); }
.preview-week-grid { display:grid; grid-template-columns:repeat(7,minmax(210px,1fr)); gap:10px; overflow-x:auto; padding-bottom:8px; }
.preview-day-card { display:flex; flex-direction:column; min-width:210px; background:var(--white); border:1px solid var(--gray-200); border-radius:10px; overflow:hidden; }
.preview-day-name { display:flex; align-items:baseline; justify-content:space-between; gap:8px; padding:10px 12px; background:#f8fafc; border-bottom:1px solid var(--gray-200); }
.preview-day-short { font-size:.68rem; font-weight:800; text-transform:uppercase; letter-spacing:.06em; color:var(--primary); }
.preview-day-full { font-size:.92rem; font-weight:800; color:var(--gray-800); }
.preview-day-meals { display:flex; flex-direction:column; gap:8px; padding:10px; }
.preview-meal-slot { border:1px solid var(--gray-100); border-radius:8px; padding:8px; background:#fff; }
.preview-meal-slot.empty { background:var(--gray-50); border-color:var(--gray-100); }
.preview-meal-label { font-size:.68rem; text-transform:uppercase; letter-spacing:.05em; font-weight:800; color:var(--gray-500); margin-bottom:6px; }
.preview-person-list { display:flex; flex-direction:column; gap:5px; }
.preview-person-meal { display:flex; align-items:flex-start; gap:7px; font-size:.78rem; color:var(--gray-700); line-height:1.35; padding:6px 7px; border-radius:7px; min-height:34px; }
.preview-person-meal.person-1 { background:#eff6ff; border-left:3px solid #2563eb; }
.preview-person-meal.person-2 { background:#fdf2f8; border-left:3px solid #db2777; }
.preview-meal-text { flex:1; min-width:0; overflow-wrap:anywhere; }
.preview-kcal { font-size:.68rem; color:var(--green); font-weight:800; margin-left:auto; white-space:nowrap; flex-shrink:0; }
.preview-empty-meal { font-size:.74rem; color:var(--gray-400); font-style:italic; padding:4px 0; }
.person-legend { display:flex; gap:12px; flex-wrap:wrap; }
.legend-item { display:flex; align-items:center; gap:5px; font-size:.8rem; color:var(--gray-600); }
.person-1-legend { color:var(--primary); }
.person-2-legend { color:var(--person2-color,#db2777); }

/* ═══════════════════════════════════════════════
   PLANS EDITOR — Visual weekly grid
   ═══════════════════════════════════════════════ */

.editor-page { display:flex; flex-direction:column; height:calc(100vh - 120px); overflow:hidden; }

.editor-topbar { display:flex; align-items:center; justify-content:space-between; padding:10px 16px; background:var(--white); border-bottom:1px solid var(--gray-200); flex-shrink:0; gap:12px; flex-wrap:wrap; }
.editor-topbar-left { display:flex; align-items:center; gap:12px; min-width:0; }
.editor-topbar-right { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.editor-plan-title { display:flex; align-items:center; gap:8px; min-width:0; }
.editor-plan-name { font-weight:700; font-size:.95rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.editor-plan-month { font-size:.75rem; color:var(--gray-400); background:var(--gray-100); padding:2px 8px; border-radius:10px; white-space:nowrap; }
.badge-active { font-size:.65rem; font-weight:700; color:var(--white); background:var(--primary); padding:2px 7px; border-radius:10px; text-transform:uppercase; letter-spacing:.04em; }

.person-legend-inline { display:flex; gap:6px; }
.legend-pill { display:flex; align-items:center; gap:5px; font-size:.78rem; padding:3px 10px; border-radius:12px; background:var(--gray-100); color:var(--gray-600); }

/* Grid */
.editor-grid-wrap { flex:1; overflow:auto; padding:12px 16px 24px; }
.editor-grid { min-width:900px; }

.editor-grid-header { display:grid; grid-template-columns:100px repeat(7,1fr); gap:4px; margin-bottom:4px; }
.editor-meal-label-col { } /* shared col */
.editor-day-head { text-align:center; padding:6px 4px; font-size:.7rem; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--gray-500); }
.day-full { display:none; }

.editor-meal-row { display:grid; grid-template-columns:100px repeat(7,1fr); gap:4px; margin-bottom:4px; }
.editor-meal-label-col { display:flex; align-items:center; padding:0 8px; font-size:.7rem; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:var(--gray-400); }

.editor-cell { display:flex; flex-direction:column; gap:2px; }

.editor-person-slot { display:flex; align-items:flex-start; gap:4px; padding:5px 6px; border-radius:6px; cursor:pointer; border:1.5px solid transparent; transition:border-color .15s, background .15s; font-size:.72rem; line-height:1.3; min-height:36px; }
.editor-person-slot.person-1-slot { background:rgba(37,99,235,.05); border-color:rgba(37,99,235,.12); }
.editor-person-slot.person-1-slot:hover { border-color:#2563eb; background:rgba(37,99,235,.1); }
.editor-person-slot.person-2-slot { background:rgba(219,39,119,.05); border-color:rgba(219,39,119,.12); }
.editor-person-slot.person-2-slot:hover { border-color:#db2777; background:rgba(219,39,119,.1); }
.editor-person-slot.empty { background:var(--gray-50); border-color:var(--gray-100); }
.editor-person-slot.empty:hover { background:var(--gray-100); border-color:var(--gray-300); }

.slot-text { flex:1; color:var(--gray-700); font-size:.7rem; line-height:1.3; }
.slot-kcal { font-size:.62rem; color:var(--gray-400); white-space:nowrap; flex-shrink:0; align-self:flex-end; }
.slot-empty-label { color:var(--gray-300); font-size:.68rem; }

/* ── Meal modal v2 ── */
.meal-modal-v2 { max-width:540px; display:flex; flex-direction:column; max-height:90vh; }
.meal-modal-sub { font-size:.8rem; color:var(--gray-500); margin-top:3px; display:flex; align-items:center; gap:5px; }

.meal-modal-scroll { flex:1; overflow-y:auto; min-height:0; }

.meal-modal-section { padding:16px 20px; }
.meal-modal-section + .meal-modal-section { border-top:1px solid var(--gray-100); }
.meal-modal-section-alts { background:var(--gray-50); }
.meal-modal-section-title { font-size:.68rem; font-weight:700; text-transform:uppercase; letter-spacing:.07em; color:var(--gray-400); margin-bottom:12px; display:flex; align-items:center; gap:8px; }
.meal-modal-section-hint { font-weight:400; text-transform:none; letter-spacing:0; font-style:italic; color:var(--gray-400); font-size:.65rem; }

.meal-main-meta { display:flex; align-items:flex-end; gap:12px; flex-wrap:wrap; margin-top:4px; }
.meal-cal-group { flex:0 0 110px; margin:0 !important; }
.meal-cal-group input { width:100%; }
.meal-main-actions { display:flex; gap:6px; flex-wrap:wrap; align-items:center; flex:1; }

/* alternatives list */
.alt-list { display:flex; flex-direction:column; gap:6px; margin-bottom:10px; }
.alt-empty { font-size:.8rem; color:var(--gray-400); font-style:italic; margin:0 0 10px; }
.alt-item { display:flex; align-items:flex-start; gap:8px; padding:9px 12px; background:#fff; border:1px solid var(--gray-200); border-radius:8px; }
.alt-item-body { flex:1; min-width:0; display:flex; flex-direction:column; gap:2px; }
.alt-item-desc { font-size:.82rem; color:var(--gray-700); line-height:1.4; }
.alt-item-kcal { font-size:.7rem; color:var(--gray-400); }
.alt-item-actions { display:flex; gap:4px; flex-shrink:0; padding-top:1px; }

/* inline add/edit form */
.alt-inline-form { background:#fff; border:1.5px solid #93c5fd; border-radius:10px; padding:14px; margin-bottom:10px; }
.alt-form-meta { display:flex; align-items:flex-end; gap:12px; flex-wrap:wrap; margin-top:8px; }
.alt-form-actions { display:flex; gap:6px; align-items:center; flex:1; flex-wrap:wrap; }

.alt-add-btn { width:100%; justify-content:center; margin-top:2px; }

/* Copy-all modal person buttons */
.modal .btn .person-avatar.small { margin-right:2px; }

/* Copy-all modal person buttons */
.modal .btn .person-avatar.small { margin-right:2px; }

/* Person avatar sizes */
.person-avatar.small { width:18px; height:18px; font-size:.65rem; }
.person-avatar.tiny  { width:14px; height:14px; font-size:.6rem; flex-shrink:0; }
:root { --person2-color: #db2777; }
.person-avatar { width:22px; height:22px; border-radius:50%; background:var(--primary); color:var(--white); display:inline-flex; align-items:center; justify-content:center; font-weight:700; font-size:.7rem; flex-shrink:0; }
.person-2-slot .person-avatar, .person-avatar[style*="person2"] { background:var(--person2-color); }

/* Plan form */
.field-hint { font-size:.72rem; color:var(--gray-400); margin-top:4px; }
.checkbox-card { display:flex; align-items:flex-start; gap:10px; padding:12px; border:1px solid var(--gray-200); border-radius:8px; background:var(--gray-50); cursor:pointer; }
.checkbox-card input { margin-top:3px; flex-shrink:0; }
.checkbox-card span { display:flex; flex-direction:column; gap:3px; min-width:0; }
.checkbox-card strong { font-size:.86rem; color:var(--gray-800); }
.checkbox-card small { font-size:.76rem; color:var(--gray-500); line-height:1.35; }

.login-body { min-height:100vh; background:linear-gradient(135deg,#f0fdf4 0%,#eff6ff 100%); }
.login-shell { min-height:100vh; display:flex; align-items:center; justify-content:center; padding:24px; }
.login-panel { width:100%; max-width:380px; background:#fff; border:1px solid var(--gray-200); border-radius:12px; padding:24px; box-shadow:0 18px 50px rgba(15,23,42,.08); }
.login-brand { display:flex; align-items:center; gap:12px; margin-bottom:22px; }
.login-brand svg { width:42px; height:42px; flex-shrink:0; }
.login-brand h1 { margin:0; font-size:1.35rem; color:var(--gray-900); }
.login-brand p { margin:2px 0 0; font-size:.82rem; color:var(--gray-500); }
.login-form { display:flex; flex-direction:column; gap:12px; }
.login-submit { width:100%; justify-content:center; margin-top:4px; }

@media (max-width:1024px) {
    .plans-sidebar { width:240px; }
    .preview-week-grid { grid-template-columns:repeat(7,minmax(190px,1fr)); }
}

@media (max-width:768px) {
    .plans-page-v2 { height:auto; min-height:calc(100vh - 120px); overflow:visible; }
    .plans-body { flex-direction:column; }
    .plans-sidebar { width:100%; border-right:none; border-bottom:1px solid var(--gray-200); max-height:none; overflow:visible; }
    .plan-list { max-height:260px; overflow-y:auto; }
    .plans-main { overflow:visible; padding:14px; }
    .active-plan-header { align-items:flex-start; flex-direction:column; gap:10px; }
    .active-plan-header .btn { width:100%; justify-content:center; }
    .plan-preview-toolbar { flex-direction:column; padding:12px; }
    .preview-week-grid { grid-template-columns:1fr; overflow:visible; gap:12px; padding-bottom:0; }
    .preview-day-card { min-width:0; }
    .preview-day-name { position:sticky; top:0; z-index:1; }
    .preview-meal-slot { padding:10px; }
    .preview-person-meal { font-size:.84rem; padding:8px; }
    .editor-grid-header, .editor-meal-row { grid-template-columns:70px repeat(7,1fr); }
    .editor-meal-label-col { font-size:.6rem; padding:0 4px; }
    .day-full { display:none !important; }
}

/* Plans activation picker */
.plans-activate-picker { padding:20px; max-width:640px; }
.plans-activate-picker-head { display:flex; align-items:flex-start; gap:14px; margin-bottom:20px; }
.plans-activate-picker-head svg { width:36px; height:36px; flex-shrink:0; color:var(--gray-400); margin-top:2px; }
.plans-activate-picker-head h3 { margin:0 0 4px; font-size:1rem; }
.plans-activate-picker-head p { margin:0; font-size:.85rem; color:var(--gray-500); }

.plans-activate-list { display:flex; flex-direction:column; gap:10px; }
.plans-activate-item { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 16px; background:var(--white); border:1.5px solid var(--gray-200); border-radius:10px; transition:border-color .15s; }
.plans-activate-item:hover { border-color:var(--primary); }
.plans-activate-item-info { flex:1; min-width:0; }
.plans-activate-item-name { font-weight:600; font-size:.9rem; color:var(--gray-800); }
.plans-activate-item-desc { font-size:.78rem; color:var(--gray-500); margin-top:2px; }
.plans-activate-item-meta { font-size:.72rem; color:var(--gray-400); margin-top:4px; }
.plans-activate-item-actions { display:flex; gap:8px; flex-shrink:0; }

/* Month checkbox grid (form) */
.month-checkbox-grid,
.dup-month-grid { display:grid; grid-template-columns:repeat(6,1fr); gap:6px; margin-top:6px; }
.month-checkbox-item { display:flex; align-items:center; justify-content:center; padding:7px 4px; border:1.5px solid var(--gray-200); border-radius:8px; cursor:pointer; font-size:.78rem; font-weight:600; color:var(--gray-500); transition:border-color .12s, background .12s, color .12s; user-select:none; }
.month-checkbox-item:hover { border-color:var(--primary); color:var(--primary); }
.month-checkbox-item.checked { border-color:var(--primary); background:var(--primary); color:#fff; }
.month-checkbox-item input[type=checkbox] { display:none; }
@media (max-width:480px) { .month-checkbox-grid, .dup-month-grid { grid-template-columns:repeat(4,1fr); } }

.dup-month-check { display:flex; align-items:center; justify-content:center; padding:7px 4px; border:1.5px solid var(--gray-200); border-radius:8px; cursor:pointer; font-size:.78rem; font-weight:600; color:var(--gray-500); transition:border-color .12s, background .12s, color .12s; user-select:none; }
.dup-month-check:hover { border-color:#2563eb; color:#2563eb; }
.dup-month-check:has(input:checked) { border-color:#2563eb; background:#2563eb; color:#fff; }
.dup-month-check input[type=checkbox] { display:none; }

/* ═══════════════════════════════════════════════
   NAV GROUP LABELS
   ═══════════════════════════════════════════════ */
.nav-group-label { font-size:.62rem; font-weight:700; text-transform:uppercase; letter-spacing:.08em; color:var(--gray-400); padding:12px 16px 2px; }

/* ═══════════════════════════════════════════════
   TODAY VIEW
   ═══════════════════════════════════════════════ */
.today-page { max-width:860px; }
.today-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; flex-wrap:wrap; gap:10px; }
.today-date-badge { font-size:1.4rem; font-weight:800; color:var(--gray-800); }
.today-date-full { font-size:.85rem; color:var(--gray-400); margin-top:1px; }
.today-plan-badge { display:flex; align-items:center; gap:6px; font-size:.78rem; font-weight:600; color:var(--primary); background:rgba(37,99,235,.08); padding:5px 12px; border-radius:20px; }
.today-plan-badge svg { width:14px; height:14px; }

.today-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:300px; text-align:center; color:var(--gray-400); gap:12px; }
.today-empty svg { width:56px; height:56px; opacity:.3; }
.today-empty h3 { color:var(--gray-600); font-size:1rem; margin:0; }
.today-empty p { font-size:.875rem; max-width:320px; margin:0; }

.today-actions-bar { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:20px; padding:14px 16px; background:var(--white); border:1px solid var(--gray-200); border-radius:10px; }

.today-meals { display:flex; flex-direction:column; gap:14px; }
.today-meal-card { background:var(--white); border:1px solid var(--gray-200); border-radius:12px; overflow:hidden; }
.today-meal-header { display:flex; align-items:center; gap:10px; padding:12px 16px; background:var(--gray-50); border-bottom:1px solid var(--gray-100); }
.today-meal-icon { font-size:1.2rem; }
.today-meal-title { font-size:.9rem; font-weight:700; margin:0; color:var(--gray-700); }

.today-meal-persons { display:flex; gap:0; flex-direction:column; }
.today-person-block { padding:12px 16px; border-bottom:1px solid var(--gray-50); }
.today-person-block:last-child { border-bottom:none; }
.today-person-block.person-1 { border-left:3px solid var(--primary); }
.today-person-block.person-2 { border-left:3px solid var(--person2-color); }
.today-person-block.shared { border-left:3px solid #16a34a; background:linear-gradient(90deg,rgba(22,163,74,.06),#fff 70%); }
.today-person-header { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.today-person-name { font-size:.82rem; font-weight:600; color:var(--gray-600); }
.today-shared-badge { font-size:.68rem; font-weight:700; color:#166534; background:rgba(22,163,74,.1); border:1px solid rgba(22,163,74,.18); padding:2px 7px; border-radius:10px; }
.today-kcal { margin-left:auto; font-size:.75rem; color:var(--gray-400); background:var(--gray-100); padding:1px 8px; border-radius:10px; }
.today-person-desc { font-size:.875rem; color:var(--gray-700); line-height:1.5; margin-bottom:8px; }
.today-person-actions { display:flex; gap:8px; flex-wrap:wrap; }

.today-recipe-area { background:var(--gray-50); border:1px solid var(--gray-100); border-radius:8px; padding:14px; margin:10px 0; font-size:.82rem; line-height:1.6; }
.today-recipe-area h4 { font-size:.85rem; font-weight:700; margin:10px 0 4px; color:var(--gray-700); }
.today-recipe-area h4:first-child { margin-top:0; }
.today-recipe-area ul { margin:4px 0; padding-left:18px; }
.today-recipe-area li { margin-bottom:2px; }
.recipe-loading { display:flex; align-items:center; gap:8px; color:var(--gray-500); font-style:italic; }
.recipe-error { color:#dc2626; font-size:.82rem; }

.today-shopping-result { margin-top:16px; }

/* Today — alternatives picker */
.today-alt-picker { display:flex; gap:5px; flex-wrap:wrap; margin-bottom:8px; }
.today-alt-btn { padding:3px 10px; border:1.5px solid var(--gray-200); border-radius:20px; background:#fff; cursor:pointer; font-size:.72rem; font-weight:600; color:var(--gray-500); transition:all .12s; white-space:nowrap; }
.today-alt-btn:hover:not(.active) { border-color:#2563eb; color:#2563eb; }
.today-alt-btn.active { border-color:#16a34a; background:#16a34a; color:#fff; }
.today-person-block.person-1 .today-alt-btn.active { border-color:#2563eb; background:#2563eb; }

/* Editor — slot alt badge */
.slot-alt-badge { font-size:.6rem; font-weight:700; background:rgba(37,99,235,.12); color:#1d4ed8; border-radius:8px; padding:1px 5px; margin-left:auto; flex-shrink:0; }

/* Editor modal — alternatives section */
.shopping-result-box { display:flex; align-items:center; gap:8px; padding:12px 16px; background:rgba(22,163,74,.08); border:1px solid rgba(22,163,74,.2); border-radius:8px; font-size:.875rem; color:var(--gray-700); flex-wrap:wrap; }

/* ═══════════════════════════════════════════════
   WEEKLY SHOPPING / SPENDING
   ═══════════════════════════════════════════════ */
.weekly-shopping-page { display:flex; flex-direction:column; gap:20px; }

.spending-dashboard { background:var(--white); border:1px solid var(--gray-200); border-radius:12px; padding:20px; }
.spending-stats { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:16px; }
.spending-stat { text-align:center; }
.spending-stat-value { font-size:1.4rem; font-weight:800; color:var(--gray-800); }
.spending-stat-label { font-size:.72rem; color:var(--gray-400); text-transform:uppercase; letter-spacing:.05em; margin-top:2px; }
.spending-chart-wrap { margin-top:4px; }

.weekly-shopping-body { display:grid; grid-template-columns:1fr 280px; gap:16px; }
.weekly-plan-card { padding:16px; }
.weekly-plan-card-header { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.weekly-plan-label { font-size:.7rem; text-transform:uppercase; letter-spacing:.06em; color:var(--gray-400); font-weight:600; }
.weekly-plan-card-header h3 { font-size:.95rem; font-weight:700; margin:3px 0; }
.weekly-plan-desc { font-size:.78rem; color:var(--gray-500); margin:2px 0 0; }

.spending-row { display:flex; align-items:center; justify-content:space-between; padding:8px 0; border-bottom:1px solid var(--gray-100); }
.spending-row:last-child { border-bottom:none; }
.spending-row-info { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.spending-row-amount { font-weight:700; font-size:.9rem; color:var(--gray-800); }
.spending-row-date { font-size:.75rem; color:var(--gray-400); }
.spending-row-notes { font-size:.75rem; color:var(--gray-500); }

.spend-type-btn { display:inline-flex; align-items:center; justify-content:center; padding:5px 12px; border:1.5px solid var(--gray-200); border-radius:6px; cursor:pointer; font-size:.78rem; font-weight:600; color:var(--gray-500); transition:all .12s; }
.spend-type-btn.active { border-color:var(--primary); background:var(--primary); color:#fff; }
.spend-type-btn:hover:not(.active) { border-color:var(--primary); color:var(--primary); }

.weekly-overview { display:grid; grid-template-columns:repeat(7,1fr); gap:4px; }
.weekly-overview-day { display:flex; flex-direction:column; align-items:center; gap:4px; }
.weekly-overview-day-name { font-size:.62rem; font-weight:700; color:var(--gray-500); text-transform:uppercase; }
.weekly-overview-dot { width:10px; height:10px; border-radius:50%; background:var(--gray-100); }
.weekly-overview-dot.filled { background:var(--primary); }

.spinner { width:16px; height:16px; border:2px solid var(--gray-200); border-top-color:var(--primary); border-radius:50%; animation:spin .7s linear infinite; flex-shrink:0; }
@keyframes spin { to { transform:rotate(360deg); } }

@media (max-width:768px) {
    .spending-stats { grid-template-columns:repeat(2,1fr); }
    .weekly-shopping-body { grid-template-columns:1fr; }
    .weekly-shopping-right { order:-1; }
}

/* ═══════════════════════════════════════════════
   SHOPPING V2 — Spesa del momento panel
   ═══════════════════════════════════════════════ */
.shopping-page-v2 { display:flex; flex-direction:column; gap:16px; }

.spesa-momento-panel { background:var(--white); border:1.5px solid #2563eb; border-radius:12px; overflow:hidden; }
.spesa-momento-header { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; cursor:pointer; user-select:none; }
.spesa-momento-header:hover { background:rgba(37,99,235,.03); }
.spesa-momento-title { display:flex; align-items:center; gap:8px; font-size:.9rem; }
.spesa-momento-title svg { width:16px; height:16px; color:#2563eb; flex-shrink:0; }
.spesa-plan-chip { font-size:.7rem; background:rgba(37,99,235,.1); color:var(--primary); padding:2px 8px; border-radius:10px; font-weight:600; }
.spesa-chevron { width:18px; height:18px; color:var(--gray-400); transition:transform .2s; flex-shrink:0; }

.spesa-momento-body { padding:0 16px 16px; border-top:1px solid var(--gray-100); }
.spesa-section-label { font-size:.68rem; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--gray-400); margin:12px 0 6px; }

.spesa-day-picker { display:flex; gap:6px; }
.spesa-day-btn { flex:1; display:flex; flex-direction:column; align-items:center; gap:3px; padding:7px 4px; border:2px solid #e5e7eb; border-radius:8px; background:#fff; cursor:pointer; font-size:.75rem; font-weight:600; color:#9ca3af; transition:all .12s; position:relative; }
.spesa-day-btn:hover:not(.active) { border-color:#2563eb; color:#2563eb; }
.spesa-day-btn.active { border-color:#2563eb !important; background:#2563eb !important; color:#fff !important; }
.spesa-day-btn.active .spesa-today-dot { background:#fff; }
.spesa-day-btn.no-meals { opacity:.4; }
.spesa-today-dot { width:5px; height:5px; background:currentColor; border-radius:50%; }
.spesa-day-short { font-size:.7rem; }

.spesa-meal-filter { display:flex; gap:6px; flex-wrap:wrap; }
.spesa-meal-btn { padding:6px 14px; border:2px solid #e5e7eb; border-radius:20px; background:#fff; cursor:pointer; font-size:.78rem; font-weight:600; color:#9ca3af; transition:all .12s; }
.spesa-meal-btn:hover:not(.active) { border-color:#2563eb; color:#2563eb; }
.spesa-meal-btn.active { border-color:#16a34a !important; background:#16a34a !important; color:#fff !important; }

.spesa-meal-preview { margin-top:12px; }
.spesa-preview-list { display:flex; flex-direction:column; gap:4px; }
.spesa-preview-row { display:flex; align-items:flex-start; gap:8px; padding:8px; background:var(--gray-50); border-radius:6px; font-size:.78rem; }
.spesa-preview-main { flex:1; min-width:0; display:flex; flex-direction:column; gap:5px; }
.spesa-preview-head { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.spesa-preview-meal-label { font-weight:700; color:var(--gray-600); flex-shrink:0; }
.spesa-preview-person { font-size:.68rem; color:var(--gray-400); }
.spesa-preview-desc { color:var(--gray-700); line-height:1.35; }
.spesa-preview-kcal { font-size:.68rem; color:var(--gray-400); flex-shrink:0; }
.spesa-alt-picker { margin:0; }
.spesa-alt-picker .today-alt-btn { max-width:100%; overflow:hidden; text-overflow:ellipsis; }
.spesa-no-meals { font-size:.8rem; color:var(--gray-400); font-style:italic; padding:6px 0; margin:0; }

.spesa-generate-row { display:flex; align-items:center; gap:12px; margin-top:14px; flex-wrap:wrap; }
.spesa-gen-result { font-size:.82rem; padding:6px 12px; border-radius:6px; }
.spesa-gen-result.success { background:rgba(22,163,74,.08); color:#166534; border:1px solid rgba(22,163,74,.2); }
.spesa-gen-result.error { background:rgba(220,38,38,.08); color:#991b1b; border:1px solid rgba(220,38,38,.2); }

.pantry-panel { background:var(--white); border:1px solid var(--gray-200); border-radius:12px; padding:14px 16px; }
.pantry-header { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.pantry-title { display:flex; align-items:center; gap:8px; font-size:.92rem; color:var(--gray-800); }
.pantry-title svg { width:16px; height:16px; color:#7c3aed; flex-shrink:0; }
.pantry-subtitle { margin:4px 0 0; font-size:.78rem; color:var(--gray-500); }
.pantry-suggestions { margin-top:12px; padding:10px; background:#fff7ed; border:1px solid #fed7aa; border-radius:8px; }
.pantry-suggestions-label { font-size:.68rem; font-weight:800; text-transform:uppercase; letter-spacing:.06em; color:#9a3412; margin-bottom:7px; }
.pantry-chip-list { display:flex; flex-wrap:wrap; gap:6px; }
.pantry-chip { display:inline-flex; align-items:center; gap:5px; max-width:100%; padding:5px 9px; border:1px solid var(--gray-200); border-radius:18px; background:#fff; color:var(--gray-700); font-size:.76rem; font-weight:600; cursor:pointer; }
.pantry-chip span { color:var(--gray-400); font-weight:500; }
.pantry-chip small { color:#dc2626; font-size:.66rem; font-weight:700; }
.pantry-chip.warning { border-color:#fdba74; }
.pantry-list { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:8px; margin-top:12px; }
.pantry-item { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px 10px; background:var(--gray-50); border-radius:8px; }
.pantry-item-info { display:flex; align-items:baseline; gap:6px; flex-wrap:wrap; min-width:0; cursor:pointer; }
.pantry-item-info strong { font-size:.82rem; color:var(--gray-800); }
.pantry-item-info span { font-size:.72rem; color:var(--gray-500); }
.pantry-item-info em { font-size:.66rem; color:var(--gray-400); font-style:normal; }
.pantry-empty { margin:12px 0 2px; font-size:.82rem; color:var(--gray-400); }
.item-delete.visible { opacity:1; }

.list-type-section { background:var(--white); border:1px solid var(--gray-200); border-radius:12px; overflow:hidden; }
.list-type-header { display:flex; align-items:center; gap:8px; padding:10px 16px; font-size:.82rem; font-weight:700; border-bottom:1px solid var(--gray-100); }
.list-type-header svg { width:15px; height:15px; flex-shrink:0; }
.list-type-header span:first-of-type { flex:1; }
.list-type-count { font-size:.7rem; font-weight:600; padding:2px 7px; border-radius:10px; }
.list-type-momento { color:#b45309; background:#fffbeb; border-bottom-color:#fde68a; }
.list-type-momento .list-type-count { background:#fef3c7; color:#92400e; }
.list-type-weekly { color:#1d4ed8; background:#eff6ff; border-bottom-color:#bfdbfe; }
.list-type-weekly .list-type-count { background:#dbeafe; color:#1e40af; }
.list-type-manual { color:#374151; background:#f9fafb; border-bottom-color:#e5e7eb; }
.list-type-manual .list-type-count { background:#e5e7eb; color:#374151; }
.item-cat-badge { font-size:.65rem; color:var(--gray-400); border:1px solid var(--gray-200); border-radius:8px; padding:1px 6px; }

.shopping-meta-row { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.shopping-meta-right { display:flex; align-items:center; gap:12px; }
.spend-quick { display:flex; align-items:center; gap:5px; font-size:.82rem; color:var(--gray-600); cursor:pointer; padding:4px 10px; border:1px solid var(--gray-200); border-radius:8px; transition:border-color .12s; }
.spend-quick:hover { border-color:#2563eb; color:#2563eb; }
.spend-quick svg { width:14px; height:14px; }
.spend-quick-label { font-size:.68rem; color:var(--gray-400); }

.spending-history-strip { background:var(--white); border:1px solid var(--gray-200); border-radius:10px; padding:12px 16px; }
.spending-strip-head { display:flex; align-items:center; justify-content:space-between; font-size:.78rem; font-weight:600; color:var(--gray-500); margin-bottom:8px; }
.spending-strip-list { display:flex; flex-direction:column; gap:4px; }
.spending-strip-item { display:flex; align-items:center; gap:8px; font-size:.8rem; padding:4px 0; border-bottom:1px solid var(--gray-50); }
.spending-strip-item:last-child { border-bottom:none; }
.spending-strip-item strong { color:var(--gray-800); min-width:56px; }
.spending-strip-item span { color:var(--gray-500); }
.spending-strip-notes { color:var(--gray-400) !important; font-style:italic; flex:1; }
.spending-strip-del { margin-left:auto; background:none; border:none; cursor:pointer; color:var(--gray-300); font-size:.75rem; padding:2px 4px; }
.spending-strip-del:hover { color:#dc2626; }
