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

:root {
    --bg-main: #f5f5f5;
    --surface-main: #ffffff;
    --surface-soft: #f8f9fa;
    --text-main: #2a2a2a;
    --text-soft: #666666;
    --border-main: #e0e0e0;
    --table-header-bg: #2f3648;
    --table-header-text: #f3f6ff;
    --table-grid: #cfd6e6;
    --slot-bg: #eef2f8;
    --slot-hover: #e3e9f4;
    --comment-bg: rgba(41, 56, 86, 0.08);
    --daily-card-bg-start: #edf1f7;
    --daily-card-bg-end: #e7edf6;
    --daily-card-hover-start: #e5ecf9;
    --daily-card-hover-end: #dde7f7;
    --control-active-bg: #3f4f6f;
    --control-active-hover: #364764;
    --control-active-border: #4c5f84;
    --control-active-text: #eef4ff;
}

body {
    font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    padding: 0;
    transition: background 0.3s ease, color 0.3s ease;
    user-select: none;
    cursor: default;
}

input, textarea, select {
    user-select: text;
    cursor: text;
}


body.theme-dark {
    --bg-main: #12151d;
    --surface-main: #1a1f2a;
    --surface-soft: #232a37;
    --text-main: #e8edf7;
    --text-soft: #adb8c8;
    --border-main: #364154;
    --table-header-bg: #253044;
    --table-header-text: #dce6f8;
    --table-grid: #2f3a4d;
    --slot-bg: #1e2633;
    --slot-hover: #273246;
    --comment-bg: rgba(161, 176, 201, 0.12);
    --daily-card-bg-start: #202a3a;
    --daily-card-bg-end: #263244;
    --daily-card-hover-start: #273548;
    --daily-card-hover-end: #2d3d52;
    --control-active-bg: #314260;
    --control-active-hover: #385072;
    --control-active-border: #496187;
    --control-active-text: #e2ecff;
}

