/* Root variables for site-wide consistency */
:root {
    --primary-color: #27AE60;
    /* Default */
    --primary-color-hover: #23bc63;
    /* Default */
    --background-color: #0f0f0f;
    /* Default */
    --surface-color: #171717;
    /* Default */
    --text-color-primary: ;
    /* Default */
    --text-color-secondary: ;

    --tool-tip-text-color: #fff;

    --tool-tip-background-color: #444;
    /* Default */
    --font-family: "Heebo", sans-serif;
    /* Default */

}

/* General Body Styles */
body {
    background-color: var(--background-color);
    margin: 0;
    /* Prevent any element from causing horizontal scrolling on the page */
    overflow-x: hidden;
    color: var(--text-color-primary);
    /* Set the default text color for the entire page */
    font-family: var(--font-family);
    /*
     * Support for a customizable tiling background image.
     * These CSS variables are set via an inline style on the body tag by PHP.
     */
    background-image: var(--background-image-url);
    background-size: var(--background-image-size, auto);
    background-repeat: repeat;
}

html {
    /* Applying this to the root HTML element is a more robust way to prevent
       any horizontal overflow on the entire page. */
    overflow-x: hidden;
}

/* New wrapper to prevent horizontal overflow on all pages */
.page-wrapper {
    overflow-x: hidden;
}

/* Utility class to hide elements */
.hidden {
    display: none !important;
}

/* Home Screen Styles */
.home-container {
    max-width: 800px;
    margin: 40px auto;
    padding: 20px;
    background-color: var(--surface-color);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: var(--text-color-primary);
    /* Ensure text inside this container uses the primary color */
    text-align: center;
}

/* Styles for content that appears after accepting the disclaimer */
#content-after-acceptance {
    margin-top: 30px;
}

#content-after-acceptance ul {
    list-style-type: disc;
    padding-left: 20px;
    text-align: left;
}

#content-after-acceptance li {
    margin-bottom: 10px;
}

.disclaimer-text {
    font-size: 0.85em;
    color: var(--text-color-secondary);
}

.small-print {
    font-size: 0.8em;
    margin-top: 30px;
    color: var(--text-color-secondary);
}

.link-tooltip-area {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    text-align: left;
}

.main-page-content-item {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    background-color: var(--surface-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    height: fit-content;
}

.main-page-content-item img {
    width: 100%;
    height: auto;
    max-width: 100%px;
    min-width: 100%;
    object-fit: contain;
}

.main-page-content-item h3 {
    margin: 0;
    font-size: 1.2em;
    color: var(--text-color-primary);
}

@media (max-width: 600px) {
    .main-page-content-item {
        flex-direction: column;
        text-align: center;
    }
}

.home-container h1 {
    font-size: 2em;
    margin-bottom: 20px;
}

/* The left column containing the image */
.main-page-item-image-wrapper {
    flex: 1 1 50%;
    /* Takes up 50% of the container width */
    min-width: 300px;
    /* Prevents the image column from becoming too small */
}

/* This is the container for a single main page item */
.main-page-item-container {
    display: flex;
    flex-wrap: wrap;
    /* Allows columns to stack on smaller screens */
    align-items: stretch;
    /* Makes both columns equal height */
    width: 100%;
    background-color: transparent;
    border: none;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: none;
}

/* The left column containing the image */
.main-page-item-image-wrapper {
    flex: 1 1 50%;
    /* Takes up 50% of the container width */
    min-width: 300px;
    /* Prevents the image column from becoming too small */
}

.main-page-item-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Ensures the image covers the area without distortion */
    display: block;
    /* Removes bottom space under the image */
}

/* The right column containing the text */
.main-page-item-text-wrapper {
    flex: 1 1 50%;
    /* Takes up 50% of the container width */
    padding: 2rem;
    /* Adds nice spacing inside the text box */
    box-sizing: border-box;
    /* Ensures padding is included in the 50% width */
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Vertically aligns content to the center */
    color: var(--text-color-primary);
    /* Ensure text in the right column is readable */
    min-width: 300px;
    /* Matches the image wrapper for responsive stacking */
    text-align: left;
}

