:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --primary: #16a34a;
    --primary-dark: #15803d;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e5e7eb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
                 Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ===================================
   UNIVERSAL PAGE SPACING
=================================== */
.main-wrapper {
    max-width: 1200px;
    margin: 0 auto;        /* center content */
    padding: 0 24px;       /* left & right spacing */
}
/* ---------- NAVBAR ---------- */

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    transition: background 0.3s ease, border 0.3s ease;
}

.nav-left {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
}

.nav-right a {
    margin-left: 18px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
    transition: color 0.2s ease;
}

.nav-right a:hover {
    color: var(--primary);
}

.nav-right a.active {
    color: var(--primary);
    font-weight: 600;
}


/* ---------- HERO ---------- */

.hero {
    max-width: 900px;
    margin: 90px auto;
    text-align: center;
    padding: 0 20px;
}

.hero h1 {
    font-size: 42px;
    margin-bottom: 16px;
}

.hero p {
    font-size: 18px;
    color: var(--muted);
    line-height: 1.6;
}

.hero-actions {
    margin-top: 36px;
}

/* ---------- BUTTONS ---------- */

.btn {
    display: inline-block;
    padding: 14px 26px;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn.secondary {
    background: #334155;
}

.btn.secondary:hover {
    background: #1e293b;
}

/* ---------- PAGE CONTENT ---------- */

h1 {
    margin-top: 30px;
    margin-bottom: 20px;
}

input,
select {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-right: 8px;
    font-size: 14px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ---------- RESULTS LIST ---------- */

#results {
    margin-top: 20px;
}

#results > div {
    background: var(--card);
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 10px;
    transition: box-shadow 0.2s ease, transform 0.1s ease;
}

#results > div:hover {
    box-shadow: 0 6px 16px rgba(0,0,0,0.06);
    transform: translateY(-2px);
}

#results a {
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
}
/* ---------- PAGINATION ---------- */

#pagination {
    display: flex;           /* use flexbox */
    justify-content: center; /* center horizontally */
    flex-wrap: wrap;         /* wrap buttons if too many */
    gap: 6px;                /* spacing between buttons */
    margin: 20px 0;
}

#pagination button {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

#pagination button:hover:not(:disabled) {
    background: var(--bg);
    border-color: var(--primary);
}

#pagination button:disabled {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    cursor: default;
}

/* ---------- FOOD DETAIL ---------- */

#nutrients div,
#similarFoods div {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 6px;
}

#similarFoods a {
    color: var(--primary);
    text-decoration: none;
}
/* ---------- MOBILE ---------- */

@media (max-width: 600px) {
    .hero h1 {
        font-size: 32px;
    }

    .navbar {
        flex-direction: column;
        gap: 8px;
    }

    input,
    select {
        width: 100%;
        margin-bottom: 8px;
    }

    .nav-links {
        gap: 12px;
        flex-wrap: wrap;
        justify-content: center;
    }
}


/* ---------- RESULT CARD ---------- */

.result-card {
    margin-top: 20px;
    padding: 20px;
    border-radius: 12px;
    background: var(--card);
    border: 1px solid var(--border);
}


/* ---------- LISTS ---------- */

.nutrition-list,
#similar-foods {
    list-style: none;
    padding: 0;
}

.nutrition-list li,
#similar-foods li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}


/* ---------- SEARCH ROW ---------- */

.search-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}


/* ---------- RESULTS LIST ---------- */

.results-list .result-item,
.similar-list div {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.results-list span,
.similar-list span {
    color: var(--muted);
    font-size: 0.9em;
    margin-left: 6px;
}


/* ---------- NAV BRAND / LINKS ---------- */

.nav-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 20px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-link {
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    transition: color 0.2s ease;
}

.nav-link:hover {
    color: var(--primary);
}

/* ACTIVE LINK */
.nav-link.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 2px;
}


/* ---------- NUTRIENT GROUP ---------- */

.nutrient-group {
    margin-bottom: 18px;
}

.nutrient-group h4 {
    margin: 10px 0 6px;
    font-size: 15px;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.nutrient-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px dashed var(--border);
}
/* ---------- FOOD DETAILS LAYOUT ---------- */

.food-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-top: 30px;
}

.food-left {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.food-right {
    background: var(--card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 900px) {
    .food-layout {
        grid-template-columns: 1fr;
    }

    .food-right {
        margin-top: 20px;
    }
}


/* =========================================
   CALCULATOR PAGE
========================================= */

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 25px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.04);
}