.theme-toggle-btn {
    border: 1px solid var(--border-main);
    background: var(--surface-soft);
    color: var(--text-main);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.82em;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle-btn.active {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

.theme-toggle-btn:hover {
    transform: translateY(-1px);
}


.sync-status {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border-main);
    flex-shrink: 0;
    cursor: help;
    transition: background 0.5s ease;
    margin-left: 4px;
}

.sync-status.status-firebase { background: #86efac; }
.sync-status.status-cache    { background: #fcd34d; }
.sync-status.status-offline  { background: #fca5a5; }
.sync-status.status-syncing  {
    background: var(--border-main);
    animation: syncPulse 1.2s ease-in-out infinite;
}

@keyframes syncPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

body .sidebar h2,
body .category-title,
body .day-header,
body .modal-category-title,
body .view-controls-label,
body td,
body .meal-text,
body .confirm-message {
    color: var(--text-main);
}

body .modal-header {
    color: #ffffff;
}

body .table-container,
body .calendar-navigation,
body .view-controls,
body .single-week-view,
body .food-modal-content,
body .modal-category-title,
body .modal-food-item,
body .meal-slot,
body .meal-content,
body .day-header {
    background: var(--surface-main);
    border-color: var(--border-main);
}

body .modal-food-item,
body .category-header,
body .meal-content,
body .day-header {
    background: var(--surface-soft);
}

body .meal-slot .meal-content {
    background: transparent;
    border-color: transparent;
}

body.theme-dark .modal-header {
    background: #2a3342;
    color: #e8edf7;
}


.calendar-action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    border-left: 1px solid var(--border-main);
    padding-left: 14px;
    margin-left: 4px;
}

/* Acción principal: Aleatorio */
.random-btn {
    padding: 8px 16px;
    background: #16a34a;
    color: #ffffff;
    border: 1px solid #15803d;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s;
    white-space: nowrap;
}

.random-btn:hover:not(:disabled) {
    background: #15803d;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35);
}

.random-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Acciones secundarias: PDF y Copia — outline neutro */
.pdf-btn {
    padding: 8px 14px;
    background: transparent;
    color: var(--text-soft);
    border: 1px solid var(--border-main);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.copy-btn {
    padding: 8px 14px;
    background: transparent;
    color: var(--text-soft);
    border: 1px solid var(--border-main);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    display: none;
}

.copy-btn:hover,
.pdf-btn:hover {
    color: var(--text-main);
    border-color: var(--text-soft);
    transform: translateY(-1px);
}

/* Reiniciar — outline rojo discreto, se activa al hover */
.reset-btn {
    padding: 8px 14px;
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

/* ===== OVERLAY GENERACIÓN MENÚ ===== */
.generation-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.generation-overlay.hidden {
    display: none;
}

.generation-box {
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 14px;
    padding: 28px 36px;
    min-width: 280px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.generation-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 18px;
}

.generation-bar-track {
    height: 8px;
    background: var(--surface-soft);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 10px;
}

.generation-bar-fill {
    height: 100%;
    width: 0%;
    background: #16a34a;
    border-radius: 99px;
    transition: width 0.25s ease;
}

.generation-label {
    font-size: 0.82em;
    color: var(--text-soft);
    min-height: 1.2em;
}

/* ===== COMBO RATING FLOAT ===== */
.combo-float {
    position: absolute;
    top: -11px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    gap: 1px;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 20px;
    padding: 1px 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.12);
    pointer-events: auto;
}

.combo-float-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.72em;
    padding: 1px 3px;
    border-radius: 10px;
    line-height: 1.5;
    transition: transform 0.12s;
    color: var(--text-soft);
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 2px;
}

.combo-float-btn:hover {
    transform: scale(1.25);
}

.combo-score {
    font-size: 0.75em;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
    line-height: 1;
    padding: 0 1px;
}

.combo-score.score-pos { color: #16a34a; }
.combo-score.score-neg { color: #ef4444; }

/* Modal de motivos */
.rating-reason-content {
    max-width: 360px;
    width: 90%;
}

.rating-combo-desc {
    font-size: 0.88em;
    color: var(--text-soft);
    margin: 0 0 12px;
    padding: 8px 10px;
    background: var(--surface-soft);
    border-radius: 6px;
    border-left: 3px solid #ef4444;
}

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

.reason-btn {
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border-main);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-size: 0.88em;
    color: var(--text-main);
    font-family: inherit;
    transition: all 0.15s;
}

.reason-btn:hover {
    background: var(--surface-soft);
    border-color: #ef4444;
    color: #ef4444;
}

.reset-btn:hover {
    background: #ef4444;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 15px 15px;
}

.sidebar {
    display: none; /* Ocultado: gestionado en otra página */
}

.sidebar h2 {
    color: #333;
    margin-bottom: 18px;
    font-size: 1.2em;
    font-weight: 600;
    border-bottom: 2px solid #333;
    padding-bottom: 8px;
}

.food-category {
    margin-bottom: 20px;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 10px;
    transition: all 0.3s;
    user-select: none;
}

.category-header:hover {
    background: #e9ecef;
}

.category-title {
    font-weight: 600;
    color: #555;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

@media (max-width: 768px) {
    .reset-btn {
        display: none !important;
    }
}

.category-arrow {
    font-size: 0.8em;
    color: #666;
    transition: transform 0.3s;
}

.category-header.collapsed .category-arrow {
    transform: rotate(-90deg);
}

.category-items {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.category-items.collapsed {
    max-height: 0;
    opacity: 0;
}

.food-item {
    background: #333;
    color: white;
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.food-item-text {
    flex: 1;
}

.delete-food-btn {
    background: #ff4444;
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    opacity: 1;
}

.food-item:hover .delete-food-btn {
    opacity: 1;
}

.delete-food-btn:hover {
    background: #cc0000;
    transform: scale(1.1);
}

.food-item:hover {
    transform: translateY(-2px);
    background: #000;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.food-item:active {
    cursor: grabbing;
}

.table-container {
    flex: 1;
    background: var(--surface-main);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-main);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    padding: 12px 8px;
    text-align: center;
    font-size: 0.95em;
    font-weight: 600;
    border: 2px solid var(--table-grid);
    min-width: 100px;
}

th:first-child {
    background: var(--surface-soft);
    color: var(--text-main);
    min-width: 120px;
}

#weekTable thead th:not(:first-child):not(.day-disabled):not(.current-day) {
    background: var(--table-header-bg);
    color: var(--table-header-text);
}

td {
    padding: 0;
    border: 2px solid var(--table-grid);
    min-width: 100px;
    width: 100px;
    max-width: 100px;
}

.day-header {
    background: var(--surface-soft);
    font-weight: bold;
    color: var(--text-main);
    padding: 12px 8px;
    text-align: center;
    min-width: 90px;
    width: 90px;
    max-width: 90px;
    white-space: nowrap;
    font-size: 1.05em;
}

/* Columna tipo de plato más estrecha en vista diaria */
body.daily-view .day-header {
    min-width: 0;
    width: 15%;
    max-width: none;
    padding: 8px 3px;
    font-size: 1.4em;
    line-height: 1.1;
}

/* En vista diaria: primera columna fija y columna de platos expandida */
body.daily-view #weekTable {
    table-layout: fixed;
}

body.daily-view #weekTable th:first-child,
body.daily-view #weekTable .day-header {
    width: 15% !important;
    min-width: 15% !important;
    max-width: 15% !important;
}

body.daily-view #weekTable th:first-child {
    padding: 8px 3px;
    border-left: 2px solid var(--table-grid);
    border-top: 2px solid var(--table-grid);
    background: var(--surface-soft);
}

body.daily-view #weekTable th:not(:first-child):not(.hide-column),
body.daily-view #weekTable td:not(.day-header):not(.hide-column) {
    width: 85% !important;
}

/* Ocultar texto en vista diaria, solo mostrar emoji */
body.daily-view .day-header .text {
    display: none;
}

body.daily-view .day-header .emoji {
    display: inline-block;
    font-size: 1.4em;
}

.meal-slot {
    min-height: 75px;
    padding: 8px 4px;
    background: var(--slot-bg);
    transition: all 0.3s;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.meal-slot:empty::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 0.85em;
    pointer-events: none;
    opacity: 0.6;
}

.meal-slot:hover {
    background: var(--slot-hover);
}

.meal-slot:hover:empty::before {
    opacity: 1;
    color: var(--text-main);
}

.meal-slot.drag-over {
    background: var(--slot-hover);
    border: 2px dashed var(--table-grid) !important;
}

.meal-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    color: var(--text-main);
    padding: 0;
    margin: 0;
    border-radius: 0;
    font-size: 0.85em;
    max-width: 100%;
    width: 100%;
    cursor: pointer;
    transition: color 0.2s;
    flex-direction: column;
    text-align: center;
    position: static;
}

