/* --- START OF FILE static/style.css --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&family=Lora:wght@500&display=swap');

/* --- :root Variables - The Control Panel for Your Theme --- */
:root {
    --bg-color: #F8F9FA;
    /* Very light grey, almost white */
    --surface-color: #FFFFFF;
    /* Pure white for cards and modals */
    --primary-accent: #28a745;
    /* A fresh, vibrant green */
    --primary-accent-hover: #218838;
    /* A slightly darker green for hover */
    --secondary-accent: #6C757D;
    /* A calm, medium grey for secondary text */
    --text-color: #343a40;
    /* Dark grey for primary text, not pure black */
    --text-color-light: #495057;
    --border-color: #E9ECEF;
    /* Light, subtle border color */
    --danger-color: #dc3545;
    --error-bg-color: #f8d7da;
    --error-text-color: #721c24;

    --font-primary: 'Inter', sans-serif;
    --font-display: 'Lora', serif;
    /* A softer, more elegant serif for big titles */

    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.07);
    --shadow-strong: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none !important;
    /* Use important to override potential inline styles if needed */
}

/* --- General Body & Typography --- */
body {
    font-family: var(--font-primary);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 2rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: var(--surface-color);
    padding: 2.5rem;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-soft);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin-top: 0;
    color: var(--text-color);
    font-weight: 500;
}

h1 {
    font-family: var(--font-display);
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary-accent);
    /* Make the main title stand out */
}

h2 {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    margin-top: 2rem;
}

h3 {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: 1.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

p.error,
p.message {
    background-color: var(--error-bg-color);
    color: var(--error-text-color);
    padding: 1rem;
    border: 1px solid #f5c6cb;
    border-radius: var(--border-radius-md);
    margin: 1.5rem 0;
}

p.message.error {
    background-color: var(--error-bg-color);
    color: var(--error-text-color);
    border-color: #f5c6cb;
}

p.message:not(.error) {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}


/* --- Nutrient Stack Styles --- */
.stack-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 1rem;
    margin-top: 2rem;
    margin-bottom: 1.5rem;
    background: #fdfdfd;
    /* Slightly off-white inside */
}

#nutrient-stack-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#nutrient-stack-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

#nutrient-stack-list li:hover {
    background-color: #f7f7f7;
}

#nutrient-stack-list li:last-child {
    border-bottom: none;
}

#empty-stack-message {
    color: var(--secondary-accent);
    font-style: italic;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
}

#nutrient-stack-list li span {
    font-weight: 500;
    font-size: 1.1rem;
}

#nutrient-stack-list li small {
    color: var(--secondary-accent);
    margin-left: 1rem;
    margin-right: auto;
    background-color: var(--bg-color);
    padding: 0.2rem 0.5rem;
    border-radius: var(--border-radius-sm);
    font-size: 0.8rem;
}

.remove-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--secondary-accent);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.remove-btn:hover {
    color: var(--danger-color);
    background-color: #fce8e6;
    border-color: #f8c8c2;
}

.edit-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--secondary-accent);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.5rem;
    margin-right: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.edit-btn:hover {
    background-color: #eef3ff;
    border-color: var(--border-color);
}


/* --- Action Buttons (REVISED) --- */
.actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Base .button class for layout, font, etc. */
.button {
    display: inline-block;
    /* Crucial for <a> tags */
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    border: 1px solid transparent;
    text-decoration: none;
    /* Removes underline from <a> tags */
    text-align: center;
}

.button-primary {
    background-color: var(--primary-accent);
    color: white !important;
    /* Important to override default link color */
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.button-primary:hover {
    background-color: var(--primary-accent-hover);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.4);
}

.button.button-primary:disabled {
    background-color: #e9ecef;
    color: #adb5bd !important;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.button-calculate {
    background-color: var(--text-color);
    color: white !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.button-calculate:hover {
    background-color: #23272b;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.button.button-calculate:disabled {
    background-color: #e9ecef;
    color: #adb5bd !important;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}


/* --- Modal Styles (REVISED) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(33, 37, 41, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Changed from 'center' to 'flex-start' */
    padding-top: 10vh;
    /* Added padding to push modal down from the top edge */
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow-y: auto;
    /* Safety for short screens */
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius-md);
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow-strong);
    transform: translateY(20px);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.modal-overlay:not(.hidden) .modal-content {
    transform: translateY(0);
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--secondary-accent);
    cursor: pointer;
    transition: transform 0.2s ease, color 0.2s ease;
}

.modal-close-btn:hover {
    transform: rotate(90deg);
    color: var(--text-color);
}


/* --- Form and Input Styles inside Modal (REVISED) --- */
#nutrient-search-input,
.configure-inputs input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-sizing: border-box;
    /* margin-bottom is handled by container */
    background-color: var(--bg-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}

#nutrient-search-input:focus,
.configure-inputs input:focus {
    outline: none;
    border-color: var(--primary-accent);
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.15);
}

#search-view {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

