/* css/style.css */

:root {
	--base-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --primary-color: #2563eb;    
    --primary-hover: #1d4ed8;
    --bg-color: #f3f4f6; 
	--header-color: #cccccc;        
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --highlight-bg: #f8fafc;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --log-column-border: 0px solid var(--border-color);
	/* Meal Colors */
	--breakfast-color: #ffe4d3;
	--morning-color: #f1e1b3;
	--lunch-color: #ddf6de;
	--afternoon-color: #bce3f7;
	--dinner-color: #ebdcf0;
	--evening-color: #d7def2; 
	--anytime-color: #e8e8e8;
}

/* Ensures Twemoji images scale perfectly with surrounding text */
img.emoji {
	height: 1.0em;
	width: 1.0em;
	margin: 0 .05em 0 .1em;
	vertical-align: -0.1em;
}       

* { box-sizing: border-box; margin: 0; padding: 0; }

.hidden {
	display: none;
}

.blank {
	visibility: hidden;
}

#logo {
	height: 45px;
	padding-right: 10px;
	vertical-align: text-bottom;
}

body {
    font-family: var(--base-font);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 14px;
}
.fatsecret-badge, #fatsecret-badge {
    text-align: center;
    padding: 10px 0;
    width: 100%;
}

.fatsecret-badge img, #fatsecret-badge img {
    max-width: 160px;
    height: auto;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.fatsecret-badge img:hover, #fatsecret-badge img:hover {
    opacity: 1;
}

a { text-decoration: none; color: var(--primary-color); }
a:hover { text-decoration: none; }

/* --- 1. Sticky Header --- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--bg-color);
    padding: 1rem 1rem 0 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.header-top h1 { font-size: 1.5rem; font-weight: 700; }
.index-links { display: flex; gap: 1.5rem; font-weight: 500; }

/* --- 2. Action Bar --- */
.bulk-action-bar {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--border-radius);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.bulk-group { display: flex; align-items: center; gap: 0.75rem; }

.action-btn {
    background: none; border: none; font-size: 0.875rem; font-weight: 500;
    cursor: pointer; color: var(--text-main); padding: 0.25rem 0.5rem;
    border-radius: 4px; transition: background 0.2s;
}

.action-btn:hover:not(:disabled) { background-color: rgba(0,0,0,0.05); }
.action-btn.danger { color: var(--danger-color); }
.action-btn.blue { color: var(--primary-color); }
.text-muted { color: var(--text-muted); }
.divider { color: #93c5fd; }

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent !important;
}

.mobile-menu-btn {
	display: none;
}

/* --- 3. Form --- */
.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.logging-form { padding: 1rem; }
.radio-toggle { margin-bottom: 0.75rem; display: flex; gap: 1.5rem; font-weight: 500; }
.radio-toggle label { cursor: pointer; display: flex; align-items: center; gap: 0.25rem; }

.form-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: stretch; }
.search-group { flex: 3 1 250px; }
.amount-group { flex: 1 1 100px; }
.category-group { flex: 1.5 1 150px; }
.date-group { flex: 1 1 120px; }
.submit-group { flex: 1 1 125px; max-width: 125px; min-width: 125px; }

input[type="text"], input[type="number"], select {
    width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border-color);
    border-radius: 6px; font-size: 0.9rem; font-family: inherit; background-color: #f9fafb;
    box-sizing: border-box;
}

input[type="text"]:focus, input[type="number"]:focus, select:focus {
    outline: none; border-color: var(--primary-color); background-color: #fff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Hide native number spinner arrows for a clean look */
input[type="number"]::-webkit-inner-spin-button, 
input[type="number"]::-webkit-outer-spin-button { 
    -webkit-appearance: none; margin: 0; 
}
input[type="number"] { -moz-appearance: textfield; }

.button, .date-btn {
    width: 100%; padding: 0.6rem 0.75rem; border-radius: 6px; font-size: 0.9rem;
    font-weight: 600; cursor: pointer; border: 1px solid var(--border-color);
    background-color: #fff; color: var(--text-main); display: flex;
    align-items: center; justify-content: center; gap: 0.5rem;
}

.primary-btn {
    background-color: var(--primary-color); color: white;
    border-color: var(--primary-color); transition: background 0.2s;
}
.primary-btn:hover { background-color: var(--primary-hover); }

/* --- 4. Table Layouts --- */
.log-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem 1rem;
}

.table-container { overflow-x: auto; }

th, td {
    padding: 0.50rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-main);
	white-space: nowrap;
    background-color: #f9fafb;
}