.meal-content:hover {
    color: var(--text-main);
}

.meal-content:hover .remove-btn {
    opacity: 1;
}

.meal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    align-items: center;
    justify-content: center;
    padding: 2px;
}

.meal-text {
    font-weight: 600;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 0.9em;
    line-height: 1.2;
    text-align: center;
    text-align-last: center;
    text-wrap: balance;
    width: 100%;
    hyphens: auto;
}

.meal-description {
    font-size: 0.75em;
    color: #666;
    line-height: 1.2;
    word-wrap: break-word;
    display: none;
}

.remove-btn {
    background: transparent;
    color: #999;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 1.15em;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    padding: 0;
    position: absolute;
    top: 1px;
    right: 1px;
    opacity: 0.5;
}

.remove-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
    transform: scale(1.2);
    opacity: 1;
}

.remove-btn.tab-close {
    display: flex;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--surface-main) 86%, #8fa2c9 14%);
    border: 1px solid var(--border-main);
    color: #43507a;
    font-weight: 700;
    top: 4px;
    right: 4px;
    opacity: 1;
    z-index: 3;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(15, 22, 38, 0.2);
}

.remove-btn.tab-close:hover {
    background: color-mix(in srgb, var(--surface-main) 72%, #768fbe 28%);
    color: #2d3b63;
    transform: scale(1.06);
}

body.theme-dark .remove-btn.tab-close {
    background: color-mix(in srgb, var(--surface-main) 78%, #6f84af 22%);
    color: #d8e4ff;
    border-color: #4e6286;
}

/* Estilos para el link de receta */
.meal-description-link {
    color: #fff !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    text-decoration: none !important;
    font-size: 0.75em;
    padding: 5px 12px;
    border-radius: 16px;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.3);
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.meal-description-link:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    text-decoration: none !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.4);
}