#search-results-container {
    min-height: 250px;
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
}

#search-results-container ul {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    flex-grow: 1;
}

#search-results-container li {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease-out;
}

#search-results-container li:last-child {
    border-bottom: none;
}

#search-results-container li:hover {
    background-color: var(--primary-accent);
    color: white;
}

.configure-inputs {
    display: flex;
    gap: 1rem;
}

.configure-inputs label {
    flex: 1;
    font-size: 0.9rem;
    color: var(--secondary-accent);
}

.configure-inputs label span {
    display: inline-block;
    margin-bottom: 0.25rem;
}


/* --- New Browser View Styles --- */
.view-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.view-toggle button {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--secondary-accent);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    border-radius: 0;
}

.view-toggle button:hover {
    color: var(--text-color);
}

.view-toggle button.active {
    color: var(--primary-accent);
    border-bottom-color: var(--primary-accent);
}

#nutrient-tree-container {
    max-height: 300px;
    min-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 0.5rem;
}

#nutrient-tree-container ul {
    list-style-type: none;
    padding-left: 1rem;
}

#nutrient-tree-container li {
    padding: 0.25rem 0;
}

#nutrient-tree-container .category-header {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
}

#nutrient-tree-container .category-header:hover {
    background-color: var(--bg-color);
}

#nutrient-tree-container .toggle-icon {
    display: inline-block;
    margin-right: 0.5rem;
    transition: transform 0.2s ease-in-out;
}

#nutrient-tree-container .toggle-icon.open {
    transform: rotate(90deg);
}

.nutrient-item {
    padding-left: 1.25rem;
}

.selectable-nutrient {
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius-sm);
}

.selectable-nutrient:hover {
    background-color: #eaf6ec;
    color: var(--primary-accent-hover);
}

.in-stack {
    color: var(--secondary-accent);
    font-style: italic;
    cursor: not-allowed;
    text-decoration: line-through;
}

.non-selectable {
    color: var(--secondary-accent);
    font-style: italic;
}



/* --- Results Page Specifics --- */
.results-summary p {
    margin: 0.25rem 0;
    font-size: 1.1rem;
}

.results-summary p strong {
    font-weight: 500;
    color: var(--text-color);
}

.results-summary .total-cost {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-accent);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.95rem;
}

th,
td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
    vertical-align: middle;
}

thead {
    background-color: var(--bg-color);
    color: var(--secondary-accent);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

tbody tr:hover {
    background-color: #fdfdfd;
}

td.value-col {
    text-align: right;
}

th.value-col {
    text-align: right;
}

/* Specific styling for results summary */
.status.exceeded {
    background-color: #fff3cd;
    color: #856404;
}

.status.below-min {
    background-color: var(--error-bg-color);
    color: var(--error-text-color);
}

.status.within-range {
    background-color: #d4edda;
    color: #155724;
}

.status {
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    text-align: center;
    font-size: 0.85rem;
}


/* --- Product Card Layout --- */
.product-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.product-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-strong);
}

.product-card__header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.product-card__header h4 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.product-card__header h4 a {
    text-decoration: none;
    color: var(--primary-accent);
}

.product-card__header h4 a:hover {
    text-decoration: underline;
}

.product-card__details {
    padding: 1rem 1.25rem;
    list-style: none;
    margin: 0;
    font-size: 0.95rem;
}

.product-card__details li {
    display: flex;
    justify-content: space-between;
    color: var(--text-color-light);
}

.product-card__details li+li {
    margin-top: 0.5rem;
}

.product-card__details li strong {
    color: var(--text-color);
    font-weight: 500;
}


.product-card__content {
    padding: 0 1.25rem 1.25rem;
    flex-grow: 1;
}

.nutrient-list {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.9rem;
    color: var(--text-color-light);
}

.nutrient-list li {
    margin-bottom: 0.25rem;
}


.product-card__footer {
    padding: 0 1.25rem 1rem;
    margin-top: auto;
    /* Pushes footer to the bottom */
}

.toggle-nutrients {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--secondary-accent);
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
    transition: background-color 0.2s ease;
}

.toggle-nutrients:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

.toggle-nutrients .icon {
    transition: transform 0.2s ease-in-out;
}

.toggle-nutrients.open .icon {
    transform: rotate(90deg);
}

#all-summary-toggle {
    margin-top: 1rem;
}



@media (max-width: 600px) {
    body {
        padding: 1rem;
    }

    .container {
        padding: 1.5rem;
    }

    .responsive-table {
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-md);
        overflow: hidden;
    }

    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        display: block;
        margin-bottom: 1rem;
        border-bottom: 2px solid var(--primary-accent);
    }

    .responsive-table tr:last-child {
        margin-bottom: 0;
        border-bottom: 0;
    }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0.75rem;
        text-align: right;
    }

    .responsive-table td:last-child {
        border-bottom: 0;
    }

    .responsive-table td::before {
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
        color: var(--text-color);
    }

    .product-card {
        flex-basis: 100%;
    }
}