thead {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

th {
    padding: 12px 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

td {
    padding: 10px 8px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
}

tbody tr:hover {
    background: var(--bg);
}


/* Smaller amount input */
td input[type="number"] {
    width: 65px;
    padding: 6px;
    text-align: center;
    font-size: 13px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
}


/* Add Food button */
button[onclick="openModal()"] {
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

button[onclick="openModal()"]:hover {
    background: var(--primary-dark);
}


/* Remove button */
td button {
    padding: 5px 10px;
    border-radius: 6px;
    border: none;
    background: var(--border);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

td button:hover {
    background: var(--bg);
}


/* Totals card */
.total-box {
    margin-top: 30px;
    background: var(--card);
    padding: 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: 0 6px 20px rgba(0,0,0,0.05);
}


/* =========================================
   MODAL (Add Food Popup - Improved)
========================================= */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal-content {
    background: var(--card);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 30px 80px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalFade 0.25s ease;
}

@keyframes modalFade {
    from { transform: translateY(15px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Header */
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

/* Close Button */
.modal-close {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--muted);
}

.modal-close:hover {
    color: var(--primary);
}

/* Search Area */
.modal-search {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-search input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 14px;
}

/* Results Area */
.modal-results {
    overflow-y: auto;
    padding: 10px 24px 20px;
    flex: 1;
}

/* Search Items */
.search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.search-item span {
    font-size: 14px;
    color: var(--text);
}

/* Add Button */
.search-item button {
    padding: 6px 14px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.search-item button:hover {
    background: var(--primary-dark);
}

.portion-controls {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.portion-controls input {
    width: 80px;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.portion-controls select {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
}


/* Animation */
@keyframes fadeIn {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
/* ---------- FOOTER ---------- */

.site-footer {
    margin-top: 100px;
    background: var(--card);
    border-top: 1px solid var(--border);
    border-radius: 0 !important;
}

.footer-accent {
    height: 3px;
    background: linear-gradient(
        90deg,
        var(--primary),
        var(--primary-dark)
    );
}

.footer-content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 28px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.footer-left p,
.footer-right p {
    margin: 4px 0;
    color: var(--muted);
    font-size: 14px;
}

.footer-small {
    font-size: 12px;
    color: var(--muted);
}


/* ===============================
   THEME VARIABLES (KEEP ONLY ONE)
================================ */

:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e5e7eb;
    --primary: #16a34a;
    --primary-dark: #15803d;
}

body {
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s ease, color 0.3s ease;
}


/* ---------- DARK THEME ---------- */

.dark {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #22c55e;
    --primary-dark: #16a34a;
}


/* ---------- TOGGLE BUTTON ---------- */

.dark-toggle {
    margin-left: 20px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s ease;
}

.dark-toggle:hover {
    opacity: 0.8;
}


/* ---------- INPUTS GLOBAL ---------- */

input,
select {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Make page take full height */
html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
}

/* Main content should expand */
.hero {
    flex: 1;
}

.more-box {
    display: none;
}

.dataset-info {
  position: relative;
  display: inline-block;
  margin-left: 6px;
}

.info-link {
  font-size: 12px;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  font-weight: normal;
}

.tooltip {
  visibility: hidden;
  opacity: 0;
  width: 400px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 15px;
  border-radius: 10px;
  position: absolute;
  top: 120%;
  left: 0;
  z-index: 1000;
  transition: opacity 0.2s ease;
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  font-size: 14px;
  line-height: 1.5;
}

.dataset-info:hover .tooltip {
  visibility: visible;
  opacity: 1;
}


.page-container {
    width: 100%;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 24px;
    padding-right: 24px;
}

/* Improve form container */
.form-container {
    max-width: 600px;
    margin: 40px auto;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Result styling */
.result-box {
    margin-top: 25px;
    padding: 25px;
    background: var(--card-bg);
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.bmi-highlight {
    font-size: 22px;
    font-weight: bold;
}

.bmi-advice {
    margin-top: 15px;
    padding: 15px;
    background: rgba(76,175,80,0.08);
    border-left: 4px solid #4CAF50;
    border-radius: 8px;
}

/* ===============================
   FORM IMPROVEMENTS
================================ */

.form-container {
    max-width: 650px;
    margin: 60px auto;
    padding: 40px;
    background: var(--card);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.form-container h2 {
    margin-bottom: 30px;
    text-align: center;
}

/* Grid spacing */
.form-grid {
    display: grid;
    gap: 22px;
}

/* Each form row */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Better labels */
.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* Inputs */
.form-group input,
.form-group select {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
}

/* Inline height inputs */
.inline-inputs {
    display: flex;
    gap: 12px;
}

.inline-inputs input {
    flex: 1;
}

/* Checkbox alignment */
.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* Full width button */
.full-width {
    width: 100%;
    margin-top: 30px;
}

/* ========= FOOTER ========= */

.site-footer {
    margin-top: 60px;
    padding: 30px 20px;
    background: var(--card);
    border-top: 1px solid var(--border);
}

.footer-content {
    max-width: 1100px;
    margin: 0 auto;
    text-align: center;
}

/* Links row */
.footer-content a {
    margin: 0 12px;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: color 0.2s ease;
}

.footer-content a:hover {
    color: #22c55e; /* green accent */
}

/* Divider spacing */
.footer-content p {
    margin-top: 15px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}

/* Small copyright text */
.footer-small {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
}

/* Optional: add spacing between links and text */
.footer-content a + a {
    position: relative;
}

.footer-content a + a::before {
    content: "|";
    position: absolute;
    left: -14px;
    color: var(--border);
}

/* BLOG LIST */
.blog-list {
    display: grid;
    gap: 20px;
    margin-top: 20px;
}

.blog-card {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    transition: 0.2s;
}

.blog-card:hover {
    transform: translateY(-3px);
}

.blog-card a {
    text-decoration: none;
    color: var(--text);
}

.blog-page {
    max-width: 800px;
    margin: auto;
}

.blog-meta {
    color: var(--muted);
    margin-bottom: 20px;
}