/* Estilos para comentarios del plato */
.meal-comments {
    font-size: 0.85em;
    color: var(--text-soft);
    line-height: 1.4;
    margin: 2px 0;
    padding: 0;
    background: transparent;
    border-radius: 6px;
    font-style: italic;
}

/* Estilos mejorados para meal-content en vista diaria */
body.daily-view .meal-content {
    background: transparent;
    border-left: none;
    padding: 8px 10px !important;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    transition: all 0.3s ease;
    display: grid;
    grid-template-columns: 2fr 3fr 1fr;
    align-items: center;
    column-gap: 10px;
    position: static;
}

body.daily-view .meal-content:hover {
    background: transparent;
    box-shadow: none;
    transform: none;
}

body.daily-view .meal-text {
    color: var(--text-main);
    font-weight: 600;
    font-size: 1.05em;
}

body.daily-view .daily-name-block {
    text-align: center;
    min-width: 0;
}

body.daily-view .daily-name-text {
    display: block;
    text-align: center;
    text-align-last: center;
    text-wrap: balance;
}

.meal-slot.slot-disabled {
    background: color-mix(in srgb, var(--surface-soft) 70%, var(--bg-main) 30%) !important;
    opacity: 0.75;
    cursor: not-allowed;
}

.meal-slot.slot-disabled .meal-content {
    opacity: 0.85;
}

.meal-slot.slot-disabled .remove-btn,
.meal-slot.slot-disabled .remove-btn.tab-close {
    opacity: 0.35 !important;
    pointer-events: none;
}

body.theme-dark .meal-slot.slot-disabled {
    background: color-mix(in srgb, var(--surface-soft) 78%, #0f131a 22%) !important;
}

body.daily-view .daily-comments-block {
    text-align: center;
    min-width: 0;
}

body.daily-view .daily-comments-text {
    display: block;
    margin: 0;
    text-align: justify;
    text-align-last: center;
    text-wrap: balance;
}

@media (max-width: 768px) {
    body.daily-view .meal-text {
        font-size: 1.12em;
    }

    body.daily-view .daily-comments-text {
        font-size: 0.95em;
    }

    body.daily-view .day-header {
        font-size: 1.5em;
    }
}

body.daily-view .daily-recipe-block {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 18px;
}

body.daily-view .daily-recipe-link {
    min-width: 32px;
    text-align: center;
    padding: 5px 8px;
    margin-right: 4px;
}

body.daily-view .daily-recipe-placeholder {
    color: var(--text-soft);
    font-weight: 600;
}

@media (max-width: 360px) {
    body.daily-view #weekTable th:first-child,
    body.daily-view #weekTable .day-header {
        width: 18% !important;
        min-width: 18% !important;
        max-width: 18% !important;
    }

    body.daily-view #weekTable th:not(:first-child):not(.hide-column),
    body.daily-view #weekTable td:not(.day-header):not(.hide-column) {
        width: 82% !important;
    }

    body.daily-view .meal-content {
        grid-template-columns: 1.6fr 2.2fr 0.7fr;
        column-gap: 6px;
        padding: 6px 6px !important;
    }

    body.daily-view .meal-text {
        font-size: 1.02em;
    }

    body.daily-view .daily-comments-text {
        font-size: 0.88em;
    }

    body.daily-view .daily-recipe-block {
        padding-right: 6px;
    }

    body.daily-view .daily-recipe-link {
        min-width: 26px;
        padding: 4px 6px;
    }

    body.daily-view .remove-btn.tab-close {
        width: 24px;
        height: 24px;
    }
}

/* Ajustar botón de eliminar en vista diaria */
body.daily-view .remove-btn {
    position: relative;
    top: auto;
    right: auto;
    margin-left: 8px;
    opacity: 0.6;
}

body.daily-view .remove-btn:hover {
    opacity: 1;
}

body.daily-view .remove-btn.tab-close {
    position: absolute;
    top: 3px;
    right: 3px;
    margin-left: 0;
    z-index: 20;
}

