/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #EDEEF7 0%, #E4FBFF 100%);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Paper Texture Effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.15) 1px, transparent 0);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header Styles */
.header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(120, 104, 230, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.header img {
    max-width: 150px;
    height: auto;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(120, 104, 230, 0.2);
    transition: transform 0.3s ease;
    object-fit: contain;
}

.header img:hover {
    transform: scale(1.05);
}

.header__title {
    font-size: 2.5rem;
    color: #7868E6;
    margin: 0;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    line-height: 1.2;
}

.header__subtitle {
    font-size: 1.1rem;
    color: #666;
    font-weight: 300;
    margin: 0;
}

.header__info {
    margin-top: 5px;
    padding: 10px 20px;
    background: rgba(120, 104, 230, 0.1);
    border-radius: 20px;
    display: inline-block;
}

.header__info small {
    color: #7868E6;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Card Styles */
.card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 40px rgba(120, 104, 230, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, #B8B5FF, #7868E6, #B8B5FF);
}

.card__title {
    font-size: 1.8rem;
    color: #7868E6;
    margin-bottom: 25px;
    font-weight: 600;
    text-align: center;
}

/* Form Styles */
.form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form__row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form__group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form__label {
    font-weight: 600;
    color: #555;
    font-size: 0.95rem;
}

.form__input,
.form__select {
    padding: 15px;
    border: 2px solid #E4FBFF;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.9);
}

.form__input:focus,
.form__select:focus {
    outline: none;
    border-color: #7868E6;
    box-shadow: 0 0 0 3px rgba(120, 104, 230, 0.1);
    transform: translateY(-2px);
}

.form__input:invalid {
    border-color: #FFB4B4;
}

.form__actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

/* Button Styles */
.btn {
    padding: 15px 30px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 140px;
}

.btn--primary {
    background: linear-gradient(135deg, #7868E6, #B8B5FF);
    color: white;
    box-shadow: 0 4px 15px rgba(120, 104, 230, 0.3);
}

.btn--primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(120, 104, 230, 0.4);
}

.btn--secondary {
    background: #EDEEF7;
    color: #7868E6;
    border: 2px solid #B8B5FF;
}

.btn--secondary:hover {
    background: #B8B5FF;
    color: white;
    transform: translateY(-2px);
}

.btn--danger {
    background: linear-gradient(135deg, #FFB4B4, #ff8a8a);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 180, 180, 0.3);
}

.btn--danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 180, 180, 0.4);
}

/* Results Styles */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.result-item {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.result-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.result-item__title {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 10px;
    font-weight: 600;
}

.result-item__value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.result-item__classification {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    display: inline-block;
}

/* Classification Colors */
.classification--low {
    background: #FFB4B4;
    color: #8B0000;
    border-color: #FFB4B4;
}

.classification--normal {
    background: #B8B5FF;
    color: #4A3C9A;
    border-color: #B8B5FF;
}

.classification--high {
    background: #E4FBFF;
    color: #0077BE;
    border-color: #E4FBFF;
}

.value--low {
    color: #FF6B6B;
}

.value--normal {
    color: #7868E6;
}

.value--high {
    color: #00A8CC;
}

/* Chart Styles */
.chart-container {
    position: relative;
    margin: 20px 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 20px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

#percentileChart {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #666;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.legend-color--low {
    background: #FFB4B4;
}

.legend-color--normal {
    background: #B8B5FF;
}

.legend-color--high {
    background: #E4FBFF;
}

/* History Styles */
.history-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    justify-content: center;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-empty {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 40px;
}

.history-item {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    border-left: 4px solid #B8B5FF;
    transition: all 0.3s ease;
}

.history-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

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

.history-item__name {
    font-weight: 600;
    color: #7868E6;
    font-size: 1.1rem;
}

.history-item__date {
    font-size: 0.85rem;
    color: #999;
}

.history-item__details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.history-detail {
    text-align: center;
}

.history-detail__label {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 5px;
}

.history-detail__value {
    font-weight: 600;
    font-size: 0.9rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #E4FBFF;
    border-top: 4px solid #7868E6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
    backdrop-filter: blur(5px);
}

.modal__content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal__title {
    color: #7868E6;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.modal__message {
    margin-bottom: 25px;
    color: #666;
    line-height: 1.8;
    text-align: left;
    max-height: 400px;
    overflow-y: auto;
}

/* Footer Styles */
.footer {
    margin-top: 50px;
    margin-bottom: 80px; /* Space for bottom nav on mobile */
    padding: 30px 0;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    box-shadow: 0 -4px 20px rgba(120, 104, 230, 0.1);
}

.footer__text {
    color: #7868E6;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 0 -4px 20px rgba(120, 104, 230, 0.15);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0;
    z-index: 999;
    border-top: 1px solid rgba(120, 104, 230, 0.1);
    
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    transition: all 0.3s ease;
    border-radius: 12px;
    min-width: 60px;
}

.nav-item:hover {
    background: rgba(120, 104, 230, 0.05);
    color: #7868E6;
}

.nav-item.active {
    color: #7868E6;
    background: rgba(120, 104, 230, 0.1);
}

.nav-item.active .nav-icon {
    transform: scale(1.1);
}

.nav-icon {
    width: 24px;
    height: 24px;
    transition: all 0.3s ease;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
}

/* FAQ Section */
.faq-section {
    margin-bottom: 30px;
}

.faq-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.faq-item {
    border: 2px solid #E4FBFF;
    border-radius: 15px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.faq-item:hover {
    border-color: #B8B5FF;
    box-shadow: 0 4px 15px rgba(120, 104, 230, 0.1);
}

.faq-item.active {
    border-color: #7868E6;
}

.faq-question {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    transition: all 0.3s ease;
}

.faq-question:hover {
    background: rgba(120, 104, 230, 0.05);
    color: #7868E6;
}

.faq-question span {
    flex: 1;
    padding-right: 15px;
}

.faq-icon {
    flex-shrink: 0;
    transition: transform 0.3s ease;
    color: #7868E6;
}

.faq-item.active .faq-icon {
    transform: rotate(180deg);
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
}

.faq-item.active .faq-answer {
    max-height: 500px;
    opacity: 1;
    padding: 0 20px 20px;
}

.faq-answer p {
    color: #666;
    line-height: 1.6;
    margin: 0;
}

.faq-answer strong {
    color: #7868E6;
    display: inline-block;
    margin-top: 10px;
}

/* Section smooth scrolling */
.section {
    scroll-margin-top: 20px;
    animation: fadeIn 0.5s ease-in-out;
}

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

/* Button hover effects */
.btn {
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

/* Card entrance animation */
.card {
    animation: slideUp 0.6s ease-out;
}

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

/* Improved focus indicators */
.btn:focus-visible,
.form__input:focus-visible,
.form__select:focus-visible,
.nav-item:focus-visible,
.faq-question:focus-visible {
    outline: 3px solid #7868E6;
    outline-offset: 2px;
}

/* Skeleton loading for history */
.history-list.loading::after {
    content: '';
    display: block;
    height: 100px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 12px;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
        padding-bottom: 90px; /* Space for bottom nav */
    }
    
    .header {
        margin-bottom: 20px;
        padding: 20px 15px;
        gap: 12px;
    }
    
    .header img {
        max-width: 120px;
    }
    
    .header__title {
        font-size: 1.8rem;
    }
    
    .header__subtitle {
        font-size: 0.95rem;
    }
    
    .header__info {
        padding: 8px 15px;
    }
    
    .header__info small {
        font-size: 0.75rem;
    }
    
    .card {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    .card__title {
        font-size: 1.5rem;
    }
    
    .form__row {
        grid-template-columns: 1fr;
    }
    
    .form__actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .results-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-legend {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .history-controls {
        flex-direction: column;
    }
    
    .history-item__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .history-item__details {
        grid-template-columns: 1fr;
    }
    
    /* Bottom nav adjustments */
    .nav-label {
        font-size: 0.65rem;
    }
    
    .nav-item {
        padding: 6px 8px;
        min-width: 50px;
    }
    
    .nav-icon {
        width: 22px;
        height: 22px;
    }
    
    /* FAQ mobile optimization */
    .faq-question {
        padding: 15px;
        font-size: 0.95rem;
    }
    
    .faq-item.active .faq-answer {
        padding: 0 15px 15px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
        padding-bottom: 85px;
    }
    
    .header {
        padding: 15px 10px;
        margin-bottom: 15px;
        gap: 10px;
    }
    
    .header img {
        max-width: 100px;
    }
    
    .header__title {
        font-size: 1.5rem;
    }
    
    .header__subtitle {
        font-size: 0.85rem;
    }
    
    .header__info {
        padding: 6px 12px;
        margin-top: 5px;
    }
    
    .header__info small {
        font-size: 0.7rem;
        display: block;
        line-height: 1.4;
    }
    
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .card__title {
        font-size: 1.3rem;
    }
    
    .form__group {
        gap: 6px;
    }
    
    .form__label {
        font-size: 0.9rem;
    }
    
    .form__input,
    .form__select {
        padding: 12px;
        font-size: 0.95rem;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .result-item {
        padding: 20px;
    }
    
    .result-item__value {
        font-size: 1.8rem;
    }
    
    .history-item {
        padding: 15px;
    }
    
    .history-item__details {
        grid-template-columns: 1fr;
    }
    
    #percentileChart {
        width: 100%;
        height: 250px;
    }
    
    /* Bottom nav extra small screens */
    .bottom-nav {
        padding: 6px 0;
    }
    
    .nav-item {
        padding: 5px 4px;
        min-width: 45px;
        gap: 2px;
    }
    
    .nav-icon {
        width: 20px;
        height: 20px;
    }
    
    .nav-label {
        font-size: 0.6rem;
    }
    
    /* FAQ extra small screens */
    .faq-question {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .faq-answer p {
        font-size: 0.9rem;
    }
    
    .footer {
        margin-bottom: 100px;
        padding: 20px;
    }
    
    .footer__text {
        font-size: 0.8rem;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) {
    .bottom-nav {
        padding: 4px 0;
    }
    
    .nav-item {
        padding: 4px 6px;
    }
    
    .nav-label {
        display: none;
    }
    
    .nav-icon {
        width: 24px;
        height: 24px;
    }
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid #000;
    }
    
    .btn--primary {
        background: #000;
        border: 2px solid #000;
    }
    
    .btn--secondary {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
}

/* Focus indicators for accessibility */
.form__input:focus,
.form__select:focus,
.btn:focus {
    outline: 3px solid #7868E6;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .header,
    .form,
    .history-controls,
    .footer {
        display: none;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    body {
        background: white;
    }
}
