/* ========================================
   Menu Escolar Lleó XIII — Design System
   Colors from AFA logo: blue, green, coral
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --brand-blue: #2fa4d9;
    --brand-blue-light: #5bbde6;
    --brand-blue-dark: #1e8bbf;
    --brand-green: #8cc63f;
    --brand-green-dark: #6fa32e;
    --brand-coral: #e85b5b;
    --brand-coral-dark: #c94444;

    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-course: #f1f5f9;
    --bg-hover: #e2e8f0;
    --text-dark: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --radius-full: 9999px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #0f172a;
        --bg-card: #1e293b;
        --bg-course: #334155;
        --bg-hover: #475569;
        --text-dark: #f1f5f9;
        --text-body: #cbd5e1;
        --text-muted: #94a3b8;
        --text-light: #64748b;
        --border: #334155;
    }
}

[data-theme="dark"] {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-course: #334155;
    --bg-hover: #475569;
    --text-dark: #f1f5f9;
    --text-body: #cbd5e1;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --border: #334155;
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-course: #f1f5f9;
    --bg-hover: #e2e8f0;
    --text-dark: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-body);
    line-height: 1.5;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

/* ---- Header & Nav ---- */
.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(10px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 800;
    color: var(--text-dark);
    text-decoration: none;
    font-size: 1.1rem;
}

.brand img {
    height: 32px;
}

.actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.icon-btn {
    background: var(--bg-course);
    border: 1px solid var(--border);
    color: var(--text-body);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.icon-btn:hover {
    background: var(--bg-hover);
}

.lang-select {
    background: var(--bg-course);
    border: 1px solid var(--border);
    color: var(--text-body);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

/* ---- Main Container ---- */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.tabs {
    display: flex;
    background: var(--bg-card);
    padding: 0.25rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.tab {
    flex: 1;
    padding: 0.75rem 0.5rem;
    border: none;
    background: transparent;
    border-radius: var(--radius-full);
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9rem;
}

.tab.active {
    background: var(--brand-blue);
    color: white;
    box-shadow: 0 4px 12px rgba(47, 164, 217, 0.3);
}

/* ---- Content Cards ---- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
    animation: fadeIn 0.4s ease-out;
}

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

.card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.day-badge {
    background: var(--brand-blue);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.1;
}

.day-badge .num { font-size: 1.25rem; font-weight: 800; }
.day-badge .mon { font-size: 0.6rem; font-weight: 700; text-transform: uppercase; }

.card-title-group h2 {
    font-size: 1.25rem;
    color: var(--text-dark);
    font-weight: 700;
}

.card-title-group p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ---- Meal Courses ---- */
.courses {
    display: grid;
    gap: 1rem;
}

.course {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-course);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: transform var(--transition);
}

.course:hover {
    transform: translateX(4px);
    border-color: var(--brand-blue);
}

.course-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.course-info .label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.course-info .text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* ---- Nutrition & Allergens ---- */
.nutrition-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.nutri-item {
    text-align: center;
}

.nutri-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-dark);
}

.nutri-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.allergens {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.allergen {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border: 1px solid var(--border);
    position: relative;
    cursor: help;
}

.allergen:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-dark);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    z-index: 10;
}

/* ---- Month View (Calendar) ---- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
}

.cal-header {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 0.5rem;
}

.cal-day {
    aspect-ratio: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    padding: 4px 3px;
    overflow: hidden;
    position: relative;
}

/* Days with a label need extra height; the whole grid row stretches uniformly */
.cal-day.special,
.cal-day.holiday {
    aspect-ratio: unset;
    min-height: 4rem;
}

.cal-num {
    line-height: 1;
    flex-shrink: 0;
}

.cal-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    background: rgba(140, 198, 63, 0.18);
    color: var(--brand-green-dark);
    border-radius: 4px;
    padding: 0.2em 0.45em;
    max-width: 96%;
    white-space: normal;
    word-break: break-word;
    text-align: center;
    line-height: 1.3;
}

.cal-day.holiday .cal-label,
.cal-day.today .cal-label {
    background: rgba(255, 255, 255, 0.28);
    color: white;
}

.cal-day.special.has-menu::after,
.cal-day.holiday.has-menu::after {
    display: none;
}

.cal-day:hover {
    border-color: var(--brand-blue);
    background: var(--bg-course);
}

.cal-day.today {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}

.cal-day.has-menu::after {
    content: '';
    position: absolute;
    bottom: 4px;
    width: 4px;
    height: 4px;
    background: var(--brand-green);
    border-radius: 50%;
}

.cal-day.weekend {
    background: var(--bg-course);
    color: var(--text-light);
    pointer-events: none;
}

.cal-day.holiday {
    background: var(--brand-coral-dark);
    color: white;
    opacity: 0.7;
}

.cal-day.empty {
    opacity: 0;
    pointer-events: none;
}

/* ---- Footer ---- */
footer {
    text-align: center;
    padding: 2rem 1rem 3rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--brand-blue);
    text-decoration: none;
    font-weight: 600;
}

/* ---- Disclaimer ---- */
.disclaimer {
    margin-top: 1.5rem;
    text-align: left;
    max-width: 680px;
    margin-inline: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    overflow: hidden;
}

.disclaimer summary {
    padding: 0.65rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: background var(--transition);
}

.disclaimer summary::-webkit-details-marker { display: none; }

.disclaimer summary:hover {
    background: var(--bg-course);
    color: var(--text-dark);
}

.disclaimer[open] summary {
    border-bottom: 1px solid var(--border);
}