th.day-disabled {
    opacity: 0.65;
    filter: saturate(0.75);
    background: var(--surface-soft) !important;
    color: var(--text-soft) !important;
}

th.current-day {
    background: #4CAF50 !important;
    color: #ffffff !important;
    opacity: 1;
    filter: none;
}


body.daily-view .meal-content .meal-text {
    margin-left: 0;
}


/* Ajustes para desktop */
@media (min-width: 769px) {
    .food-modal-content {
        margin: 8% auto;
        max-width: 500px;
        max-height: 75vh;
    }
    
    .modal-food-item {
        font-size: 1em;
        padding: 14px;
    }
}

@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
    }

    .table-container {
        padding: 15px;
    }

    table {
        font-size: 0.85em;
    }

    th, td {
        min-width: 90px;
        padding: 10px 6px;
    }

    th:first-child,
    .day-header {
        min-width: 90px;
        width: 90px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .main-container {
        gap: 10px;
        padding-top: 10px;
    }

    .meal-description {
        font-size: 0.8em;
    }

    /* Ocultar botón Nuevo en móvil */
    .add-calendar-btn {
        display: none !important;
    }

    .table-container {
        padding: 5px;
        border-radius: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.7em;
        min-width: auto;
        width: 100%;
    }

    th, td {
        min-width: auto;
        padding: 5px 2px;
    }

    th:first-child,
    .day-header {
        min-width: 60px;
        font-size: 0.9em;
        padding: 5px 2px;
    }

    .meal-slot {
        min-height: 50px;
        padding: 6px 3px;
        gap: 2px;
    }

    .meal-slot:empty::before {
        font-size: 0.7em;
    }

    .meal-content {
        padding: 0;
        font-size: 0.75em;
        width: 100%;
    }

    .meal-text {
        font-size: 0.85em;
        line-height: 1.1;
    }

    .remove-btn {
        width: 18px;
        height: 18px;
        font-size: 1em;
        display: flex;
    }

    .remove-btn {
        width: 20px;
        height: 20px;
        font-size: 1.1em;
        display: flex;
    }

    .scroll-hint {
        display: none;
    }

    .view-controls {
        flex-wrap: wrap;
        padding: 6px;
        gap: 5px;
        margin-bottom: 8px;
    }

    .view-controls-label {
        width: 100%;
        text-align: center;
        margin-bottom: 4px;
        font-size: 0.85em;
    }

    .view-btn {
        flex: 1;
        min-width: 100px;
        font-size: 0.85em;
        padding: 10px;
    }

    .calendar-navigation {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 8px 10px;
        margin-bottom: 8px;
    }

    .calendar-action-buttons {
        display: none !important;
    }

    .calendar-nav-left {
        display: flex;
    }
}

@media (max-width: 600px) {
    .calendar-indicators {
        display: none !important;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }

    /* En pantallas muy pequeñas ocultar botones secundarios */
    .random-btn,
    .pdf-btn {
        display: none;
    }

    .table-container {
        padding: 3px;
    }

    table {
        font-size: 0.65em;
        min-width: auto;
        width: 100%;
    }

    th, td {
        min-width: auto;
        padding: 4px 1px;
    }

    .day-header {
        font-size: 0.85em;
        padding: 4px 1px;
        min-width: 50px;
    }

    .meal-slot {
        min-height: 45px;
        padding: 5px 2px;
    }

    .meal-slot:empty::before {
        font-size: 0.65em;
    }

    .meal-content {
        padding: 0;
        font-size: 0.68em;
        width: 100%;
    }

    .meal-text {
        font-size: 0.9em;
        line-height: 1.1;
    }

    .remove-btn {
        width: 18px;
        height: 18px;
        font-size: 1em;
        top: 1px;
        right: 1px;
        display: flex;
    }

    .view-controls {
        padding: 5px;
        gap: 4px;
    }

    .view-btn {
        padding: 8px;
        font-size: 0.8em;
    }

    .calendar-navigation {
        padding: 6px;
        gap: 6px;
    }

    .calendar-indicator {
        width: 30px;
        height: 30px;
        font-size: 0.85em;
    }

    .reset-btn {
        padding: 8px 12px;
        font-size: 0.8em;
    }
}

