:root {
    --primary: #0048ac;
    --secondary: #ffb200;
    --tertiary: #ffffff;
    --bg: #f5f8fc;
    --card: #ffffff;
    --text-main: #0048ac;
    --border: #dee6f0;
}

body.dark {
    --bg: #0b1426;
    --card: #16243d;
    --text-main: #ffb200;
    --border: #2a3b5a;
}

* {
    box-sizing: border-box;
    font-family: 'Segoe UI', Roboto, sans-serif;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text-main);
    overflow: hidden;
}

/* ================= FULL SCREEN WRAP ================= */

.main-wrapper {
    height: calc(100vh - 20px);
    margin: 10px auto;
    max-width: 1100px;
    display: flex;
}

.calculator-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--primary);
    border-radius: 16px;
    padding: 14px 18px;
}

/* ================= HEADER ================= */

.app-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 90px;
    border-bottom: 1px solid var(--border);
}

.logo-area {
    display: flex;
    align-items: center;
}

.app-logo {
    height: 60px;
}

.title-area {
    text-align: center;
}

.main-title {
    margin: 0;
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
}

body.dark .main-title {
    color: var(--secondary);
}

.sub-brand {
    font-size: 13px;
    opacity: 0.8;
}

.theme-switcher {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
}

/* ================= TOGGLE ================= */

.switch {
    position: relative;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 20px;
    cursor: pointer;
}

.slider:before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked + .slider {
    background: var(--primary);
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

body.dark .switch input:checked + .slider {
    background: var(--secondary);
}

/* ================= BRAND TABS ================= */

.brand-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 12px 0 18px;
}

.brand-btn {
    padding: 8px 22px;
    border-radius: 22px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 800;
    cursor: pointer;
}

.brand-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

body.dark .brand-btn.active {
    background: var(--secondary);
    color: #000;
}

/* ================= FILTER BAR (FIXED) ================= */

.controls-row {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 200px;
    gap: 16px;
    margin-bottom: 14px;
}

.control-group label {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
    display: block;
}

.control-group select,
.control-group input {
    width: 100%;
    min-height: 44px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-main);
    font-weight: 600;
}

/* ================= MAIN GRID ================= */

.calc-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    overflow: hidden;
}

/* ================= PANELS ================= */

.panel {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    overflow: hidden;
}

.panel-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.panel-title {
    font-size: 18px;
    font-weight: 800;
}

/* ================= MENU ================= */

#menuContainer {
    flex: 1;
    overflow-y: auto;
}

.item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--card);
}

.item-card p {
    margin: 0;
    font-weight: 700;
}

.item-card span {
    font-size: 12px;
    opacity: 0.7;
}

.btn-add {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

body.dark .btn-add {
    background: var(--secondary);
    color: #000;
}

/* ================= YOUR MEAL ================= */

#mealContainer {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 8px;
}

/* ================= TOTALS (FIXED) ================= */

.totals-board {
    border-top: 1px solid var(--border);
    padding-top: 6px;
    flex-shrink: 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.stat-box {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
}

.stat-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-inline span {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.7;
}

.stat-inline b {
    font-size: 14px;
}

/* ================= MOBILE ================= */

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .main-wrapper {
        height: auto;
        margin: 10px;
    }

    .calc-grid {
        grid-template-columns: 1fr;
    }

    .controls-row {
        grid-template-columns: 1fr;
    }

    #menuContainer {
        max-height: 300px;
    }

    #mealContainer {
        max-height: 240px;
    }
}


/* =========================
   YOUR MEAL + TOTALS FINAL FIX
========================= */

/* Right panel structure */
.panel:last-child {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Meal list: max 4 items then scroll */
#mealContainer {
    flex: 1;
    max-height: 260px;        /* ~4 items */
    overflow-y: auto;
    margin-bottom: 6px;
}

/* Totals always visible at bottom */
.totals-board {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--card);
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

/* Compact totals layout */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

/* Each stat row: left label, right value */
.stat-box {
    padding: 6px 10px;
}