/* Strict Column Math to ensure top and bottom tables align perfectly */
.col-labels th { background-color: var(--header-color); font-weight: 700; font-size: 12px; }
th.col-food, td.col-food { text-align: left; }
th.col-amount, td.col-amount { text-align: left; color: var(--text-main); }
th.col-num, td.col-num { text-align: right; }

.daily-total-row { background-color: var(--header-color); font-weight: 700; font-size: 14px; }
.meal-header-row { background-color: #f9fafb; font-weight: 600; cursor: pointer; user-select: none; }
.meal-header-row:hover { background-color: #f1f5f9; }
.food-row { transition: background 0.2s; }
.food-row:hover { background-color: var(--highlight-bg); }

/* Color-coded Meal Headers: Time-of-Day Sky Theme */
tr.meal-header-row[data-cat="Breakfast"] { background-color: var(--breakfast-color); }
tr.meal-header-row[data-cat="Morning snack"] { background-color: var(--morning-color); }
tr.meal-header-row[data-cat="Lunch"] { background-color: var(--lunch-color); }
tr.meal-header-row[data-cat="Afternoon snack"] { background-color: var(--afternoon-color); }
tr.meal-header-row[data-cat="Dinner"] { background-color: var(--dinner-color); }
tr.meal-header-row[data-cat="Evening snack"] { background-color: var(--evening-color); }
tr.meal-header-row[data-cat="Anytime"] { background-color: var(--anytime-color); }

/* Ensures the header text remains readable against the background */
.meal-header-row { font-weight: bold; }

/* --- Drag & Drop Visuals --- */
.food-row[draggable="true"] { cursor: grab; }
.food-row.dragging { opacity: 0.5; background: #e0f2fe; }
.meal-tbody.drag-over .meal-header-row { background-color: #dbeafe; outline: 2px dashed var(--primary-color); }
.meal-tbody.drag-over { background-color: rgba(37, 99, 235, 0.02); }
.meal-tbody.collapsed-meal .food-row { display: none; }

/* --- 5. Modals --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5); z-index: 200;
    display: flex; justify-content: center; align-items: center;
}

.calendar-popup { background: var(--card-bg); padding: 1.5rem; border-radius: var(--border-radius); box-shadow: var(--shadow-lg); width: 320px; }
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; font-weight: 600; }
.cal-days-header, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; }
.cal-days-header span { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; padding-bottom: 0.5rem; }
.cal-day-btn { background: none; border: none; padding: 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.875rem; }
.cal-day-btn:hover:not(.empty) { background-color: var(--highlight-bg); }
.cal-day-btn.empty { cursor: default; }
.cal-day-btn.current-today { color: var(--primary-color); font-weight: 700; background-color: #eff6ff; }
.cal-day-btn.selected-target { border: 2px solid var(--text-muted); font-weight: 600; }
.cal-footer { margin-top: 1rem; text-align: center; }

/* ====================================================
   EXTRACTED UI UTILITIES, LAYOUTS, AND SMART DROPDOWNS
   ==================================================== */

/* SPACING & UTILITIES */
.w-full { width: 100%; box-sizing: border-box; }
.mt-0 { margin-top: 0; }
.mb-1 { margin-bottom: 1rem; }
.mb-1-5 { margin-bottom: 1.5rem; }
.mb-075 { margin-bottom: 0.75rem; }
.p-10 { padding: 10px; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* FLEX & GRID LAYOUTS */
.btn-group { display: flex; gap: 0.5rem; }
.input-col { display: flex; flex-direction: column; }
.flex-2-input { flex: 2; min-width: 150px; }
.flex-1-input { flex: 1; min-width: 80px; }
.manual-macro-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; margin-bottom: 1.5rem; }

/* MAIN LOGGING BAR (Flex Ratio Layout) */
.top-logging-row { display: flex; gap: 10px; align-items: center; width: 100%; }
.search-group { flex: 3; min-width: 200px; }
.amount-group { flex: 1.5; min-width: 120px; }
.category-group { flex: 1.5; min-width: 140px; }
.date-group { flex: 1.2; min-width: 120px; }
.submit-group { flex: 1.2; min-width: 120px; }

/* MAIN DASHBOARD TABLES */
.table-header-card { margin-top: 1rem; padding: 0; }
.table-body-card { border-top-left-radius: 0; border-top-right-radius: 0; border-top: none; }
.data-table { width: 100%; min-width: 800px; table-layout: fixed; border-collapse: collapse; }

/* Log Table Vertical Column Borders */
.data-table th:not(:last-child),
.data-table td:not(:last-child) { border-right: var(--log-column-border); }

/* COLUMN WIDTHS */
.col-34 { width: 34%; }
.col-15 { width: 15%; }
.col-8-5 { width: 8.5%; }
.col-28 { width: 28%; }
.col-14 { width: 14%; }
.col-7 { width: 7%; }

/* Checkboxes */
.table-header-card input[type="checkbox"] {
    transform: scale(1.2) !important;
    margin-right: 8px !important;
    margin-left: 2px !important;
    vertical-align: middle;
}
#nutrition-table input[type="checkbox"] {
    transform: scale(1.1) !important;
    margin-right: 8px !important;
    margin-left: 2px !important;
    vertical-align: middle !important;
}
.mgr-bulk-checkbox {
    transform: scale(1.2) !important;
    margin-right: 6px !important;
    margin-left: 2px !important;
    vertical-align: middle !important;
}

/* MODALS & RECIPE BUILDER */
#history-modal .modal-wide { width: 500px; }
#history-results-container {
    max-height: 50vh; /* Caps the results list at exactly 50% of the desktop monitor height */
}
.modal-wide { width: 850px; max-width: 95vw; }
.macro-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.recipe-builder-box { margin-bottom: 1.5rem; border: 1px solid var(--border-color); border-radius: 6px; overflow: visible; background: #fff; }
.recipe-input-strip { padding: 0.75rem; background: #f9fafb; border-bottom: 1px solid var(--border-color); display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.input-w-150 { flex: 1 1 calc(65% - 0.5rem); min-width: 200px; }
.input-w-65 { flex: 1 1 85px; min-width: 85px; }
.input-w-55 { flex: 1 1 80px; min-width: 80px; }
.btn-add-recipe { flex: 1 1 100%; padding: 0.6rem 1rem; margin-top: 0.25rem; }

/* RECIPE BUILDER TABLE */
.recipe-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 0.85rem; }
.recipe-thead { background-color: var(--header-color); }
.recipe-th { padding: 8px; color: var(--text-main); font-weight: 700; }
.recipe-tfoot { background-color: var(--header-color); font-weight: 700; border-top: 2px solid var(--border-color); }
.recipe-item-row { border-bottom: 1px solid var(--border-color); }
.recipe-cell { padding: 8px; }
.recipe-cell-muted { padding: 8px; color: var(--text-muted); overflow: visible !important; position: relative; }
.recipe-cell-name { padding: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-remove-item { background: none; border: none; color: var(--danger-color); cursor: pointer; font-weight: bold; padding: 0; }

/* CUSTOM SMART DROPDOWN */
.smart-dropdown-wrapper { position: relative; display: flex; flex-direction: column; }
.smart-dropdown-recipe { flex: 1 1 calc(35% - 0.5rem); min-width: 120px; }
.smart-dropdown { position: absolute; top: calc(100% + 2px); left: 0; min-width: 100%; width: max-content; background: #fff; border: 1px solid var(--border-color); border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); max-height: 200px; overflow-y: auto; z-index: 10005 !important; display: none; margin: 0; padding: 0; list-style: none; }
.smart-dropdown li { padding: 8px 12px; cursor: pointer; font-size: 0.85rem; color: var(--text-main); border-bottom: 1px solid #f0f0f0; }
.smart-dropdown li:hover { background-color: var(--primary-color); color: #fff; }
.smart-dropdown li:last-child { border-bottom: none; }

/* ====================================================
   SLIDE-OUT CUSTOM MANAGER PANEL
   ==================================================== */
.panel-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 10000; }
.slide-panel { position: absolute; top: 0; right: -450px; width: 450px; max-width: 100vw; height: 100%; background: #fff; box-shadow: -4px 0 15px rgba(0,0,0,0.1); transition: right 0.3s ease; display: flex; flex-direction: column; }
.slide-panel.open { right: 0; }
.panel-header { padding: 15px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--header-color); }
.panel-body { padding: 20px; overflow-y: auto; flex: 1; }
.manager-item { border: 1px solid var(--border-color); border-radius: 6px; padding: 12px; margin-bottom: 12px; background: #fff; }
.manager-item-header { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; color: var(--text-main); }
.manager-item-macros { font-size: 0.8rem; color: var(--text-muted); display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; margin-bottom: 10px; background: #f9fafb; padding: 8px; border-radius: 4px; }
.manager-item-actions { display: flex; gap: 5px; justify-content: flex-end; }

/* ====================================================
   SLIDE-OUT MANAGER CONTROLS (SEARCH & CHIPS)
   ==================================================== */
.panel-controls { padding: 15px 20px 0 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; background: #fff; }
#manager-search { width: 100%; box-sizing: border-box; padding: 8px 10px; margin-bottom: 10px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 0.9rem; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: #f0f0f0; border: 1px solid #ddd; padding: 5px 12px; border-radius: 20px; font-size: 0.75rem; cursor: pointer; color: var(--text-muted); transition: all 0.2s ease; font-weight: 500; }
.chip:hover { background: #e0e0e0; }
.chip.active { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
/* Enlarge emojis inside Food Manager filter chips */
.filter-chips .chip img.emoji { height: 15px; width: 15px; vertical-align: -3px; }

/* Custom Manager Checkbox Alignment */
.manager-item-title-group { display: flex; align-items: center; gap: 8px; }
.mgr-bulk-checkbox { cursor: pointer; transform: scale(1.1); margin: 0; }
/* Enlarge food category icon of manager cards */
.manager-item-header img.emoji { height: 15px; width: 15px; vertical-align: middle; }


/* CLEAR SEARCH BUTTONS */
.search-input-wrapper { position: relative; width: 100%; display: flex; align-items: center; }
.search-input-wrapper input { width: 100%; padding-right: 30px; }
.btn-clear-search { position: absolute; right: 8px; background: none; border: none; font-size: 12px; cursor: pointer; color: var(--text-muted); padding: 4px; z-index: 10; }
.btn-clear-search:hover { color: var(--danger-color); }

/* HISTORY MODAL */
.history-row { cursor: pointer; transition: background 0.2s; }
.history-row:hover { background: #f0f8ff; }

/* QUICK DATE NAV BUTTONS */
.btn-date-nav {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-date-nav:hover { background: var(--border-color); }

/* MEAL ITEM COUNT */
.meal-item-count {
    margin-left: 4px;
    font-size: 0.9em;
	vertical-align: text-top;
}
.meal-item-count.active {
    color: var(--danger-color, red);
}
.meal-item-count.empty {
    color: var(--text-muted, grey);
}

/* --- Floating Macro Dashboard --- */
#macro-widget-container { margin-left: auto; } /* Pushes the widget to the right edge */

#macro-popup {
    display: none;
    position: absolute;
    top: 34px; 
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    background: #ffffff;
    border: 1px solid #cccccc;
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    z-index: 10001; 
    color: #333333;
}

#macro-popup.open {
    display: block;
}

#macro-close {
    position: absolute;
    top: 0px;
    right: -25px;
    background: transparent;
    border: none;
    box-shadow: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
}

.macro-header {
    background: #2d3d4d;
    padding: 3px;
    text-align: center;
	font-family: inherit;
	font-size: 140%;
    font-weight: bold;
	color: #ffffcc;
    border-bottom: 1px solid #cccccc;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.macro-body {
	height: auto;
    padding: 14px 12px;
    line-height: 1.8;
    font-size: 15px;
	background: #ffffff;
}

/* Global fix to strip the border off the New/Copy button completely */
#btn-new-custom, 
#btn-new-custom.btn-duplicate-mode {
    border: 1px solid var(--primary-color);
}

/* ====================================================
   TABLET OPTIMIZATIONS (769px to 1024px)
   ==================================================== */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    /* 1. Header & Title Realignment (Center top, stacked) */
    .header-top {
        flex-direction: column !important;
        gap: 15px;
    }
    .header-top h1 {
        text-align: center;
    }
    .index-links {
        justify-content: center;
        width: 100%;
        flex-wrap: wrap;
    }

    /* 2. Logging Form - Proportional 3-Column Grid for perfect edge alignment */
    .top-logging-row {
        display: grid !important;
        grid-template-columns: 1fr 1.4fr 1fr !important; /* Col 1 & 3 are equal. Date gets a bit more room */
        gap: 10px !important;
        width: 100% !important;
    }
    
    /* Map elements to specific grid lanes to force alignment */
    .search-group { grid-column: 1 / 3 !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
    .amount-group { grid-column: 3 / 4 !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
    .category-group { grid-column: 1 / 2 !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
    .date-group { grid-column: 2 / 3 !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
    .submit-group { grid-column: 3 / 4 !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }

    /* 3. Sync Table Scroll & Shrink to Fit Viewport natively */
    .table-header-container, .table-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table {
        min-width: 700px !important; /* Allows table to fit naturally on 768px screens without clipping */
    }
    
    th, td {
        padding: 0.5rem 0.5rem !important; /* Compress padding slightly to ensure everything fits */
    }

    /* 4. Prevent Action Bar Buttons from squishing */
    .bulk-action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .bulk-group {
        flex-wrap: wrap;
        justify-content: space-between;
        width: 100%;
        gap: 8px;
    }
    
    .action-btn {
        flex: 1 1 auto;
        text-align: center;
        white-space: nowrap;
    }
}