/* Handle case where image is missing */
.main-page-item-container.no-image .main-page-item-text-wrapper {
    flex: 1 1 100%;
    width: 100%;
}

/* This is the inner container for the text, which is NOT a flex container.
   This prevents KaTeX from breaking formulas into multiple lines. */
.main-page-item-text-content {
    width: 100%;
    /* Ensure it takes the full width of its parent */
}

.home-container .disclaimer {
    font-size: 1em;
    color: var(--text-color-secondary);
    margin-bottom: 30px;
}

.home-container .accept-button {
    display: inline-block;
    margin-top: 30px;
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: var(--text-color-primary);
    text-decoration: none;
    border-radius: 5px;
    font-size: 1.1em;
    transition: background-color 0.2s;
}

.home-container .accept-button:hover {
    background-color: var(--primary-color-hover);
}

.tooltip-items-container {
    display: flex;
    gap: 20px;
    font-size: 0.95em;
    flex-wrap: wrap;
    cursor: default;
}

/* Shared style for the 'x' dismiss buttons on modals */
.btn-dismiss {
    position: absolute !important;
    top: -10px !important;
    left: -10px !important;
    background-color: #8c8787 !important;
    color: var(--text-color-primary) !important;
    border: none !important;
    border-radius: 50% !important;
    width: 20px !important;
    height: 20px !important;
    font-size: 12px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    transition: background-color 0.3s !important;
}

/* Tooltip styles for grid items, now also used for chart labels */
.item-info-icon {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    background-color: transparent;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--text-color-secondary);
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    font-style: italic;
    font-weight: bold;
    z-index: 2;
}

.item-info-tooltip {
    max-height: 200px;
    /* Allow scrolling for long content */
    overflow-x: hidden;
    /* Prevent horizontal overflow */
    overflow-y: auto;
    /* Enable vertical scrollbar when needed */
    width: max-content;
    /* Let the content determine the width */
    visibility: hidden;
    width: max-content;
    /* Let the content determine the width */
    max-width: 220px;
    /* But don't let it get too wide */
    background-color: var(--tool-tip-background-color);
    word-wrap: break-word;
    /* Allow long words to wrap */
    color: var(--tool-tip-text-color);
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    /* Fade-in transition */
    transition-delay: 0.5s;
    /* Delay the fade-in by 0.5 seconds */
    font-size: 0.9rem;
    font-style: normal;
    font-weight: normal;
    line-height: 1.4;
    pointer-events: none;
}

/* New style to flip the tooltip when it's too close to the top of the viewport */
.item-info-icon.tooltip-opens-down .item-info-tooltip {
    top: 125%;
    /* Position below the icon */
    bottom: auto;
    /* Override the default bottom positioning */
}

.item-info-icon.show-tooltip .item-info-tooltip {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* Allow interaction (like scrolling or clicking links) when visible */
}

.item-info-icon::after {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
}

.btn-dismiss:hover {
    background-color: #cc0000 !important;
}

.info-icon {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--surface-color);
    /* To cover the card corner */
    cursor: pointer;
    font-size: 0.8em;
    color: var(--text-color-secondary);
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    font-style: italic;
    font-weight: bold;
}

.info-tooltip {
    visibility: hidden;
    width: 220px;
    background-color: #444;
    color: red;
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    /* Position above the icon */
    left: 50%;
    transform: translateX(-50%);
    /* Use transform to center for dynamic adjustments */
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    font-style: normal;
    font-weight: normal;
    line-height: 1.4;
    pointer-events: none;
    /* Prevent tooltip from interfering with hover when hidden */
}

.info-tooltip .tooltip-definition {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--text-color-secondary);
    /* Separator line */
    font-size: 0.9em;
    line-height: 1.3;
}

.info-tooltip .tooltip-section {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--text-color-secondary);
}

.info-icon.show-tooltip .info-tooltip,
.info-icon:hover .info-tooltip {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* Allow interaction with links when visible */
}

