/* ===== Theme Variables ===== */
:root {
    /* Dark Theme (Default) */
    --bg-color: #252525;
    --bg-secondary: #1a1a1a;
    --card-bg: #414141;
    --text-color: #ffffff;
    --text-secondary: #b0b0b0;
    --accent-color: #af0404;
    --highlight-color: #ff0000;
    --success-color: #4caf50;
    --warning-color: #ff9800;
    --danger-color: #f44336;
    --info-color: #3498db;
    --glass-bg: rgba(65, 65, 65, 0.25);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-bg-focus: rgba(255, 255, 255, 0.1);
}

/* Light Theme */
[data-theme="light"] {
    --bg-color: #f5f5f5;
    --bg-secondary: #e8e8e8;
    --card-bg: #ffffff;
    --text-color: #1a1a1a;
    --text-secondary: #666666;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(0, 0, 0, 0.1);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    --input-bg: rgba(0, 0, 0, 0.03);
    --input-bg-focus: rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

/* ===== Header ===== */
header {
    text-align: center;
    margin-bottom: 10px;
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 5px;
}

header h1 {
    font-weight: 700;
    letter-spacing: 1px;
}

header p {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
    width: 44px;
    height: 44px;
    padding: 10px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: var(--accent-color);
    transform: rotate(15deg);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-color);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .moon-icon {
    display: none;
}

/* ===== Calculator Card ===== */
.calculator-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 25px;
    box-shadow: var(--shadow);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* ===== Segmented Unit Toggle ===== */
.unit-toggle-container {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 4px;
    border: 1px solid var(--glass-border);
}

[data-theme="light"] .unit-toggle-container {
    background: rgba(0, 0, 0, 0.05);
}

.unit-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.unit-btn .unit-sub {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 2px;
}

.unit-btn:hover {
    color: var(--text-color);
}

.unit-btn.active {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 2px 8px rgba(175, 4, 4, 0.4);
}

.unit-btn.active .unit-sub {
    opacity: 1;
}

.unit-btn:focus {
    outline: 2px solid var(--highlight-color);
    outline-offset: 2px;
}

/* ===== Form Styles ===== */
.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.input-group {
    margin-bottom: 20px;
    position: relative;
}

.input-group.half {
    flex: 1;
    margin-bottom: 0;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 12px 15px;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1rem;
    transition: all 0.3s ease;
    -moz-appearance: textfield;
    appearance: textfield;
}

.input-group select {
    cursor: pointer;
}

.input-group select option {
    background: var(--card-bg);
    color: var(--text-color);
}

/* Hide number input spinners */
.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    background: var(--input-bg-focus);
}

.unit-label {
    font-weight: 400;
    opacity: 0.7;
    font-size: 0.85rem;
}

/* ===== Submit Button ===== */
button[type="submit"],
#calculateBtn {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
}

button[type="submit"]:hover,
#calculateBtn:hover {
    background-color: var(--highlight-color);
}

button[type="submit"]:active,
#calculateBtn:active {
    transform: scale(0.98);
}

/* ===== Result Styles ===== */
.result-container {
    margin-top: 25px;
    border-top: 1px solid var(--glass-border);
    text-align: center;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-20px);
    transition: 
        max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.6s ease 0.1s,
        transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s,
        padding 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: 0;
    padding-bottom: 0;
}

.result-container.visible {
    max-height: 450px;
    opacity: 1;
    transform: translateY(0);
    padding-top: 20px;
    padding-bottom: 10px;
}

.result-container .score,
.result-container .result-details,
.result-container .visualization {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.result-container.visible .score {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.2s;
}

.result-container.visible .result-details {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.35s;
}

.result-container.visible .visualization {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.5s;
}

.hidden {
    pointer-events: none;
}

.score {
    margin-bottom: 15px;
}

#bmiValue {
    display: block;
    font-size: 3rem;
    font-weight: 700;
    line-height: 1.2;
}

#bmiCategory {
    font-size: 1.2rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Result Details Grid */
.result-details {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 15px 0;
    padding: 15px;
    background: var(--input-bg);
    border-radius: 10px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color);
}

