/* ============================================
   CSS Variables & Reset
   ============================================ */
:root {
    --color-primary: #667eea;
    --color-primary-dark: #764ba2;
    --color-secondary: #11998e;
    --color-secondary-light: #38ef7d;
    --color-accent: #ffc107;
    --color-accent-dark: #ffa000;
    --color-success: #4caf50;
    --color-success-dark: #2e7d32;
    --color-text: #333;
    --color-text-light: #666;
    --color-text-lighter: #999;
    --color-border: #e0e0e0;
    --color-bg-light: #f8f9fa;
    --color-bg-lighter: #f0f0f0;
    --color-white: #ffffff;
    --shadow-sm: 0 5px 15px rgba(102, 126, 234, 0.2);
    --shadow-md: 0 5px 20px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.3);
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 15px;
    --radius-xl: 20px;
    --transition: all 0.3s ease;
}


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}


/* ============================================
   Layout Components
   ============================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--color-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}


.header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
    padding: 30px;
    text-align: center;
}


.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}


.header p {
    font-size: 1.1em;
    opacity: 0.9;
}


.content {
    padding: 40px;
}


/* ============================================
   Form Elements
   ============================================ */
.input-section {
    background: var(--color-bg-light);
    padding: 30px;
    border-radius: var(--radius-lg);
    margin-bottom: 30px;
}


.section-title {
    margin-bottom: 25px;
    color: var(--color-text);
    font-size: 1.5em;
}


.section-description {
    margin-bottom: 20px;
    color: var(--color-text-light);
    font-size: 1.05em;
}


.input-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}


.input-group {
    margin-bottom: 25px;
}


.input-group label {
    display: block;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 10px;
    font-size: 1.1em;
}


.input-group input,
.input-group select {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1em;
    transition: var(--transition);
    font-family: inherit;
}


.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}


.radio-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}


.radio-option {
    display: flex;
    align-items: center;
    padding: 15px 25px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}


.radio-option:hover {
    border-color: var(--color-primary);
    background: #f0f2ff;
}


.radio-option input[type="radio"] {
    width: auto;
    margin-right: 10px;
    cursor: pointer;
}


/* ============================================
   Buttons
   ============================================ */
.btn {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
    border: none;
    padding: 18px 40px;
    font-size: 1.2em;
    border-radius: var(--radius-md);
    cursor: pointer;
    width: 100%;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}


.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}


.btn:active {
    transform: translateY(0);
}


.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}


.btn-secondary {
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-secondary-light) 100%);
    margin-top: 15px;
}


.copy-btn {
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-secondary-light) 100%);
    color: var(--color-white);
    border: none;
    padding: 12px 30px;
    font-size: 1em;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    margin-top: 20px;
    transition: transform 0.2s;
    font-family: inherit;
}


.copy-btn:hover {
    transform: translateY(-2px);
}


/* ============================================
   IBW Selection Cards
   ============================================ */
.ibw-selection-card {
    border: 3px solid var(--color-border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: var(--transition);
    background: var(--color-white);
}


.ibw-selection-card:hover {
    border-color: var(--color-primary);
    background: #f0f2ff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}


.ibw-selection-card.selected {
    border-color: var(--color-primary);
    background: #e8eeff;
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}


.ibw-method-name {
    font-weight: 700;
    font-size: 1.3em;
    color: var(--color-primary);
    margin-bottom: 8px;
}


.ibw-weight-value {
    font-size: 2em;
    font-weight: 800;
    color: var(--color-text);
    margin: 10px 0;
}


.ibw-description {
    color: var(--color-text-light);
    font-size: 0.9em;
    font-style: italic;
}


/* ============================================
   Results Section
   ============================================ */
.results {
    margin-top: 30px;
}


.results.hidden {
    display: none;
}


.results:not(.hidden) {
    animation: fadeIn 0.5s ease;
}


@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.results-title {
    margin-bottom: 25px;
    color: var(--color-text);
    font-size: 2em;
}


.result-card {
    background: var(--color-white);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 25px;
    margin-bottom: 20px;
    transition: var(--transition);
}


.result-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}


.result-card h3 {
    color: var(--color-primary);
    font-size: 1.5em;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--color-primary);
}


.result-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-bg-lighter);
}


.result-row:last-child {
    border-bottom: none;
}


.result-label {
    font-weight: 600;
    color: #555;
    flex: 1;
}


.result-value {
    color: var(--color-text);
    font-weight: 700;
    font-size: 1.1em;
    text-align: right;
}


.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
}


.info-box {
    background: #e8f4f8;
    border-left: 4px solid #2196F3;
    padding: 15px;
    border-radius: var(--radius-sm);
    margin: 20px 0;
}


.info-box p {
    color: #0277bd;
    line-height: 1.6;
}


.info-box p + p {
    margin-top: 10px;
}


.highlight {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 1.1em;
}


.highlight-green {
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-secondary-light) 100%);
    color: var(--color-white);
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 1.1em;
}


/* ============================================
   Filter Section
   ============================================ */
.filter-section {
    background: #fff9e6;
    border: 3px solid var(--color-accent);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 25px;
}


.filter-section h4 {
    color: #f57c00;
    margin-bottom: 10px;
    font-size: 1.3em;
}


.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 15px;
}


.filter-description {
    color: var(--color-text-light);
    font-size: 0.9em;
    margin-top: 5px;
}


