/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #10b981;
    --primary-dark:  #059669;
    --primary-light: #d1fae5;
    --primary-dim:   #ecfdf5;
    --surface:       #ffffff;
    --bg:            #f1f5f9;
    --border:        #e2e8f0;
    --text:          #0f172a;
    --text-muted:    #64748b;
    --danger:        #ef4444;
    --danger-light:  #fee2e2;
    --warning:       #f59e0b;
    --info:          #3b82f6;
    --radius:        14px;
    --radius-sm:     8px;
    --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:     0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
    --transition:    .18s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

/* ===== HEADER ===== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -.3px;
}

.logo-icon { width: 28px; height: 28px; color: var(--primary); }

/* ===== TABS NAV ===== */
.tab-nav {
    display: flex;
    gap: .25rem;
    background: var(--bg);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.tab-btn:hover { background: var(--surface); color: var(--text); }
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); font-weight: 600; }

.cart-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--primary);
    color: white;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
}

/* ===== LAYOUT ===== */
main { padding: 1.75rem 0 3rem; }

.container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ===== TAB PANES ===== */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== PANELS ===== */
.panel {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: visible;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .875rem 1.25rem;
    font-weight: 600;
    font-size: .875rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    gap: .5rem;
}

.panel-subtitle {
    font-weight: 400;
    color: var(--text-muted);
    font-size: .8rem;
}

.text-btn {
    border: none;
    background: none;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    padding: .3rem .6rem;
    border-radius: 5px;
    transition: var(--transition);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: .3rem;
    white-space: nowrap;
}
.text-btn:hover { background: var(--bg); color: var(--text); }
.text-btn.danger { color: var(--danger); }
.text-btn.danger:hover { background: var(--danger-light); }
.text-btn.primary { color: var(--primary); }
.text-btn.primary:hover { background: var(--primary-dim); color: var(--primary-dark); }

/* ===== CALCULATOR GRID ===== */
.calc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.panel-full { grid-column: 1 / -1; }

@media (max-width: 680px) {
    .calc-grid { grid-template-columns: 1fr; }
    .panel-full { grid-column: auto; }
}

/* ===== SEARCH BOX ===== */
.search-box {
    position: relative;
    padding: 1rem 1.25rem;
}
.search-box.compact { padding: 0; }

.search-icon {
    position: absolute;
    left: 2.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-box.compact .search-icon { left: .875rem; }

.search-box input {
    width: 100%;
    padding: .65rem 1rem .65rem 2.5rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.search-box input:focus { border-color: var(--primary); background: var(--surface); }

.hint-text {
    padding: 0 1.25rem 1rem;
    font-size: .8rem;
    color: var(--text-muted);
}

/* ===== DROPDOWN ===== */
.dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 1.25rem;
    right: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 300;
    max-height: 280px;
    overflow-y: auto;
}
.search-box.compact .dropdown { left: 0; right: 0; }
.dropdown.hidden { display: none; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1rem;
    cursor: pointer;
    transition: background var(--transition);
}
.dropdown-item:hover { background: var(--primary-dim); }
.dropdown-item:not(:last-child) { border-bottom: 1px solid var(--bg); }

.dropdown-name { font-size: .875rem; font-weight: 500; }
.dropdown-brand { font-size: .78rem; color: var(--text-muted); }

.dropdown-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: .875rem;
}

/* ===== CART LIST ===== */
.cart-list {
    padding: .75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    min-height: 80px;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    transition: border-color var(--transition);
}
.cart-item:hover { border-color: var(--primary); }

.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: .875rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cart-controls {
    display: flex;
    align-items: center;
    gap: .375rem;
    flex-shrink: 0;
}

.qty-btn {
    width: 26px;
    height: 26px;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-muted);
    padding-bottom: 1px;
}
.qty-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-dim); }

.qty-value { min-width: 26px; text-align: center; font-size: .875rem; font-weight: 600; }
.qty-label { font-size: .75rem; color: var(--text-muted); }

.remove-btn {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: var(--transition);
    margin-left: .2rem;
}
.remove-btn:hover { background: var(--danger-light); color: var(--danger); }

/* ===== TOTALS GRID ===== */
.totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: .875rem;
    padding: 1rem 1.25rem;
}

.nutrient-tile {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .875rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    transition: border-color var(--transition);
}
.nutrient-tile:hover { border-color: var(--primary); }