.info-tooltip .tooltip-row {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.info-tooltip .tooltip-row:last-child {
    margin-bottom: 0;
}

.info-tooltip .green-dot,
.info-tooltip .yellow-dot,
.info-tooltip .red-dot {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
    flex-shrink: 0;
}

.info-tooltip .green-dot {
    background-color: var(--primary-color);
}

.info-tooltip .yellow-dot {
    background-color: #F1C40F;
}

.info-tooltip .red-dot {
    background-color: #E74C3C;
}

.info-tooltip .warn-text {
    font-style: italic;
    color: #ffc107;
    margin-top: 5px;
    border-top: 1px solid #555;
    padding-top: 5px;
}

/* Methodology Modal Styles */
.methodology-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.methodology-modal-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.methodology-modal-content {
    background: var(--surface-color);
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    position: relative;
    transform: translateY(-50px);
    transition: transform 0.3s ease;
}

.methodology-modal-backdrop.show .methodology-modal-content {
    transform: translateY(0);
}

.methodology-modal-content h2 {
    margin-top: 0;
    text-align: center;
    color: var(--text-color-primary);
}

.methodology-modal-content .tooltip-section {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
    text-align: left;
    font-size: 1rem;
}

/* Methodology Notch Button Styles */
.methodology-notch-btn {
    position: fixed;
    /* Use fixed positioning to not interfere with nav layout */
    /* The 'bottom' property is now set dynamically by JavaScript */
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    /* Make it wider */
    height: 40px;
    /* Make it shorter */
    background-color: var(--surface-color);
    border: 2px solid var(--primary-color);
    border-bottom: none;
    /* Remove bottom border to blend with nav bar */
    border-radius: 10px 10px 0 0;
    /* Round top corners only */
    color: var(--text-color-primary);
    /* Use primary color for the text */
    font-size: 1em;
    /* Use a relative font size */
    font-family: var(--font-family);
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
    /* Softer, more modern shadow */
    transition: background-color 0.2s, transform 0.3s ease-out, opacity 0.3s ease-out;
    z-index: 999;
    /* Position it BEHIND the nav bar (which is at z-index 1000) */
}

.methodology-notch-btn:hover {
    background-color: var(--primary-color-hover);
    transform: translateX(-50%) scale(1.05);
    /* Adjust hover transform */
}

/* Class to hide the notch button when scrolling down */
.methodology-notch-btn.notch-hidden {
    transform: translate(-50%, 150%);
    /* Move it down out of view */
    opacity: 0;
    pointer-events: none;
}

/* Styles for the new hyperlink container in the item details modal */
.modal-hyperlinks-container {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    /* A subtle separator */
    text-align: center;
    /* Center the links */
}

.modal-hyperlinks-container ul {
    list-style-type: none;
    /* Remove bullet points */
    padding: 0;
    margin: 0;
}

.modal-hyperlinks-container li {
    margin-bottom: 8px;
    /* Space between multiple links */
}

.modal-hyperlinks-container a {
    display: inline-block;
    padding: 10px 20px;
    margin: 5px;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    text-align: center;
    font-family: var(--font-family);
    transition: background-color 0.3s;
}

/* ==========================================================================
   Modal Styles
   ========================================================================== */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1001;
    /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: auto;
    /* Enable scroll if needed */
    background-color: rgba(0, 0, 0, 0.4);
    /* Black w/ opacity */
    justify-content: center;
    /* Center content horizontally */
    align-items: center;
    /* Center content vertically */
    font-family: var(--font-family);
}

.modal.show {
    display: flex;
    /* Use flex to center content */
}

.modal-content {
    background-color: var(--surface-color);
    margin: auto;
    padding: 15px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    max-height: 95vh;
    overflow: visible;
    border-radius: 10px;
    position: relative;
    text-align: center;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

#modal-food-name {
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    margin-bottom: 10px;
    flex-shrink: 0;
}

