/* ── Tokens ───────────────────────────────────────────────────────────── */
:root {
    --primary:        #1565c0;
    --primary-light:  #e3f2fd;
    --primary-dark:   #0d47a1;
    --accent:         #f57c00;
    --accent-dark:    #e65100;
    --bg:             #f5f5f7;
    --surface:        #ffffff;
    --surface-hover:  #fafafc;
    --text:           #1c1c1e;
    --text-secondary: #6b6b70;
    --muted:          var(--text-secondary);
    --divider:        #e2e2e7;
    --shadow-sm:      0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:      0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg:      0 12px 32px rgba(0,0,0,0.18);
    --radius:         12px;
    --radius-sm:      8px;
    --header-h:       60px;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

[x-cloak] { display: none !important; }

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

.muted { color: var(--muted); }

/* ── Topbar ───────────────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 30;
    background: var(--surface);
    border-bottom: 1px solid var(--divider);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.topbar-inner {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    height: var(--header-h);
    padding: 0 16px;
    max-width: 1400px;
    margin: 0 auto;
}
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-size: 1.05rem; font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.brand-logo {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: block;
    box-shadow: 0 1px 3px rgba(21,101,192,0.25);
}
.topbar-actions {
    display: flex; gap: 6px; align-items: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.875rem; font-weight: 500;
    transition: background 0.15s, color 0.15s, transform 0.05s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-ghost          { color: var(--text); }
.btn-ghost:hover    { background: var(--primary-light); }

.btn-primary        { background: var(--primary); color: white; }
.btn-primary:hover  { background: var(--primary-dark); }

.btn-accent         { background: var(--accent); color: white; }
.btn-accent:hover   { background: var(--accent-dark); }

.btn .ico   { font-size: 1rem; line-height: 1; }
.btn .label { display: inline; }

/* ── Banners ──────────────────────────────────────────────────────────── */
.banner {
    padding: 12px 16px;
    font-size: 0.9rem;
}
.banner-error {
    background: #ffebee;
    color: #b71c1c;
    border-bottom: 1px solid #ef9a9a;
}

/* ── Layout ───────────────────────────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.planner { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.list-aside {
    position: sticky;
    top: calc(var(--header-h) + 20px);
    align-self: start;
    max-height: calc(100vh - var(--header-h) - 40px);
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }
    .list-aside {
        position: static;
        max-height: none;
    }
    .layout[data-view="planner"] .list-aside { display: none; }
    .layout[data-view="list"]    .planner    { display: none; }
    .topbar-actions .btn .label { display: none; }
    .topbar-actions .btn         { padding: 8px 10px; }
    .topbar-actions .btn-accent .label { display: inline; }
    .brand { font-size: 0.95rem; }
    .brand-logo { width: 28px; height: 28px; }
}
@media (max-width: 480px) {
    .brand-text { display: none; }
    .topbar-actions .btn-accent .label { display: none; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
}
.card-title {
    font-size: 0.72rem; font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* ── Form fields ──────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.input {
    width: 100%;
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    background: var(--surface);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.15);
}
select.input {
    appearance: none;
    -webkit-appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
        linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
    background-position: right 14px top 50%, right 9px top 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 28px;
}
.textarea { resize: vertical; min-height: 64px; font-family: inherit; }

.settings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

/* ── Days ─────────────────────────────────────────────────────────────── */
.days {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.day {
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--surface);
    display: flex; flex-direction: column; gap: 6px;
}
.day-header {
    font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--primary);
}
.meal {
    display: flex; align-items: center; gap: 6px;
}
.meal-tag {
    flex-shrink: 0;
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
}
.meal-recette { flex: 1; font-size: 0.85rem; font-style: italic; }
.meal-select  { flex: 1; min-width: 0; padding: 6px 10px; padding-right: 24px; font-size: 0.85rem; }
.meal-select.input { background-position: right 12px top 50%, right 7px top 50%; }
.input.gens {
    width: 56px; padding: 6px 8px; font-size: 0.85rem;
    text-align: center; flex-shrink: 0;
}
.pers { font-size: 0.72rem; color: var(--text-secondary); flex-shrink: 0; }

/* ── Extras ───────────────────────────────────────────────────────────── */
.extras {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 14px;
}
.check {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
}
.check:hover { background: var(--primary-light); }
.check input[type="checkbox"] {
    width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer;
}

/* ── Custom items ─────────────────────────────────────────────────────── */
.add-item {
    display: grid;
    grid-template-columns: 2fr 80px 80px 1.3fr auto;
    gap: 8px;
    align-items: center;
}
.ai-name { grid-column: 1; }
.ai-qty  { grid-column: 2; }
.ai-unit { grid-column: 3; }
.ai-rayon{ grid-column: 4; }
.ai-add  { grid-column: 5; padding: 9px 14px; }

