:root {
    --bg-body: #F3F6F9;
    --bg-card: #FFFFFF;
    --primary-dark: #003366; /* Deep Navy */
    --primary-blue: #0F4C75; /* Medical Blue */
    --accent-blue: #3282B8;
    --text-main: #1A202C;
    --text-sub: #718096;
    --border: #E2E8F0;
    --input-bg: #F7FAFC;
    --danger: #E53E3E;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* --- HEADER --- */
header {
    background: var(--bg-card);
    padding: 15px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-main);
    font-weight: 800;
    font-size: 1.25rem;
}

.brand-icon {
    background: var(--primary-blue);
    color: white;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 1.2rem;
}

.beta-tag {
    background: #cd2525;
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* --- LAYOUT GRID --- */
.app-container {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 30px;
    display: grid;
    grid-template-columns: 1fr 1.2fr; /* Ingredients Left, Stats Right */
    gap: 25px;
}

@media(max-width: 1000px) {
    .app-container { grid-template-columns: 1fr; }
}

/* --- CARDS --- */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    padding: 25px;
    margin-bottom: 25px;
}

h3 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 20px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- INPUTS & FORMS --- */
.search-box {
    position: relative;
    margin-bottom: 20px;
}
.search-box input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--bg-card);
    box-sizing: border-box;
	cursor: pointer;
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-sub);
    font-size: 1.1rem;
}

/* --- BUTTON GROUP (Lye Selector) --- */
.btn-group {
    display: flex;
    width: 100%;
}

.btn-group button {
    flex: 1; /* Split width 50/50 */
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text-sub);
    transition: all 0.2s ease;
}

/* Round the outer corners only */
.btn-group button:first-child {
    border-radius: 6px 0 0 6px;
}
.btn-group button:last-child {
    border-radius: 0 6px 6px 0;
    margin-left: -1px; /* Pull back to overlap middle border */
}

/* Active State (The Blue Button) */
.btn-group button.active {
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
    z-index: 1; /* Bring to front so border sits on top of neighbor */
    font-weight: 600;
}

/* Ingredients List */
.ingredient-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    background: white;
}
.ing-info { flex-grow: 1; }
.ing-name { font-weight: 600; font-size: 0.95rem; display: block; }
.ing-sub { font-size: 0.75rem; color: var(--text-sub); }

.ing-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}
.mini-input-group {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
}
.mini-input {
    width: 50px;
    border: none;
    background: transparent;
    text-align: right;
    font-weight: 600;
    font-size: 0.9rem;
    outline: none;
}
.unit-label { font-size: 0.8rem; color: var(--text-sub); margin-left: 4px; }

.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-sub);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
}
.btn-delete:hover { color: var(--danger); background: #FFF5F5; }

/* Configuration Grid */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-sub);
    text-transform: uppercase;
    margin-bottom: 8px;
}
.select-input, .text-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    font-size: 0.9rem;
    box-sizing: border-box;
}

/* --- RESULTS SECTION (RIGHT COLUMN) --- */

/* The Blue Totals Card */
.total-card {
    background-color: var(--primary-blue);
    color: white;
    border-radius: 12px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 220px;
    position: relative;
}
.total-header { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 10px; margin-bottom: 25px;}

.total-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.stat-block { margin-bottom: 10px; }
.stat-label { font-size: 0.75rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; display: block; margin-bottom: 4px;}
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-unit { font-size: 0.9rem; font-weight: 400; opacity: 0.8; }

.grand-total {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.big-total { font-size: 2.5rem; font-weight: 800; }

/* Analysis Grid (Chart + Values) */
.analysis-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 25px;
}

/* Qualities List */
.quality-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.quality-row:last-child { border-bottom: none; }
.q-name { color: var(--text-sub); }
.q-range { font-size: 0.75rem; color: #CBD5E0; margin-right: 8px; }
.q-val { font-weight: 700; color: var(--primary-blue); }

/* Fatty Acid Tags */
.acid-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.acid-tag {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    text-align: center;
    min-width: 50px;
}
.acid-name { font-size: 0.65rem; font-weight: 700; color: var(--text-sub); display: block; margin-bottom: 2px;}
.acid-val { font-size: 0.9rem; font-weight: 700; color: var(--text-main); }


/* --- MODAL (POPUP) --- */


.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal-card {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-close {
    background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-sub);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-primary:hover {
    background-color: var(--primary-dark); /* Darker blue on hover */
}

.btn-primary:active {
    transform: translateY(1px); /* Slight click effect */
}

.tab-group {
    display: flex;
    margin-bottom: 20px;
    background: var(--input-bg);
    padding: 4px;
    border-radius: 8px;
}
.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-sub);
    cursor: pointer;
}
.tab-btn.active { background: white; color: var(--primary-blue); shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* Utility for the magic wand button */
.btn-icon-only {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 36px;
    height: 36px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--primary-blue);
    transition: all 0.2s;
}
.btn-icon-only:hover { border-color: var(--primary-blue); background: #EBF8FF; }


/* --- CUSTOM DROPDOWN --- */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    max-height: 250px;
    overflow-y: auto;
    z-index: 50; /* floats above everything */
    display: none; /* Hidden by default */
    margin-top: 8px;
}

.autocomplete-dropdown.show {
    display: block;
}

.dropdown-item {
    padding: 12px 15px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--input-bg);
    color: var(--primary-blue);
    font-weight: 600;
}

/* --- SAP BADGE (Trust Indicator) --- */
.sap-badge {
    background: #E2E8F0;
    color: #4A5568;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace; /* Monospace font looks more "sciency" */
    letter-spacing: -0.5px;
}