.stat-box.stat-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Left text */
.stat-box.stat-inline span {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.75;
    margin: 0;
}

/* Right value */
.stat-box.stat-inline b {
    font-size: 14px;
    font-weight: 800;
    margin: 0;
}

/* Prevent totals jumping on add/remove */
.panel:last-child > * {
    flex-shrink: 0;
}

/* ================= MOBILE SAFE ================= */
@media (max-width: 900px) {
    #mealContainer {
        max-height: 220px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}


/* =========================
   WWS JSON TOOL PATCHES
========================= */

/* Hidden (indexable) tool FAQs */
.tool-faqs{
  position:absolute;
  left:-9999px;
  top:auto;
  width:1px;
  height:1px;
  overflow:hidden;
}

/* Theme labels in dark mode */
body.dark .theme-switcher span{
  color: var(--tertiary);
  opacity: 0.95;
}

/* Brand tab text color in dark mode */
body.dark .brand-btn{
  color: var(--primary);
}
body.dark .brand-btn.active{
  color: var(--primary);
}

/* Your Meal left border control */
.meal-item{
  border-left: 4px solid var(--primary);
}
body.dark .meal-item{
  border-left-color: var(--secondary);
}

/* Trash button visibility in dark mode */
.meal-remove{
  color: inherit; /* SVG uses currentColor */
}
body.dark .meal-remove{
  color: var(--tertiary);
  border-color: var(--tertiary);
}

/* Totals: label left, value right */
.stat-box{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.stat-box span{ white-space:nowrap; }
.stat-box b{ margin-left:auto; white-space:nowrap; }

/* Mobile header layout */
@media (max-width: 600px){
  .app-header{
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .logo-area{ justify-content:center; }
  .title-area{ text-align:center; }
  .theme-switcher{ justify-content:center; }
  .brand-tabs{ flex-wrap: wrap; gap: 8px; justify-content:center; }
}









/* ===============================
   CLEAR MEAL = BRAND BUTTON STYLE
=============================== */
.btn-clear {
    padding: 8px 22px;
    border-radius: 22px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 800;
    cursor: pointer;
    color: var(--primary);
}

/* Dark mode */
body.dark .btn-clear {
    background: transparent;
    border: 2px solid var(--secondary);
    color: var(--secondary);
}

body.dark .btn-clear:hover {
    background: var(--secondary);
    color: #000;
}





/* =========================
   Horizontal qty controls
========================= */
.qty-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.qty-controls .qty-btn,
.qty-controls .meal-remove {
    flex-shrink: 0;
}


/* =========================
   MOBILE TOTALS – SINGLE COLUMN
   (VERTICAL STACK, NO SWIPE)
========================= */

@media (max-width: 600px) {

  /* Totals in one column */
  .stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Each stat full width */
  .stat-box {
    width: 100%;
    padding: 8px 12px;
    white-space: normal;
  }

  /* Label + value never cut */
  .stat-box span,
  .stat-box b {
    max-width: 100%;
    white-space: nowrap;
  }
}


/* =========================
   MOBILE – SHOW UNITS WITH VALUES
   (CSS ONLY, SAFE)
========================= */

@media (max-width: 600px) {

  /* Calories */
  .stats-grid .stat-box:nth-child(1) b::after {
    content: " kcal";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }

  /* Protein */
  .stats-grid .stat-box:nth-child(2) b::after {
    content: " g";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }

  /* Carbs */
  .stats-grid .stat-box:nth-child(3) b::after {
    content: " g";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }

  /* Fat */
  .stats-grid .stat-box:nth-child(4) b::after {
    content: " g";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }

  /* Sugar */
  .stats-grid .stat-box:nth-child(5) b::after {
    content: " g";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }

  /* Sodium */
  .stats-grid .stat-box:nth-child(6) b::after {
    content: " mg";
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
  }
}


/* =========================
   MOBILE – FIX TOGGLE GAP
========================= */

@media (max-width: 600px) {

  /* Light / Dark toggle spacing */
  .theme-switcher {
    margin-bottom: 12px;
  }

}
