* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.modal-content::-webkit-scrollbar {
    display: none;
}

:root {
    --primary: #ff6b35;
    --primary-dark: #e55a2b;
    --primary-light: #ff8c5a;
    --bg: #fff8f0;
    --card: #ffffff;
    --text: #2d2d2d;
    --text-light: #888;
    --border: #eee;
    --danger: #e74c3c;
    --success: #27ae60;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 500px;
    margin: 0 auto;
    padding-bottom: 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 18px 20px 14px;
    text-align: left;
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--card);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Pages */
.page {
    padding: 16px;
}

.page.hidden {
    display: none;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.97);
}

.btn-success {
    background: #2ecc71;
    color: white;
}

.btn-success:active {
    background: #27ae60;
    transform: scale(0.97);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger-outline {
    background: none;
    color: var(--danger);
    border: 2px solid var(--danger);
}

.btn-danger-outline:active {
    background: var(--danger);
    color: white;
}

.btn-full {
    width: 100%;
    margin-bottom: 16px;
}

.btn-small {
    padding: 6px 14px;
    font-size: 1.1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--card);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Week navigation */
.week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

#week-label {
    font-weight: 600;
    font-size: 1rem;
}

.planning-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.planning-actions .btn {
    flex: 1;
    font-size: 0.85rem;
    padding: 10px 8px;
}

/* Planning grid */
.planning-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.planning-grid .day-card:last-child {
    grid-column: 2;
}

.day-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.day-header {
    background: var(--primary);
    color: white;
    padding: 6px 0;
    font-weight: 700;
    font-size: 0.8rem;
    text-align: center;
}

.day-header.today {
    background: var(--primary-dark);
}

.meal-slot {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    gap: 6px;
    min-height: 38px;
    cursor: pointer;
}

.meal-slot:last-child {
    border-bottom: none;
}

.meal-slot.disabled {
    opacity: 0.3;
    cursor: default;
}

.meal-label {
    font-size: 0.7rem;
    color: var(--text-light);
    font-weight: 600;
    width: 28px;
    flex-shrink: 0;
}

.meal-name {
    flex: 1;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.meal-name.empty {
    color: var(--text-light);
    font-style: italic;
}

.meal-slot .btn-change {
    display: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s;
    padding: 0;
    margin: 0;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card);
    border-radius: 20px 20px 0 0;
    padding: 24px 16px 30px;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
    animation: slideUp 0.3s;
}

.modal-content h2 {
    margin-bottom: 4px;
    font-size: 1.2rem;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.recipe-category-select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: white;
    color: var(--text);
    appearance: auto;
}

.category-limits-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 14px 0;
}

.category-limit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #fff5f0;
    border-radius: var(--radius);
}

.category-limit-row span {
    font-size: 0.85rem;
    font-weight: 600;
}

.category-limit-row select {
    padding: 4px 8px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: white;
}

.exclude-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding: 10px 12px;
    background: #fff5f0;
    border-radius: var(--radius);
}

.exclude-toggle label {
    margin: 0 !important;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.exclude-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--danger);
    cursor: pointer;
}

.group-switcher {
    margin-top: 14px;
}

.group-switcher label {
    font-size: 0.85rem;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.group-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.group-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 2px solid transparent;
}

.group-list-item.active {
    border-color: var(--primary);
    background: #fff5f0;
}

.group-list-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.85rem;
}

.group-list-code {
    font-size: 0.7rem;
    color: var(--text-light);
    font-family: monospace;
}