.scroll-hint {
    text-align: center;
    color: #999;
    font-size: 0.85em;
    margin-top: 10px;
}

/* Navegación de calendarios */
.calendar-navigation {
    display: grid;
    grid-template-columns: auto auto auto;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    padding: 15px;
    background: var(--surface-main);
    border-radius: 8px;
    border: 1px solid var(--border-main);
}

/* Controles de vista */
.view-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 15px;
    padding: 12px;
    background: var(--surface-main);
    border-radius: 8px;
    border: 1px solid var(--border-main);
    justify-content: center;
}

.view-controls-label {
    font-weight: 600;
    color: var(--text-soft);
    font-size: 0.9em;
    margin-right: 8px;
}

.view-btn {
    padding: 8px 16px;
    background: var(--surface-soft);
    color: var(--text-soft);
    border: 1px solid var(--border-main);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.3s;
}

.view-btn:hover {
    border-color: var(--table-grid);
    color: var(--text-main);
}

.view-btn.active {
    background: transparent;
    color: #4a90d9;
    border-color: #4a90d9;
    font-weight: 700;
}

/* Ocultar columnas en modo día/3días */
.hide-column {
    display: none;
}

/* Vista de 4 semanas */
.four-week-view {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.four-week-view.active {
    display: grid;
}

.week-calendar {
    background: var(--surface-main);
    border-radius: 8px;
    padding: 15px;
    border: 2px solid var(--border-main);
}

.week-calendar-header {
    text-align: center;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--table-grid);
    font-size: 1.05em;
}

.week-calendar table {
    font-size: 0.75em;
}

.week-calendar th,
.week-calendar td {
    min-width: 60px;
    padding: 6px 3px;
}

.week-calendar .meal-slot {
    min-height: 50px;
    padding: 5px;
    font-size: 0.7em;
}

.week-calendar .day-header {
    font-size: 0.75em;
    min-width: 70px;
}

.single-week-view {
    display: block;
}

.single-week-view.hide {
    display: none;
}

.calendar-nav-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-arrow {
    background: var(--control-active-bg);
    color: var(--control-active-text);
    border: 1px solid var(--control-active-border);
    border-radius: 6px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    font-weight: bold;
}

.nav-arrow:hover {
    background: var(--control-active-hover);
    transform: scale(1.05);
}

.nav-arrow:disabled {
    background: var(--surface-soft);
    border-color: var(--border-main);
    color: var(--text-soft);
    cursor: not-allowed;
    opacity: 0.5;
}

.calendar-indicators {
    display: flex;
    gap: 10px;
    align-items: center;
}

.calendar-indicator {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--surface-soft);
    border: 2px solid var(--border-main);
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    color: var(--text-soft);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-indicator:hover {
    border-color: var(--table-grid);
    color: var(--text-main);
}

.calendar-indicator.active {
    background: transparent;
    color: #4a90d9;
    border-color: #4a90d9;
    font-weight: 700;
}

.add-calendar-btn {
    padding: 10px 20px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s;
    white-space: nowrap;
}

.add-calendar-btn:hover {
    background: #45a049;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.3);
}

.current-calendar-label {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text-main);
    min-width: 200px;
    text-align: center;
}

/* Modal para selección en móvil */
.food-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s;
}

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

.food-modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 0;
    border-radius: 12px;
    width: min(96vw, 533px);
    max-width: 533px;
    max-height: 70vh;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.confirm-modal-content {
    max-width: 460px;
}

.food-modal-content .modal-tab-close {
    position: static;
    width: 30px;
    height: 30px;
    border: 1px solid #c21d16;
    border-radius: 50%;
    background: #ff3b30 !important;
    color: #ffffff !important;
    font-size: 1.05em;
    font-weight: 700;
    line-height: 1;
    font-family: Arial, Helvetica, sans-serif;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
    display: inline-grid;
    place-items: center;
    text-align: center;
    padding: 0;
    margin-left: 12px;
}

.food-modal-content .modal-tab-close:hover {
    background: #d7261d;
    transform: scale(1.06);
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    background: #333;
    color: white;
    padding: 16px 18px;
    border-radius: 12px 12px 0 0;
    font-size: 1.1em;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 20;
}