#modal-food-image {
    max-width: 100%;
    flex: 1 1 auto;
    min-height: 50px;
    width: auto;
    height: auto;
    margin: 10px auto;
    border-radius: 5px;
    object-fit: contain;
}

.servings-label {
    display: block;
    margin-top: 20px;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text-color-primary);
    flex-shrink: 0;
}

.servings-control {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 5px 0 20px;
    flex-shrink: 0;
}

.servings-control .servings-decrease,
.servings-control .servings-increase {
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    cursor: pointer;
    margin: 0 5px;
    /* Adjust margin to separate from input */
}

.servings-control .servings-decrease {
    border-right: 8px solid var(--primary-color);
    /* Left-pointing triangle */
}

.servings-control .servings-increase {
    border-left: 8px solid var(--primary-color);
    /* Right-pointing triangle */
}

.servings-control input {
    width: 60px;
    padding: 8px;
    text-align: center;
    font-size: 1.1em;
    border: 1px solid #ccc;
    border-radius: 5px;
}

/* Hide spin buttons on number inputs inside servings control */
.servings-control input::-webkit-outer-spin-button,
.servings-control input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.servings-control input {
    -moz-appearance: textfield;
    appearance: textfield;
}

.live-lead-contribution {
    font-size: 1.1em;
    margin-bottom: 20px;
}

.modal-actions {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* General button styles within modals */
#modal-save-button,
#modal-cancel-button,
#modal-deselect-button,
#historical-save-btn,
#historical-clear-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1.1em;
    cursor: pointer;
    font-family: var(--font-family);
    border-radius: 5px;
    transition: background-color 0.3s;
}

@media (max-width: 480px) {

    #modal-save-button,
    #modal-cancel-button,
    #modal-deselect-button {
        padding: 8px 15px;
        font-size: 1rem;
    }
}

#modal-save-button:hover {
    background-color: var(--primary-color-hover);
}

/* Specific modal button styles */
#modal-cancel-button {
    background-color: #ccc;
    color: #333;
}

#modal-cancel-button:hover {
    background-color: #bbb;
}

#modal-deselect-button,
#historical-clear-btn {
    background-color: #dc3545;
    /* Red color */
}

#modal-deselect-button:hover {
    background-color: #c82333;
    /* Darker red on hover */
}

/* Styles for the email form when it appears inside a modal */
.modal .email-form-container {
    margin: 20px 0;
}

.modal .small-print {
    font-size: 0.8em;
    color: var(--text-color-secondary);
    margin-top: 15px;
}

/* ==========================================================================
   Shared Bottom Navigation Styles
   ========================================================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: var(--surface-color);
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    /* This was missing */
    justify-content: center;
    align-items: center;
    padding: 10px;
    z-index: 1000;
    box-sizing: border-box;
}

.bottom-nav #summary-results {
    display: flex;
    justify-content: center;
    align-items: stretch;
    /* Make all cards the same height */
    flex-wrap: nowrap;
    /* Prevent items from ever stacking vertically */
    gap: 20px;
    max-width: 900px;
    /* Increased max-width to allow children to be wider */
    padding: 0 10px;
    box-sizing: border-box;
}

/* Responsive scaling for the methodology modal on smaller screens */
@media (max-width: 550px) {
    .methodology-modal-content {
        padding: 15px;
        /* Reduce padding */
    }

    .methodology-modal-content h2 {
        font-size: 1.2em;
        /* Smaller heading */
    }

    .methodology-modal-content .tooltip-section {
        font-size: 0.9rem;
        /* Smaller text for the formulas */
    }

    .methodology-notch-btn {
        width: 110px;
        /* Narrower for mobile */
        height: 35px;
        /* Shorter for mobile */
        font-size: 0.8em;
        /* Smaller font */
    }
}

/* Responsive behavior for smaller screens */
@media (max-width: 768px) {
    .main-page-item-container {
        flex-direction: column;
        /* Stack the columns vertically */
    }

    .main-page-item-image-wrapper,
    .main-page-item-text-wrapper {
        flex-basis: auto;
        /* Allow columns to take full width when stacked */
    }
}