.sort-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--color-white);
    padding: 10px 20px;
    border-radius: 25px;
    border: 2px solid var(--color-border);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}


.sort-toggle:hover {
    border-color: var(--color-primary);
    background: #f0f2ff;
}


.sort-toggle.active {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border-color: var(--color-primary);
    color: var(--color-white);
}


.sort-icon {
    font-size: 1.2em;
    font-weight: bold;
}


.filter-chips {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}


.filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 12px 20px;
    background: var(--color-white);
    border: 2px solid var(--color-border);
    border-radius: 25px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    user-select: none;
}


.filter-chip:hover {
    border-color: var(--color-accent);
    background: #fffbf0;
}


.filter-chip.active {
    background: linear-gradient(135deg, #ffd54f 0%, #ffb300 100%);
    border-color: var(--color-accent-dark);
    color: var(--color-white);
    box-shadow: 0 4px 12px rgba(255, 160, 0, 0.3);
}


.filter-chip input[type="checkbox"] {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}


/* ============================================
   Product Cards
   ============================================ */
.product-card {
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: var(--transition);
    background: var(--color-white);
}


.product-card:hover {
    border-color: var(--color-primary);
    background: #f0f2ff;
    transform: translateY(-2px);
}


.product-card.selected {
    border-color: var(--color-primary);
    background: #e8eeff;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}


.product-card.hidden {
    display: none;
}


.product-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
    gap: 15px;
}


.product-name {
    font-weight: 700;
    font-size: 1.3em;
    color: var(--color-text);
    flex: 1;
}


.product-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
}


.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    margin: 2px;
}


.badge-sodium {
    background: #e3f2fd;
    color: #1565c0;
}


.badge-fluid {
    background: #f3e5f5;
    color: #6a1b9a;
}


.badge-protein-high {
    background: #e8f5e9;
    color: #2e7d32;
}


.badge-protein-low {
    background: #fff3e0;
    color: #e65100;
}


.product-feature {
    font-size: 0.95em;
    color: var(--color-text-light);
    font-style: italic;
    margin-bottom: 15px;
    line-height: 1.5;
}


.product-specs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 15px;
    font-size: 0.9em;
}


.spec-item {
    background: var(--color-bg-light);
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}


.spec-label {
    font-weight: 600;
    color: var(--color-primary);
    display: block;
    margin-bottom: 5px;
}


.spec-value {
    color: var(--color-text);
    font-weight: 700;
    font-size: 1.1em;
}


.no-products {
    text-align: center;
    padding: 40px;
    color: var(--color-text-lighter);
    font-size: 1.1em;
}


/* ============================================
   Dilution Controls
   ============================================ */
.dilution-control-section {
    background: #e8f5e9;
    border: 3px solid var(--color-success);
    border-radius: 12px;
    padding: 25px;
    margin-top: 20px;
}


.dilution-control-section h4 {
    color: var(--color-success-dark);
    margin-bottom: 20px;
    font-size: 1.3em;
}


.dilution-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}


.dilution-card {
    background: var(--color-white);
    border: 3px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}


.dilution-card:hover {
    border-color: var(--color-success);
    background: #f1f8f4;
}


.dilution-card.selected {
    border-color: var(--color-success);
    background: #e8f5e9;
    box-shadow: 0 3px 10px rgba(76, 175, 80, 0.3);
}


.dilution-card input[type="radio"] {
    display: none;
}


.dilution-title {
    font-weight: 700;
    font-size: 1.2em;
    color: var(--color-success-dark);
    margin-bottom: 10px;
}


.dilution-description {
    color: var(--color-text-light);
    font-size: 0.9em;
}


.rate-selector {
    margin-top: 20px;
}


.rate-selector label {
    display: block;
    font-weight: 600;
    color: var(--color-success-dark);
    margin-bottom: 10px;
    font-size: 1.1em;
}


.rate-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
}


.rate-btn {
    padding: 15px;
    background: var(--color-white);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1em;
    transition: var(--transition);
    text-align: center;
}


.rate-btn:hover {
    border-color: var(--color-success);
    background: #f1f8f4;
}


.rate-btn.selected {
    border-color: var(--color-success);
    background: var(--color-success);
    color: var(--color-white);
}


.dilution-preview {
    margin-top: 25px;
    padding: 20px;
    background: var(--color-white);
    border-radius: var(--radius-md);
    border: 2px solid var(--color-success);
}


/* ============================================
   Prescription
   ============================================ */
.prescription-template {
    background: var(--color-white);
    padding: 30px;
    border-radius: var(--radius-md);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.8;
    color: #000;
    white-space: pre-wrap;
    border: 2px solid var(--color-border);
    overflow-x: auto;
}


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


/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }


    .content {
        padding: 20px;
    }


    .header h1 {
        font-size: 1.8em;
    }


    .header p {
        font-size: 1em;
    }


    .radio-group {
        flex-direction: column;
    }


    .grid-2 {
        grid-template-columns: 1fr;
    }


    .filter-chips {
        flex-direction: column;
    }


    .filter-chip {
        width: 100%;
        justify-content: center;
    }


    .input-row {
        grid-template-columns: 1fr;
    }


    .product-header {
        flex-direction: column;
    }


    .product-badges {
        justify-content: flex-start;
    }
}


@media print {
    body {
        background: white;
        padding: 0;
    }


    .btn, .filter-section, .input-section {
        display: none;
    }


    .container {
        box-shadow: none;
    }
}