/* === Google Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600&family=Roboto:wght@400;500&display=swap');

/* Animated Gradient Background */
body {
    font-family: 'Roboto', Arial, sans-serif;
    background: var(--bg-gradient);
    background-size: 400% 400%;
    animation: gradientBG 8s infinite linear;
    color: var(--text-color);
    min-height: 100vh;
    margin: 0;
    transition: background 0.4s, color 0.4s;
}

/* Gradient Animation */
@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Root Variables */
:root {
    --primary: #00C9A7;
    --primary-dark: #000000;
    --secondary: #b63c3c;
    --accent: #b26ff1;
    --neutral: #F9F9F9;
    --text-color: #000000;
    --bg-gradient: linear-gradient(-45deg, #1f629a, #04384d, #73a2f5, #138df0);
    --card-bg: #ffffff;
    --shadow: 0 8px 16px rgba(0,0,0,0.1);
}

/* Main Container */
.container {
    background: var(--card-bg);
    padding: 32px 24px 24px 24px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    margin: 40px auto;
    animation: slideIn 0.7s ease-out;
    transition: background 0.4s, color 0.4s;
}

/* Slide-in Effect */
@keyframes slideIn {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Headings */
h2, h3 {
    font-family: 'Poppins', sans-serif;
    color: var(--primary);
    margin-bottom: 16px;
}

/* Input Field with Floating Label Effect */
/* --- Floating Label Fix --- */
.input-group {
    position: relative;
    margin-bottom: 20px;
}
.input-group input {
    width: 100%;
    padding: 20px 8px 20px 6px;
    border: 2px solid #d1d5db;
    border-radius: 16px;
    font-size: 1.08rem;
    background: #fff;
    color: var(--text-color);
    outline: none;
    transition: border 0.3s, box-shadow 0.3s, background 0.4s, color 0.4s;
    font-family: 'Roboto', Arial, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.input-group label {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    padding: 0 4px;
    font-size: 16px;
    color: #777;
    pointer-events: none;
    transition: 0.3s;
    z-index: 2;
    opacity: 0;
}
.input-group input:focus + label,
.input-group input:not(:placeholder-shown) + label {
    top: 0;
    left: 14px;
    font-size: 12px;
    color: var(--primary);
    background: var(--card-bg);
    opacity: 1;
    padding: 0 4px;
    z-index: 3;
}
.input-group input:placeholder-shown + label {
    opacity: 0;
}
.input-group input:not(:placeholder-shown) + label {
    opacity: 1;
}
.input-group input:focus + label {
    opacity: 1;
}

/* Hide label when placeholder is visible and not focused */
.input-group input:placeholder-shown + label {
    opacity: 0;
}

/* Ensure placeholder is visible and styled */
.input-group input::placeholder {
    color: #b0b0b0;
    opacity: 1;
    font-size: 1.08rem;
    font-family: 'Roboto', Arial, sans-serif;
}

/* --- End Floating Label Fix --- */

/* Button Styles */
.button-container {
    display: flex;
    justify-content: space-between;
    margin-top: 18px;
    gap: 10px;
}

button {
    font-family: 'Poppins', sans-serif;
    padding: 12px 0;
    width: 48%;
    font-size: 16px;
    cursor: pointer;
    border-radius: 16px;
    border: none;
    transition: all 0.3s cubic-bezier(.4,2,.6,1), box-shadow 0.3s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

/* Calculate BMI Button */
.calculate-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 600;
}
.calculate-btn:hover, .calculate-btn:focus {
    transform: scale(1.05);
    box-shadow: 0 4px 16px var(--primary, #00C9A7, 0.2);
}

/* Reset Button */
.reset-btn {
    background: linear-gradient(135deg, #ff7043, #e64a19);
    color: #fff;
    font-weight: 600;
}
.reset-btn:hover, .reset-btn:focus {
    transform: scale(1.05);
    box-shadow: 0 4px 16px #ff7043aa;
}

/* Result and Error Messages */
.result-card {
    background: var(--neutral);
    color: var(--text-color);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin: 18px 0 0 0;
    padding: 18px 12px;
    min-height: 60px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s;
    font-size: 1.1rem;
}
.result-card.show-result {
    opacity: 1;
    transform: translateY(0);
}

#message {
    margin-top: 12px;
    color: #ff3b3b;
    font-weight: 900;
    min-height: 40px;
    font-size: 1rem;
    transition: color 0.3s;
    text-align: center;
    letter-spacing: 0.5px;
    line-height: 1.2;
    font-family: 'Poppins', 'Arial', sans-serif;
}

/* BMI Chart Card */
.bmi-chart-card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin: 28px 0 0 0;
    padding: 1px 12px;
    transition: box-shadow 0.3s, background 0.4s;
    font-size: 1rem;
    outline: none;
}
.bmi-chart-card:hover, .bmi-chart-card:focus {
    box-shadow: 0 12px 32px rgba(0,201,167,0.18);
    background: var(--neutral);
}
.bmi-chart-card h3 {
    color: var(--primary-dark);
    margin-bottom: 10px;
    font-size: 1.1rem;
}
.bmi-chart-card table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.98rem;
}
.bmi-chart-card th, .bmi-chart-card td {
    padding: 6px 0;
    text-align: left;
}
.bmi-chart-card tr:nth-child(even) {
    background: #f3f3f3;
}

/* --- BMI Meter Styles --- */
.bmi-meter-card {
    background: var(--card-bg, #fff);
    border-radius: 16px;
    box-shadow: var(--shadow, 0 8px 16px rgba(0,0,0,0.1));
    margin: 8px 0 0 0;
    padding: 18px 12px 8px 12px;
    transition: box-shadow 0.3s, background 0.4s;
    font-size: 1rem;
    outline: none;
    text-align: center;
    min-height: unset;
}
.bmi-meter-card h3 {
    color: var(--primary-dark, #005F73);
    margin-bottom: 10px;
    font-size: 1.1rem;
}
.bmi-meter-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
#bmi-meter {
    display: block;
    margin: 0 auto;
}
#bmi-meter-value {
    font-weight: 700;
    font-size: 2em;
    dominant-baseline: middle;
}
.bmi-meter-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.95em;
    gap: 4px;
}
.bmi-meter-labels span {
    flex: 1;
    text-align: center;
    font-weight: 500;
}

/* Animations */
.fade-in {
    animation: fadeIn 1.2s;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.bmi-meter-card, .bmi-chart-card, .result-card, .input-group, .button-container {
    animation: fadeInUp 0.8s cubic-bezier(.4,2,.6,1) both;
}
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Smooth Scroll */
html {
    scroll-behavior: smooth;
}

/* Responsive Design */
@media (max-width: 600px) {
    .container {
        padding: 12px 2vw 18px 2vw;
        max-width: 100vw;
        margin: 10px auto;
        border-radius: 0 0 16px 16px;
    }
    .button-container {
        flex-direction: column;
        gap: 12px;
    }
    button {
        width: 100%;
        font-size: 1.1rem;
        border-radius: 14px;
    }
    .input-group input {
        font-size: 1rem;
        padding: 16px 8px 16px 8px;
    }
    .bmi-meter-card, .bmi-chart-card {
        margin: 12px 0 0 0;
        padding: 10px 2vw 10px 2vw;
        border-radius: 12px;
    }
    .bmi-meter-card h3, .bmi-chart-card h3 {
        font-size: 1rem;
    }
    #bmi-meter {
        width: 100px;
        height: 100px;
    }
    #bmi-meter-value {
        font-size: 1.2em;
    }
    .bmi-meter-labels {
        font-size: 0.85em;
        gap: 2px;
    }
    #message {
        font-size: 1.1rem;
        min-height: 28px;
    }
    h2 {
        font-size: 1.1rem;
    }
}

/* Accessibility: High Contrast Mode */
body.high-contrast {
    --card-bg: #000;
    --text-color: #FFD700;
    --bg-gradient: #000;
}

button:focus, input:focus, .bmi-chart-card:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Card and Input Corners Fix --- */
.container {
    border-radius: 16px;
}
/* --- End Card and Input Corners Fix --- */

/* Hide empty result/message containers */
#result:empty {
    display: none;
    margin: 0;
    padding: 0;
}
#message:empty {
    display: none;
    margin: 0;
    padding: 0;
}

/* Adjust result card margin */
.result-card {
    margin-bottom: 0;
}

/* Adjust BMI meter card margin */
.bmi-meter-card {
    margin-top: 8px;
}

button {
    font-family: 'Poppins', sans-serif;
    padding: 12px 0;
    width: 48%;
    font-size: 16px;
    cursor: pointer;
    border-radius: 16px;
    border: none;
    transition: all 0.3s cubic-bezier(.4,2,.6,1), box-shadow 0.3s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

button:focus, input:focus, .bmi-chart-card:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}