/* --- High-End Custom Diet Planner 2.0: Celestial Theme --- */
:root {
    --cdp-bg-dark-glass: rgba(10, 20, 40, 0.85);
    --cdp-border-glow: rgba(130, 170, 255, 0.3);
    --cdp-accent-blue: #82AAFF;
    --cdp-text-primary: #EAEAEA;
    --cdp-text-secondary: #C0C8E7;
    --cdp-text-bright: #FFFFFF;
    --cdp-button-gradient: linear-gradient(90deg, #89F7FE 0%, #66A6FF 100%);
    --cdp-button-text: #0A1428;
}

/* --- Main Planner Container --- */
#cdp-planner-wrapper {
    background-color: var(--cdp-bg-dark-glass);
    border: 1px solid var(--cdp-border-glow);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: clamp(20px, 5vw, 40px);
    max-width: 900px;
    margin: 40px auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--cdp-text-primary);
}

/* --- Typography --- */
#cdp-planner-wrapper h1, #cdp-planner-wrapper h2, #cdp-planner-wrapper h3 {
    text-align: center;
    color: var(--cdp-text-bright);
    text-shadow: 0 0 10px rgba(130, 170, 255, 0.5);
    margin-bottom: 15px;
}
.cdp-subtitle {
    text-align: center;
    margin-top: -10px;
    margin-bottom: 30px;
    color: var(--cdp-text-secondary);
    font-size: 1.1em;
}
.cdp-step-title {
    color: var(--cdp-text-bright);
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 15px;
}

/* --- Step 1: Initial Form --- */
#cdp-user-info {
    background: rgba(130, 170, 255, 0.1);
    border-left: 4px solid var(--cdp-accent-blue);
    padding: 15px 25px;
    margin-bottom: 30px;
    border-radius: 8px;
    text-align: center;
    font-size: 1.1em;
}
.cdp-form-group {
    margin-bottom: 25px;
}
.cdp-day-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.cdp-day-label {
    padding: 10px 20px;
    border: 1px solid var(--cdp-border-glow);
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
.cdp-day-label input {
    display: none;
}
.cdp-day-label:has(input:checked) {
    background-color: var(--cdp-accent-blue);
    color: var(--cdp-button-text);
    border-color: var(--cdp-accent-blue);
    font-weight: bold;
}
#cdp-food-cravings {
    width: 100%;
    padding: 15px;
    border: 1px solid var(--cdp-border-glow);
    border-radius: 8px;
    box-sizing: border-box;
    background-color: rgba(10, 20, 40, 0.9);
    color: var(--cdp-text-bright);
    font-size: 16px;
}
#cdp-generate-btn {
    background: var(--cdp-button-gradient);
    color: var(--cdp-button-text);
    width: 100%;
    padding: 15px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
}
#cdp-generate-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(122, 187, 255, 0.4);
}

/* --- Step 2: Interactive Planner --- */
#cdp-planner-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 1px solid var(--cdp-border-glow);
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.cdp-tab-day {
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease-in-out;
}
.cdp-tab-day.active {
    background-color: var(--cdp-accent-blue);
    color: var(--cdp-button-text);
    font-weight: bold;
}
.cdp-day-plan-content {
    display: none; /* JS will manage visibility */
}
.cdp-day-plan-content.active {
    display: block;
}
.cdp-calorie-bar-container {
    margin: 20px 0;
}
.cdp-calorie-bar {
    width: 100%;
    height: 25px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 30px;
    overflow: hidden;
    border: 1px solid var(--cdp-border-glow);
}
.cdp-calorie-bar-fill {
    height: 100%;
    width: 0%; /* JS will update this */
    background: linear-gradient(90deg, #57cbbf 0%, #82AAFF 100%);
    border-radius: 30px;
    transition: width 0.5s ease;
}
.cdp-calorie-bar-text {
    text-align: center;
    margin-top: 8px;
    font-weight: bold;
    color: var(--cdp-text-secondary);
}
.cdp-meal-type-section {
    margin: 25px 0;
}
.cdp-recipe-cards-container {
    display: flex;
    gap: 15px;
    overflow-x: auto; /* Allows horizontal scrolling of cards */
    padding: 15px;
    scrollbar-color: var(--cdp-accent-blue) transparent;
}
.cdp-recipe-card {
    flex: 0 0 280px; /* Cards have a fixed width */
    border: 1px solid var(--cdp-border-glow);
    border-radius: 10px;
    padding: 15px;
    background-color: rgba(0,0,0,0.2);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    position: relative;
}
.cdp-recipe-card.selected {
    border-color: var(--cdp-accent-blue);
    box-shadow: 0 0 15px rgba(130, 170, 255, 0.5);
}
.cdp-recipe-card h4 {
    margin: 0 0 10px 0;
    color: var(--cdp-text-bright);
}
.cdp-recipe-card p {
    margin: 0;
    font-size: 0.9em;
    color: var(--cdp-text-secondary);
}
.cdp-recipe-macros {
    font-size: 0.8em;
    margin-top: 10px;
    opacity: 0.8;
}
#cdp-finalize-plan-btn {
    /* Uses same style as generate button */
    background: var(--cdp-button-gradient);
    color: var(--cdp-button-text);
    width: 100%; padding: 15px; font-size: 18px; font-weight: bold;
    border-radius: 8px; border: none; cursor: pointer; transition: all 0.3s ease;
    margin-top: 20px;
}