.disclaimer-body {
    padding: 1rem;
    display: grid;
    gap: 0.75rem;
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.disclaimer-body p { margin: 0; }
.disclaimer-body strong { color: var(--text-body); }

/* ---- Cookie / RGPD banner ---- */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
    z-index: 200;
    font-size: 0.82rem;
    color: var(--text-muted);
    animation: slideUp 0.3s ease-out;
}

.cookie-banner p { margin: 0; flex: 1; line-height: 1.5; }

.cookie-btn {
    background: var(--brand-blue);
    color: white;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-full);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background var(--transition);
}

.cookie-btn:hover { background: var(--brand-blue-dark); }

.cookie-hiding {
    animation: slideDown 0.35s ease-in forwards;
}

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

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

/* ---- Rating widget ---- */
.rating-section {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
}

.rating-q {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: center;
}

.rating-btns {
    display: flex;
    gap: 0.85rem;
}

.rate-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--bg-course);
    border: 2px solid transparent;
    padding: 0.45rem 1.25rem;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-body);
}

.rate-btn:hover:not(:disabled) { transform: scale(1.07); }

.rate-btn.up.active  {
    background: rgba(140,198,63,0.14);
    border-color: var(--brand-green);
    color: var(--brand-green-dark);
}

.rate-btn.down.active {
    background: rgba(232,91,91,0.14);
    border-color: var(--brand-coral);
    color: var(--brand-coral-dark);
}

.rate-btn:disabled { opacity: 0.65; cursor: default; }

/* ---- Share button row ---- */
.share-btn-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* ---- Share Button & Modal ---- */
.share-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: all var(--transition);
    margin: 0;
    box-shadow: var(--shadow-sm);
}

.share-btn:hover {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 { font-size: 1.25rem; color: var(--text-dark); }

.share-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.share-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-body);
    font-size: 0.75rem;
    font-weight: 600;
    transition: transform var(--transition);
}

.share-item:hover { transform: scale(1.1); }

.share-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.copy-link-box {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-course);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.copy-link-box input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-body);
    font-size: 0.85rem;
    outline: none;
}

.copy-link-box button {
    background: var(--brand-blue);
    color: white;
    border: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* ---- Menu Type Select ---- */
.type-filters-bar {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.menu-type-select {
    background: var(--bg-card);
    border: 1.5px solid var(--brand-green);
    color: var(--text-dark);
    padding: 0.6rem 2.5rem 0.6rem 1.25rem;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(140, 198, 63, 0.15);
    max-width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238cc63f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.85rem center;
}

.menu-type-select:focus {
    box-shadow: 0 0 0 3px rgba(140, 198, 63, 0.25);
}

/* ---- Special / Holiday Card ---- */
.card.holiday {
    background: linear-gradient(135deg, var(--brand-coral), var(--brand-coral-dark));
    color: white;
    border: none;
    text-align: center;
}

.card.holiday h2, .card.holiday p { color: white; }

/* ---- Stats Tab ---- */
.stats-card {
    padding: 1.5rem;
}

.stat-header {
    text-align: center;
    margin-bottom: 1.75rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.stat-header h2 {
    font-size: 1.3rem;
    color: var(--text-dark);
    margin-bottom: 0.25rem;
}

.stat-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* View toggle (Gràfic / Llista) */
.stats-toggle {
    display: inline-flex;
    background: var(--bg-course);
    border-radius: var(--radius-full);
    padding: 3px;
    gap: 2px;
}

.stg-btn {
    background: transparent;
    border: none;
    padding: 0.3rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.stg-btn.active {
    background: var(--bg-card);
    color: var(--brand-blue);
    box-shadow: var(--shadow-sm);
}

/* Pie / donut chart */
.pie-container {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.pie-chart-wrap {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.10));
}

.pie-legend {
    flex: 1;
    min-width: 160px;
    display: grid;
    gap: 0.45rem;
}

.pie-legend-item {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 0.5rem;
}

.pie-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pie-legend-label {
    font-size: 0.78rem;
    color: var(--text-body);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pie-legend-stat {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-dark);
    white-space: nowrap;
}

.pie-legend-stat em {
    font-style: normal;
    font-weight: 400;
    color: var(--text-muted);
}

.stat-section {
    margin-bottom: 1.75rem;
}

.stat-section:last-child {
    margin-bottom: 0;
}

.stat-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

.stat-bars {
    --bar-color: var(--brand-blue);
    display: grid;
    gap: 0.45rem;
}

.stat-row {
    display: grid;
    grid-template-columns: 140px 1fr 28px;
    align-items: center;
    gap: 0.6rem;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-body);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-bar-wrap {
    background: var(--bg-course);
    border-radius: var(--radius-full);
    height: 14px;
    overflow: hidden;
}

.stat-bar {
    height: 100%;
    background: var(--bar-color);
    border-radius: var(--radius-full);
    min-width: 6px;
    animation: growBar 0.5s ease-out both;
}

@keyframes growBar {
    from { width: 0 !important; }
}

.stat-count {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .container { padding: 1rem 0.5rem; }
    .tabs { margin-bottom: 1.5rem; }
    .nutrition-grid { grid-template-columns: repeat(2, 1fr); }
    .card { padding: 1.25rem; }
    .stat-row { grid-template-columns: 100px 1fr 24px; gap: 0.4rem; }
    .stat-label { font-size: 0.72rem; }
    .pie-container { flex-direction: column; align-items: center; }
    .pie-legend { width: 100%; }
}