.nutrient-tile-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.nutrient-tile-name { font-size: .8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.nutrient-tile-amount { font-size: 1.1rem; font-weight: 700; color: var(--text); white-space: nowrap; }

.nutrient-tile-bar-wrap { height: 5px; background: var(--border); border-radius: 999px; overflow: hidden; }
.nutrient-tile-bar { height: 100%; border-radius: 999px; transition: width .4s ease; }

.bar-low  { background: #94a3b8; }
.bar-ok   { background: var(--primary); }
.bar-high { background: var(--warning); }
.bar-over { background: var(--danger); }

.nutrient-tile-nrv { font-size: .75rem; color: var(--text-muted); display: flex; justify-content: space-between; }
.nrv-pct { font-weight: 600; }
.nrv-pct.ok   { color: var(--primary); }
.nrv-pct.high { color: var(--warning); }
.nrv-pct.over { color: var(--danger); }
.no-nrv-note { font-size: .75rem; color: var(--text-muted); font-style: italic; }

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    color: var(--text-muted);
    font-size: .875rem;
    padding: 1.5rem;
    text-align: center;
    grid-column: 1 / -1;
}
.empty-state svg { opacity: .3; }

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.filter-item { display: flex; flex-direction: column; gap: .35rem; flex: 1; min-width: 150px; }
.filter-item label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.filter-item select,
.filter-item input {
    padding: .6rem .875rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .875rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
    width: 100%;
}
.filter-item select:focus,
.filter-item input:focus { border-color: var(--primary); background: var(--surface); }

.filter-search { flex: 1.5; }
.filter-dir { max-width: 180px; }

.results-info { font-size: .83rem; color: var(--text-muted); margin-bottom: .75rem; padding-left: .25rem; }

/* ===== CATALOG GRID ===== */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.25rem; }

/* ===== PRODUCT CARD ===== */
.product-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.product-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }

.product-img-wrap {
    width: 100%;
    height: 155px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.product-img-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }

.product-card-body { padding: 1rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.product-card-name { font-weight: 700; font-size: .95rem; color: var(--text); line-height: 1.3; }
.product-card-divider { border: none; border-top: 1px solid var(--border); margin: .25rem 0; }

.nutrient-list { display: flex; flex-direction: column; gap: .325rem; }
.nutrient-row-chip { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; padding: .3rem .5rem; background: var(--bg); border-radius: 5px; }
.chip-name { color: var(--text-muted); }
.chip-value { font-weight: 700; color: var(--primary-dark); }

.add-btn { margin-top: auto; padding-top: .375rem; }
.add-btn button {
    width: 100%;
    padding: .6rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.add-btn button:hover { background: var(--primary-dark); }
.add-btn button.added { background: var(--info); }

/* ===== CALENDAR ===== */
.cal-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 900px) {
    .cal-layout { grid-template-columns: 1fr; }
}

.cal-panel { overflow: hidden; }
.cal-detail-panel { position: sticky; top: 78px; }

/* calendar header nav */
.cal-nav-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transition: var(--transition);
    flex-shrink: 0;
}
.cal-nav-btn:hover:not(:disabled) { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }
.cal-nav-btn:disabled { opacity: .3; cursor: default; }

#cal-month-title { font-weight: 600; font-size: .95rem; }

/* weekday header */
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: .625rem .875rem .25rem;
    gap: .25rem;
}
.cal-weekdays > div {
    text-align: center;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    padding: .25rem 0;
}
.cal-weekdays > div.weekend { color: var(--primary); }

/* day grid */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: .25rem;
    padding: .25rem .875rem .875rem;
}

.day-cell {
    aspect-ratio: 1;
    border: 1.5px solid transparent;
    border-radius: 8px;
    padding: .2rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: var(--transition);
    min-height: 46px;
    max-height: 64px;
}
.day-cell:hover:not(.disabled) { background: var(--primary-dim); border-color: var(--primary); }
.day-cell.today { background: var(--primary-light); border-color: var(--primary) !important; }
.day-cell.selected { background: var(--primary); border-color: var(--primary-dark) !important; }
.day-cell.disabled { opacity: .25; cursor: default; pointer-events: none; }
.day-cell.other-month { opacity: .2; pointer-events: none; }

.day-num {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
    margin-top: 2px;
}
.day-cell.selected .day-num { color: white; }
.day-cell.today:not(.selected) .day-num { color: var(--primary-dark); }

.day-dots {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
}
.day-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}
.day-cell.selected .day-dot { filter: brightness(2); }

/* calendar legend */
.cal-legend {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .875rem .75rem;
    font-size: .75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}
.legend-today {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--primary-light);
    border: 1.5px solid var(--primary);
}
.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: .5rem;
}

/* day detail */
.day-detail-content {
    padding: .875rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .625rem;
}

.detail-log-list { display: flex; flex-direction: column; gap: .5rem; }

.log-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .55rem .75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}
.log-item:hover { border-color: var(--primary); }
.log-item-info { flex: 1; min-width: 0; }
.log-item-name { font-size: .82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-section-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    padding: .25rem 0 .125rem;
}

.detail-add-wrap { position: relative; }

.copy-cart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    width: 100%;
    padding: .6rem 1rem;
    background: var(--primary-dim);
    color: var(--primary-dark);
    border: 1.5px solid var(--primary-light);
    border-radius: var(--radius-sm);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.copy-cart-btn:hover { background: var(--primary-light); border-color: var(--primary); }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: .65rem 1.25rem;
    border-radius: 999px;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    transition: opacity .3s;
    white-space: nowrap;
}
.toast.hidden { display: none; }
.toast.fade-out { opacity: 0; }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

@media (max-width: 480px) {
    .filter-bar { flex-direction: column; }
    .filter-item, .filter-dir, .filter-search { min-width: 0; max-width: none; width: 100%; flex: auto; }
    .tab-btn { padding: .4rem .65rem; font-size: .8rem; gap: .25rem; }
    .tab-btn svg { display: none; }
}