/* --- Smart Swap Modal --- */
.cdp-modal {
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
}
.cdp-modal-content {
    background: var(--cdp-bg-dark-glass);
    padding: 30px;
    border: 1px solid var(--cdp-border-glow);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    position: relative;
}
.cdp-modal-close {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 28px;
    color: var(--cdp-text-secondary);
    cursor: pointer;
}
#cdp-swap-options-container {
    max-height: 40vh;
    overflow-y: auto;
}
.cdp-swap-option {
    padding: 15px;
    border: 1px solid var(--cdp-border-glow);
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
}
.cdp-swap-option:hover {
    background-color: rgba(130, 170, 255, 0.1);
}

/* --- Final Weekly Table --- */
.cdp-weekly-table-wrapper {
    margin-top: 30px;
}
.cdp-day-table-container {
    margin-bottom: 40px;
}
.cdp-day-title {
    color: var(--cdp-text-bright);
    border-bottom: 2px solid var(--cdp-accent-blue);
    padding-bottom: 10px;
    margin-bottom: 20px;
}
.cdp-diet-table {
    width: 100%;
    border-collapse: collapse;
}
.cdp-diet-table th, .cdp-diet-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--cdp-border-glow);
}
.cdp-diet-table th {
    color: var(--cdp-text-secondary);
}

/* --- Misc & Responsive --- */
.cdp-notice {
    text-align: center; padding: 30px; background: var(--cdp-bg-dark-glass);
    border-radius: 8px; border: 1px solid var(--cdp-border-glow);
    color: var(--cdp-text-secondary);
}
@media (max-width: 768px) {
    .cdp-diet-table, .cdp-diet-table thead, .cdp-diet-table tbody, .cdp-diet-table th, .cdp-diet-table td, .cdp-diet-table tr {
		display: block;
	}
    /* Hide table headers (but not display: none;, for accessibility) */
	.cdp-diet-table thead tr {
		position: absolute;
		top: -9999px;
		left: -9999px;
	}
    .cdp-diet-table td {
		border: none;
		border-bottom: 1px solid var(--cdp-border-glow);
		position: relative;
		padding-left: 50%;
        text-align: right;
	}
    .cdp-diet-table td:before {
		position: absolute;
		top: 12px;
		left: 10px;
		width: 45%;
		padding-right: 10px;
		white-space: nowrap;
        text-align: left;
        font-weight: bold;
        color: var(--cdp-text-secondary);
        content: attr(data-label);
	}
	/* --- High-End Mobile Responsiveness Enhancements --- */

/* This media query targets tablets and mobile phones */
@media (max-width: 768px) {

    /* --- General Text & Button Adjustments for Mobile --- */
    #cdp-planner-wrapper h1 {
        font-size: 1.8em; /* Further reduce main title size */
    }
    #cdp-generate-btn, #cdp-finalize-plan-btn {
        padding: 15px;
        font-size: 16px; /* A more standard mobile button font size */
    }

    /* --- The Definitive Recipe Card Fix --- */

    /* Make cards narrower to improve scrolling feel and prevent filling the screen */
    .cdp-recipe-card {
        flex: 0 0 220px; 
        padding: 15px; /* Reduce padding to give text more room */
        text-align: center; /* Center all text content within the card */
    }

    /* Drastically reduce the title font size on mobile */
    .cdp-recipe-card h4 {
        font-size: 1rem;  /* This is the most critical change. 1rem is a much better base size. */
        line-height: 1.25; /* Keep multi-line titles tight */
        font-weight: bold;
        margin-bottom: 8px;
    }

    /* Reduce the description text size */
    .cdp-recipe-card p {
        font-size: 0.85rem; /* Make description text clearly smaller than the title */
        line-height: 1.4;
    }

    /* Reduce the macro text size to be the smallest */
    .cdp-recipe-macros {
        margin-top: 12px;
        font-size: 0.75rem; /* Small and subtle */
    }

    /* --- Final Table Adjustments for Readability --- */
    .cdp-diet-table td {
        padding-left: 45%;
        padding-right: 10px;
        text-align: left;
    }
    .cdp-diet-table td:before {
        left: 15px;
        width: 40%;
    }
    
}
}
.cdp-final-plan-wrapper {
    margin-top: 30px;
}

.cdp-final-tabs-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 1px solid var(--cdp-border-glow);
    margin-bottom: 20px;
}

.cdp-final-tab-link {
    padding: 12px 22px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--cdp-text-secondary);
    font-size: 16px;
    font-weight: 500;
    position: relative;
    transition: color 0.3s ease;
}

.cdp-final-tab-link::after {
    content: '';
    position: absolute;
    bottom: -1px; /* Sits on top of the nav border */
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--cdp-accent-blue);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.cdp-final-tab-link.active {
    color: var(--cdp-text-bright);
    font-weight: bold;
}

.cdp-final-tab-link.active::after {
    transform: scaleX(1);
}

.cdp-final-tab-pane {
    display: none; /* All tabs are hidden by default */
    animation: cdpFadeIn 0.5s ease-in-out;
}

.cdp-final-tab-pane.active {
    display: block; /* The active tab is made visible */
}

/* A simple fade-in animation for the smooth effect */
@keyframes cdpFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ensure the table itself has a transparent background to blend in */
.cdp-final-tab-pane .cdp-diet-table {
    background-color: transparent;
    border: none;
    box-shadow: none;
}