#foodModal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-body {
    padding: 10px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    flex: 1;
}

.modal-fixed-zone {
    padding-top: 6px;
    background: var(--surface-main);
    z-index: 26;
}

#modalFoods {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-top: 4px;
    padding-right: 4px;
}

.modal-search {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-main);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--text-main);
    font-size: 0.88em;
    margin-bottom: 8px;
    position: relative;
    z-index: 24;
}

.modal-fixed-category-title {
    font-weight: 700;
    color: var(--text-main);
    padding: 10px 12px;
    border: 1px solid var(--border-main);
    border-radius: 8px;
    font-size: 0.83em;
    text-transform: uppercase;
    letter-spacing: 0.45px;
    background: var(--surface-soft);
    margin-bottom: 2px;
}

.modal-fixed-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-fixed-row .modal-fixed-category-title {
    flex: 1;
    margin-bottom: 0;
}

.modal-clear-slot-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #ff5c53;
    font-size: 1.2em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: none;
    transition: all 0.2s ease;
}

.modal-clear-slot-btn:hover:not(:disabled) {
    color: #e34a41;
    transform: scale(1.06);
}

.modal-clear-slot-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

.modal-search:focus {
    outline: none;
    border-color: var(--control-active-border);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--control-active-bg) 22%, transparent);
}

.modal-category {
    margin-bottom: 20px;
    padding: 10px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface-main) 82%, var(--surface-soft) 18%);
    border: 1px solid var(--border-main);
}

.modal-category.collapsed .modal-food-item {
    display: none;
}

.modal-category-title {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-main);
    border-radius: 8px;
    font-size: 0.82em;
    text-transform: uppercase;
    position: relative;
    top: auto;
    background: var(--surface-soft);
    z-index: 10;
}

@media (max-width: 768px) {
    .food-modal-content {
        width: 96vw;
        max-width: 96vw;
    }

    .modal-body {
        padding: 8px 10px 10px;
    }

    .modal-fixed-category-title {
        font-size: 0.78em;
        padding: 9px 10px;
    }

    .modal-clear-slot-btn {
        width: 30px;
        height: 30px;
        font-size: 1.1em;
    }
}

.modal-category-title .category-arrow {
    transition: transform 0.3s;
    font-size: 0.8em;
}

.modal-food-item {
    padding: 12px 14px;
    background: #f8f9fa;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9em;
    overflow-wrap: anywhere;
    white-space: normal;
    line-height: 1.3;
}

.modal-food-item.hidden-by-search,
.modal-category.hidden-by-search {
    display: none;
}

.modal-food-item:hover {
    background: #333;
    color: white;
    transform: translateX(5px);
}

.modal-close {
    background: #ff4444;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    width: 100%;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #cc0000;
}

.modal-close.secondary {
    background: #777;
}

.modal-close.secondary:hover {
    background: #5a5a5a;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    padding: 0 20px 20px;
}

.confirm-message {
    color: #444;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Sistema de notificaciones */
.notification {
    position: fixed;
    bottom: 20px;
    left: 20px;
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    font-size: 0.9em;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease;
    pointer-events: none;
    max-width: 300px;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.notification.success {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
}

.notification.error {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.notification.info {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
}

@media (max-width: 768px) {
    .notification {
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
        font-size: 0.85em;
        padding: 12px 16px;
    }
}

/* ====================================
   FORCE RELOAD BUTTON ANIMATION
   ==================================== */

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 6px 18px rgba(255,107,107,0.5);
    }
}

.force-reload-btn {
    animation: pulse 2s infinite;
}

.force-reload-btn:hover {
    background: linear-gradient(135deg, #f57c00 0%, #e65100 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(255,152,0,0.6) !important;
}

.force-reload-btn:active {
    transform: translateY(0) scale(0.98) !important;
}

/* ====================================
   AUTH WIDGET
   ==================================== */

.auth-widget {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 1300;
}

.auth-login-btn {
    display: block;
    background: transparent;
    color: var(--text-soft);
    border: 1px solid var(--border-main);
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    user-select: none;
}

.auth-login-btn:hover {
    background: var(--surface-soft);
    color: var(--text-main);
    border-color: var(--text-soft);
}

.auth-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-soft);
    color: var(--text-main);
    border: 1px solid var(--border-main);
    padding: 5px 10px 5px 6px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85em;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.auth-trigger:hover {
    background: var(--slot-hover, var(--surface-soft));
    border-color: var(--text-soft);
}

.auth-trigger.active {
    background: var(--surface-soft);
    color: var(--text-main);
    border-color: var(--border-main);
}

.auth-trigger.active:hover {
    border-color: var(--text-soft);
}

.auth-trigger.no-access {
    background: var(--surface-soft);
    color: var(--text-soft);
    border-color: var(--border-main);
}

.auth-trigger.no-access:hover {
    border-color: var(--text-soft);
}

.auth-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1.5px solid var(--border-main);
}