/* ===== Visualization Bar ===== */
.visualization {
    margin-top: 20px;
    position: relative;
}

.bar-container {
    height: 12px;
    background: #555;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    margin-bottom: 8px;
}

.bar-gradient {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, 
        #3498db 0%, 
        #3498db 25%, 
        #4caf50 25%, 
        #4caf50 50%, 
        #ff9800 50%, 
        #ff9800 75%, 
        #f44336 75%, 
        #f44336 100%);
    opacity: 0.8;
}

.indicator {
    position: absolute;
    top: -4px;
    width: 4px;
    height: 20px;
    background-color: #fff;
    border: 1px solid #000;
    transform: translateX(-50%);
    transition: left 1s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 2;
}

.labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ===== History Section ===== */
.history-section {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
    transition: background 0.3s ease;
}

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

.history-section h2 {
    font-size: 1.1rem;
    color: var(--text-color);
    margin: 0;
}

.clear-history-btn {
    width: 36px;
    height: 36px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-history-btn:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.clear-history-btn svg {
    width: 100%;
    height: 100%;
    color: var(--text-secondary);
}

.clear-history-btn:hover svg {
    color: white;
}

/* Chart Container */
.chart-container {
    width: 100%;
    height: 200px;
    margin-bottom: 15px;
    background: var(--input-bg);
    border-radius: 10px;
    padding: 10px;
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--input-bg);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.history-item:hover {
    background: var(--input-bg-focus);
}

.history-item .bmi-value {
    font-weight: 600;
}

.history-item .bmi-date {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.history-item .bmi-category {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.history-item .bmi-category.underweight { background: rgba(52, 152, 219, 0.2); color: #3498db; }
.history-item .bmi-category.normal { background: rgba(76, 175, 80, 0.2); color: #4caf50; }
.history-item .bmi-category.overweight { background: rgba(255, 152, 0, 0.2); color: #ff9800; }
.history-item .bmi-category.obese { background: rgba(244, 67, 54, 0.2); color: #f44336; }

/* ===== Footer Sign ===== */
.sign {
    width: 100%;
    text-align: center;
    padding: 20px 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: auto;
}

.sign a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.sign a:hover {
    color: var(--highlight-color);
    text-decoration: underline;
}

/* ===== Modal Styles ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 30px;
    max-width: 340px;
    width: 90%;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    transform: scale(0.8) translateY(-20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-icon {
    width: 50px;
    height: 50px;
    margin: 0 auto 15px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
}

.modal-icon.warning {
    background: rgba(255, 152, 0, 0.2);
    border: 2px solid var(--warning-color);
    color: var(--warning-color);
}

.modal-icon.error {
    background: rgba(244, 67, 54, 0.2);
    border: 2px solid var(--danger-color);
    color: var(--danger-color);
}

.modal-icon.success {
    background: rgba(76, 175, 80, 0.2);
    border: 2px solid var(--success-color);
    color: var(--success-color);
}

#modalMessage {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 20px;
    color: var(--text-color);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.modal-btn {
    flex: 1;
    max-width: 160px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
}

.modal-btn:active {
    transform: scale(0.96);
}

.modal-close-btn {
    background: var(--accent-color);
    color: white;
}

.modal-close-btn:hover {
    background: var(--highlight-color);
}

.modal-cancel-btn {
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
}

.modal-cancel-btn:hover {
    background: var(--input-bg-focus);
}

/* Hide cancel button for simple alert modals */
.modal-overlay:not(.confirm) .modal-cancel-btn {
    display: none;
}

/* ===== Scrollbar Styling ===== */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--input-bg);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
    #bmiValue {
        font-size: 2.5rem;
    }
    
    .labels span {
        font-size: 0.6rem;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .input-group.half {
        margin-bottom: 20px;
    }
    
    .result-details {
        flex-direction: column;
        gap: 15px;
    }
    
    .chart-container {
        height: 180px;
    }
}

/* ===== High Contrast Mode ===== */
@media (prefers-contrast: high) {
    :root {
        --glass-border: rgba(255, 255, 255, 0.3);
    }
    
    [data-theme="light"] {
        --glass-border: rgba(0, 0, 0, 0.3);
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