@media (max-width: 540px) {
    .add-item {
        grid-template-columns: 1fr 1fr;
    }
    .ai-name { grid-column: 1 / -1; }
    .ai-qty  { grid-column: 1; }
    .ai-unit { grid-column: 2; }
    .ai-rayon{ grid-column: 1 / span 1; }
    .ai-add  { grid-column: 2; }
}

.custom-items {
    margin-top: 10px;
    display: flex; flex-direction: column; gap: 4px;
}
.custom-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg);
}
.ci-name { flex: 1; font-size: 0.9rem; }
.ci-qty  { font-size: 0.8rem; }
.x {
    width: 28px; height: 28px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: background 0.15s;
}
.x:hover { background: var(--divider); color: var(--text); }

/* ── List panel ───────────────────────────────────────────────────────── */
.list-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: flex; flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - var(--header-h) - 40px);
}
@media (max-width: 960px) {
    .list-card {
        max-height: none;
        box-shadow: var(--shadow-sm);
    }
}

.list-head {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--divider);
    background: var(--surface);
}
.list-head .card-title { margin-bottom: 0; flex: 1; }
.pill {
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 999px;
}
.list-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 4px 8px;
}
.empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 32px 16px;
    font-size: 0.9rem;
}

.rayon { margin-bottom: 4px; }
.rayon-name {
    font-size: 0.65rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary);
    padding: 4px 10px;
    border-bottom: 1px solid var(--divider);
    margin-bottom: 1px;
    position: sticky; top: 0;
    background: var(--surface);
}
.rayon-items { display: flex; flex-direction: column; }

.liste-item {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.liste-item:hover { background: var(--primary-light); }

.li-name { flex: 1; font-size: 0.875rem; min-width: 0; }
.li-qty  { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }

.qty-btn {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 1px solid var(--divider);
    color: var(--primary);
    background: var(--surface);
    font-size: 0.875rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.qty-btn:hover { background: var(--primary-light); border-color: var(--primary); }

.qty-val {
    min-width: 44px;
    text-align: center;
    font-size: 0.8rem; font-weight: 500;
    color: var(--primary);
    padding: 1px 4px;
    border-bottom: 1px dashed transparent;
    cursor: pointer;
}
.qty-val:hover { border-bottom-color: var(--primary); }

.qty-edit { display: inline-flex; align-items: center; gap: 3px; }
.qty-input {
    width: 52px;
    text-align: center;
    font-size: 0.8rem; font-weight: 500;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 1px 4px;
    background: var(--surface);
    outline: none;
}
.qty-edit .unit { font-size: 0.75rem; }

/* ── Mobile view switch (Recettes / Liste) ────────────────────────────── */
.view-switch { display: none; }
@media (max-width: 960px) {
    .view-switch {
        display: flex;
        gap: 4px;
        background: var(--surface);
        border-bottom: 1px solid var(--divider);
        padding: 8px 12px;
        position: sticky;
        top: var(--header-h);
        z-index: 25;
    }
    .vs-tab {
        flex: 1;
        padding: 9px 12px;
        border-radius: var(--radius-sm);
        font-size: 0.9rem; font-weight: 500;
        color: var(--text-secondary);
        background: var(--bg);
        transition: background 0.15s, color 0.15s;
        display: inline-flex; align-items: center; justify-content: center;
        gap: 8px;
    }
    .vs-tab.active {
        background: var(--primary);
        color: white;
        box-shadow: var(--shadow-sm);
    }
    .vs-count {
        font-size: 0.72rem; font-weight: 700;
        background: rgba(255,255,255,0.25);
        padding: 2px 8px;
        border-radius: 999px;
        min-width: 24px;
    }
    .vs-tab:not(.active) .vs-count {
        background: var(--divider);
        color: var(--text-secondary);
    }
}

/* ── Modals ───────────────────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    width: min(440px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 14px;
}
.modal-card h2 {
    font-size: 1.05rem;
    font-weight: 600;
}
.modal-actions {
    display: flex; justify-content: flex-end; gap: 8px;
    margin-top: 4px;
}

@media (max-width: 540px) {
    .modal { align-items: flex-end; padding: 0; }
    .modal-card {
        width: 100%;
        max-height: 92vh;
        border-radius: var(--radius) var(--radius) 0 0;
    }
}

/* ── Tabs (inside shop modal) ─────────────────────────────────────────── */
.tabs {
    display: flex; gap: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
}
.tab {
    flex: 1;
    padding: 8px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ── Saved-list selector ──────────────────────────────────────────────── */
.saved-list {
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    overflow: hidden;
    max-height: 280px;
    overflow-y: auto;
}
.saved-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--divider);
    cursor: pointer;
    transition: background 0.15s;
}
.saved-item:last-child { border-bottom: none; }
.saved-item:hover  { background: var(--primary-light); }
.saved-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); padding-left: 9px; }
.sl-name { flex: 1; font-weight: 500; }
.sl-date { font-size: 0.8rem; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    left: 50%; bottom: 24px;
    transform: translateX(-50%);
    background: rgba(28,28,30,0.92);
    color: white;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-width: calc(100vw - 32px);
    text-align: center;
}