.auth-avatar-ph { font-size: 1.1em; }

.auth-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.auth-chevron {
    font-size: 0.75em;
    opacity: 0.7;
}

.auth-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    min-width: 200px;
    z-index: 1400;
    animation: authDropIn 0.15s ease;
}

.auth-dropdown.hidden { display: none; }

@keyframes authDropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    font-size: 0.88em;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--text-main);
    text-decoration: none;
    border: none;
    background: none;
    box-sizing: border-box;
}

.auth-dropdown-item:hover { background: var(--surface-soft); }

.auth-dropdown-admin { border-bottom: 1px solid var(--border-main); }

.auth-dropdown-logout { color: #dc2626; }

.auth-dropdown-logout:hover {
    background: #fee2e2;
    color: #991b1b;
}

body.theme-dark .auth-dropdown-logout:hover {
    background: #3b1111;
    color: #fca5a5;
}

@media (max-width: 768px) {
    .auth-widget { top: 60px; right: 10px; }
    .auth-name { max-width: 80px; }
}

/* ====================================
   AUTH GATE
   ==================================== */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-gate.hidden { display: none; }

.auth-gate-card {
    text-align: center;
    padding: 48px 40px;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    max-width: 320px;
    width: 90%;
}

.auth-gate-icon { font-size: 2.5em; margin-bottom: 12px; }

.auth-gate-title {
    font-size: 1.4em;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--text-main);
}

.auth-gate-msg {
    color: var(--text-soft);
    margin: 0 0 24px;
    font-size: 0.9em;
}

.auth-gate-btn {
    padding: 12px 24px;
    background: var(--control-active-bg);
    color: var(--control-active-text);
    border: 1px solid var(--control-active-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s;
}

.auth-gate-btn:hover { opacity: 0.85; transform: translateY(-1px); }

/* Slots bloqueados para no-editores */
.meal-slot.auth-locked { cursor: not-allowed !important; }
.meal-slot.auth-locked .remove-btn { pointer-events: none; }

/* Plato único: comida2 bloqueada */
.meal-slot.slot-unico-blocked {
    cursor: not-allowed !important;
    opacity: 0.6;
    pointer-events: none;
}
.meal-slot.slot-unico-blocked .remove-btn { display: none; }

/* Botones de edición en modo solo-lectura */
body.view-only .reset-btn,
body.view-only .random-btn,
body.view-only #createCopyBtn,
body.view-only #applyCopyBtn {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ====================================
   TOPBAR (barra de navegación superior)
   ==================================== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 20px;
    height: 56px;
    background: var(--surface-main);
    border-bottom: 1px solid var(--border-main);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.07);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.topbar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1em;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    pointer-events: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.topbar-nav-btn {
    background: transparent;
    color: var(--text-main);
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.topbar-nav-btn:hover {
    background: var(--surface-soft);
    transform: translateY(-1px);
}

/* Dentro del topbar: overrides de estilos flotantes */
.topbar .theme-toggle-btn {
    font-size: 0.85em;
    padding: 5px 9px;
}

.topbar .auth-widget {
    position: relative;
    top: auto;
    right: auto;
    z-index: auto;
}

@media (max-width: 768px) {
    .topbar { padding: 0 10px; gap: 6px; height: 52px; }
    .topbar-center { display: none; }
    .topbar-nav-btn { padding: 7px 10px; font-size: 0.78em; }
    .auth-name { max-width: 60px; }
}