.group-list-badge {
    font-size: 0.65rem;
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.group-join-inline {
    margin-top: 14px;
}

.group-join-inline label {
    font-size: 0.85rem;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.group-name-edit {
    margin-bottom: 14px;
}

.group-name-edit label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

.group-name-row {
    display: flex;
    gap: 8px;
}

.group-name-row input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    outline: none;
}

.group-name-row input:focus {
    border-color: var(--primary);
}

.source-link {
    margin-bottom: 8px;
}

.source-link a {
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.source-link a:active {
    text-decoration: underline;
}

.modal-actions-top {
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.modal-actions .btn {
    flex: 1;
}

.modal-top {
    align-items: flex-start;
}

.modal-content-top {
    border-radius: 0 0 20px 20px;
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Slots grid (cocher repas) */
.slots-grid {
    margin-top: 12px;
}

.slots-grid table {
    width: 100%;
    border-collapse: collapse;
}

.slots-grid th,
.slots-grid td {
    padding: 10px 4px;
    text-align: center;
    font-size: 0.85rem;
}

.slots-grid th {
    color: var(--text-light);
    font-weight: 600;
}

.slots-grid td:first-child {
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
}

.slot-checkbox {
    width: 28px;
    height: 28px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Recipes */
.recipes-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.recipe-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0;
    cursor: pointer;
    transition: transform 0.1s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    aspect-ratio: 1;
}

.recipe-card:active {
    transform: scale(0.97);
}

.recipe-card h3 {
    font-size: 0.75rem;
    margin: 0;
    padding: 6px 6px 2px;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.recipe-card .recipe-ingredients {
    font-size: 0.6rem;
    color: var(--text-light);
    line-height: 1.2;
    padding: 0 6px 4px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.recipe-card .recipe-instructions-preview {
    display: none;
}

.recipe-card .recipe-tags {
    display: flex;
    gap: 3px;
    padding: 0 6px 4px;
    flex-wrap: wrap;
}

.recipe-tag {
    font-size: 0.55rem;
    padding: 1px 5px;
    background: #fff0e6;
    color: var(--primary);
    border-radius: 20px;
    font-weight: 600;
}

.recipe-top-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

/* Recipe image */
.recipe-image-section {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
    margin-top: 10px;
}

.recipe-image-preview {
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.recipe-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-placeholder {
    color: var(--text-light);
    font-size: 0.75rem;
}

.recipe-image-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-small-text {
    padding: 6px 12px;
    font-size: 0.8rem;
    text-align: center;
    cursor: pointer;
}

/* Recipe card image */
.recipe-card-img {
    width: 100%;
    flex: 1;
    min-height: 0;
    object-fit: cover;
    display: block;
}

.recipe-card-noimg {
    flex: 1;
    min-height: 0;
    background: linear-gradient(135deg, #ffe0cc, #ffd4b8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Selection mode */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    margin-bottom: 10px;
}

.selection-bar span {
    font-size: 0.85rem;
    font-weight: 600;
}

.selection-actions {
    display: flex;
    gap: 6px;
}

.recipe-card.selected {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

.select-check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    z-index: 1;
}

.recipe-card {
    position: relative;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.recipe-card img {
    pointer-events: none;
}

/* Image search panel */
.image-search-panel {
    margin-top: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--bg);
}

.image-search-panel.hidden {
    display: none;
}

.image-search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
}

.image-search-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.image-search-grid img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: border-color 0.2s, transform 0.1s;
}

.image-search-grid img:active {
    transform: scale(0.95);
}

.image-search-grid img.selected {
    border-color: var(--primary);
}

/* Recipe form */
.modal-content label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-top: 14px;
    margin-bottom: 6px;
}

.modal-content input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.modal-content input[type="text"]:focus,
.modal-content textarea:focus {
    border-color: var(--primary);
}

.modal-content textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    resize: vertical;
    line-height: 1.5;
}

.ingredients-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 20px;
}

.ingredient-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f0f0f0;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
}

.ingredient-chip .remove-ingredient {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 2px;
    line-height: 1;
}

.ingredient-add {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ingredient-add input {
    flex: 1;
}

.qty-input {
    flex: 0 0 60px !important;
    text-align: center;
}

.tags-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag-btn {
    padding: 6px 14px;
    border: 2px solid var(--border);
    border-radius: 20px;
    background: none;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tag-btn.selected {
    border-color: var(--primary);
    background: #fff0e6;
    color: var(--primary);
}

/* Shopping add */
.shopping-add {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.shopping-add input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    outline: none;
}

.shopping-add input:focus {
    border-color: var(--primary);
}

/* Shopping list */
.shopping-list h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--primary);
}

.shopping-done-title {
    margin-top: 16px;
    color: var(--text-light) !important;
}

.shopping-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.shopping-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.75rem;
    line-height: 1.2;
    min-height: 58px;
}

.shopping-chip input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.shopping-chip span {
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.shopping-chip.done {
    opacity: 0.5;
}

.shopping-chip.done span {
    text-decoration: line-through;
}

.shopping-grid-done {
    opacity: 0.7;
}

.shopping-item-name {
    cursor: pointer;
}

.btn-delete-item {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state p:first-child {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.hint {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* Recipe picker modal */
.recipe-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 12px;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: none;
}

.recipe-picker-grid::-webkit-scrollbar {
    display: none;
}

.recipe-pick-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    min-height: 48px;
}

.recipe-pick-card:active {
    background: #ffe0cc;
}

.recipe-pick-card img {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.recipe-pick-card .recipe-card-noimg {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.recipe-pick-card span {
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.recipe-pick-remove {
    justify-content: center;
    color: var(--danger);
    font-style: italic;
}

.recipe-pick-remove span {
    font-size: 0.8rem;
}

/* Group screen */
.group-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.group-screen.hidden {
    display: none;
}

.group-box {
    background: var(--card);
    border-radius: 20px;
    padding: 40px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
}

.group-box h1 {
    font-size: 1.8rem;
    color: var(--primary);
    margin-bottom: 4px;
}

.group-subtitle {
    color: var(--text-light);
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.group-separator {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: var(--text-light);
}

.group-separator::before,
.group-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.group-separator span {
    padding: 0 12px;
    font-size: 0.85rem;
}

.group-box label {
    display: block;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.group-join {
    display: flex;
    gap: 8px;
}

.group-join input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 3px;
    text-align: center;
    outline: none;
    text-transform: uppercase;
}

.group-join input:focus {
    border-color: var(--primary);
}

.group-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 12px;
}

.group-error.hidden {
    display: none;
}

/* Header with group button */
.header {
    position: relative;
}

.header-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

/* Group info modal */
.group-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    padding: 14px;
    background: var(--bg);
    border-radius: var(--radius);
}

.group-code-display strong {
    font-size: 1.4rem;
    letter-spacing: 3px;
    color: var(--primary);
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Responsive */
@media (min-width: 500px) {
    #app {
        margin-top: 20px;
        border-radius: 20px;
        overflow: hidden;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    }
}
