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

body {
    font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.6;
}

/* Navigation */
.nav-bar {
    background: #fff;
    padding: 18px 24px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    color: #4361ee;
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 20px;
    align-items: center;
}

.nav-links > a {
    color: #555;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.3s;
}

.nav-links > a:hover, .nav-links > a.active {
    color: #4361ee;
    background: rgba(67, 97, 238, 0.1);
}

/* Dropdown */
.dropdown { position: relative; }

.dropdown-btn {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.dropdown-btn.app-btn {
    background: linear-gradient(135deg, #4361ee, #7209b7);
    color: white;
    border: none;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    min-width: 180px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.12);
    border-radius: 8px;
    padding-top: 8px;
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
}

.dropdown-content::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}

.dropdown:hover .dropdown-content { display: block; }

.dropdown-content a {
    display: block;
    padding: 12px 18px;
    color: #555;
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.dropdown-content a:hover, .dropdown-content a.active {
    background: #f8f9fa;
    color: #4361ee;
    border-left-color: #4361ee;
}

.user-btn { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 24px; height: 24px; border-radius: 50%; }

.login-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: #555;
    padding: 8px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s;
}

.login-btn:hover {
    background: #f8f9fa;
    color: #4361ee;
}

/* Container */
.container {
    max-width: 850px;
    margin: 30px auto;
    padding: 0 20px;
}

.calculator-container {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

.title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 30px;
    color: #4361ee;
    position: relative;
    padding-bottom: 15px;
}

.title:after {
    content: '';
    position: absolute;
    width: 80px;
    height: 3px;
    background: linear-gradient(90deg, #4361ee, #7209b7);
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* Form */
.form-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

@media (min-width: 768px) {
    .form-row { flex-direction: row; align-items: center; }
    .label { width: 150px; margin-bottom: 0; }
}

.label {
    font-size: 16px;
    color: #444;
    margin-bottom: 8px;
    font-weight: 500;
}

.input-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    flex: 1;
}

.input-field {
    flex: 1;
    min-width: 150px;
    height: 46px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0 15px;
    font-size: 16px;
}

.input-field:focus {
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
    outline: none;
}

.unit-label { color: #666; font-weight: 500; }

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

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

/* Buttons */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 25px 0;
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    min-width: 120px;
}

.calculate-btn {
    background: linear-gradient(135deg, #4361ee, #7209b7);
    color: white;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
}

.reset-btn { background: linear-gradient(135deg, #f44336, #ff9800); color: white; }
.share-btn { background: linear-gradient(135deg, #4CAF50, #8BC34A); color: white; }
.save-btn { background: #4361ee; color: white; margin-top: 15px; width: 100%; }

/* Result */
.result {
    margin: 20px 0;
    padding: 20px;
    text-align: center;
    background: linear-gradient(135deg, #f0f8ff, #e8f4fd);
    border-radius: 12px;
}

.result-content { display: flex; justify-content: center; align-items: center; gap: 10px; }
.result-gender { font-size: 17px; color: #444; }
.result-value { font-size: 24px; color: #4361ee; font-weight: 700; }

.message {
    text-align: center;
    padding: 10px;
    background: #d4edda;
    color: #155724;
    border-radius: 6px;
    margin: 10px 0;
}

/* Sections */
.interpretation, .disclaimer {
    margin-top: 30px;
    padding: 25px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #eee;
}

.interpretation h2 {
    font-size: 20px;
    color: #333;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #4361ee;
}

.ckd-stages { list-style: none; }
.ckd-stages li { padding: 10px 15px; margin: 5px 0; border-radius: 6px; font-size: 15px; }
.stage-normal { background: #d4edda; color: #155724; }
.stage-mild { background: #fff3cd; color: #856404; }
.stage-moderate { background: #ffe5d0; color: #8a4500; }
.stage-severe { background: #f8d7da; color: #721c24; }
.stage-failure { background: #d6336c; color: white; }

.disclaimer { background: #f8f9fa; color: #666; font-size: 14px; }

/* Footer */
.footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 40px;
    background: #fff;
    border-top: 1px solid #eee;
}

.footer-link {
    margin-top: 10px;
}

.footer-link a {
    color: #4361ee;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.3s ease;
}

.footer-link a:hover {
    color: #3451d1;
    text-decoration: underline;
}

.footer-apps { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }

.app-link {
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 20px;
    text-decoration: none;
    color: #555;
    font-size: 14px;
}

.app-link:hover { background: #4361ee; color: white; }
.copyright { color: #888; font-size: 14px; }

/* History */
.history-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.history-table th, .history-table td { padding: 12px; text-align: left; border-bottom: 1px solid #eee; }
.history-table th { background: #4361ee; color: white; }
.btn-delete { background: #f44336; color: white; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; }
.no-history { text-align: center; color: #888; padding: 40px; }

/* Responsive */
@media (max-width: 768px) {
    .nav-bar { flex-direction: column; gap: 15px; }
    .nav-links { flex-wrap: wrap; justify-content: center; }
    .button-group { flex-direction: column; }
    .btn { width: 100%; }
}

/* Home Page */
.home-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px 20px;
}

.hero {
    text-align: center;
    margin-bottom: 50px;
}

.hero h1 {
    font-size: 2.5rem;
    color: #333;
    margin-bottom: 15px;
}

.hero-desc {
    font-size: 1.1rem;
    color: #666;
}

.calculators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.calculator-card {
    background: #fff;
    border-radius: 16px;
    padding: 30px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    display: block;
}

.calculator-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(67, 97, 238, 0.15);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.card-title {
    font-size: 1.3rem;
    color: #333;
    margin-bottom: 10px;
}

.card-desc {
    font-size: 0.95rem;
    color: #666;
    line-height: 1.5;
}


/* Auth Pages */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 40px 20px;
}

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
    font-size: 1.8rem;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #555;
}

.auth-form input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.auth-form input:focus {
    outline: none;
    border-color: #4361ee;
}

.auth-form small {
    display: block;
    margin-top: 4px;
    color: #888;
    font-size: 12px;
}

.auth-btn {
    width: 100%;
    padding: 14px;
    background: #4361ee;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.auth-btn:hover {
    background: #3451d1;
}

.auth-error {
    background: #fee;
    color: #c00;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

.auth-divider {
    text-align: center;
    margin: 25px 0;
    position: relative;
}

.auth-divider::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 1px;
    background: #e0e0e0;
}

.auth-divider span {
    background: #fff;
    padding: 0 15px;
    position: relative;
    color: #888;
    font-size: 14px;
}

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    background: #fff;
    color: #333;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s;
}

.google-btn:hover {
    background: #f8f8f8;
    border-color: #ccc;
}

.auth-link {
    text-align: center;
    margin-top: 25px;
    color: #666;
    font-size: 14px;
}

.auth-link a {
    color: #4361ee;
    text-decoration: none;
    font-weight: 500;
}

.auth-link a:hover {
    text-decoration: underline;
}


/* History table params */
.params-cell {
    font-size: 13px;
    color: #666;
    max-width: 300px;
    line-height: 1.5;
}


/* Formula box */
.formula-box {
    background: #f0f4ff;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
}

.formula-box h2 {
    font-size: 1.1rem;
    color: #4361ee;
    margin-bottom: 10px;
}

.formula {
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    color: #333;
    background: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    display: inline-block;
}


/* Risk badges */
.risk-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    margin-left: 10px;
}

.risk-very-low {
    background: #d4edda;
    color: #155724;
}

.risk-low {
    background: #fff3cd;
    color: #856404;
}

.risk-high {
    background: #f8d7da;
    color: #721c24;
}

.stroke-risk-info {
    margin: 15px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
}

.recommendation-box {
    margin: 15px 0;
    padding: 15px;
    background: #e8f4fd;
    border-radius: 8px;
    border-left: 4px solid #4361ee;
}

.criteria-list {
    list-style: none;
    padding: 0;
}

.criteria-list li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.criteria-list li:last-child {
    border-bottom: none;
}

.risk-stages {
    list-style: none;
    padding: 0;
}

.risk-stages li {
    padding: 12px 15px;
    margin: 8px 0;
    border-radius: 8px;
    font-size: 15px;
}


/* ========== Mobile Responsive Enhancement ========== */
@media (max-width: 480px) {
    .nav-bar {
        padding: 12px 15px;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .nav-links {
        gap: 8px;
    }
    
    .dropdown-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .login-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .container {
        margin: 15px auto;
        padding: 0 12px;
    }
    
    .calculator-container {
        padding: 20px 15px;
        border-radius: 8px;
    }
    
    .title {
        font-size: 22px;
        margin-bottom: 20px;
    }
    
    .input-field {
        height: 44px;
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    .radio-label {
        padding: 6px 12px;
        font-size: 14px;
    }
    
    .btn {
        padding: 12px 16px;
        font-size: 15px;
    }
    
    .result-value {
        font-size: 20px;
    }
    
    .interpretation, .disclaimer {
        padding: 15px;
    }
    
    .ckd-stages li {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .hero h1 {
        font-size: 1.8rem;
    }
    
    .hero-desc {
        font-size: 1rem;
    }
    
    .calculator-card {
        padding: 20px;
    }
    
    .card-icon {
        font-size: 2.5rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
    
    .auth-card {
        padding: 25px 20px;
    }
    
    .auth-card h1 {
        font-size: 1.5rem;
    }
    
    /* History table scroll */
    .history-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .params-cell {
        max-width: 200px;
        white-space: normal;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .hero h1 {
        font-size: 2rem;
    }
    
    .calculators-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Touch-friendly */
@media (hover: none) {
    .dropdown:hover .dropdown-content {
        display: none;
    }
    
    .dropdown.active .dropdown-content {
        display: block;
    }
    
    .btn:active {
        transform: scale(0.98);
    }
    
    .calculator-card:active {
        transform: scale(0.98);
    }
}

/* Safe area for notch devices */
@supports (padding: max(0px)) {
    .nav-bar {
        padding-left: max(24px, env(safe-area-inset-left));
        padding-right: max(24px, env(safe-area-inset-right));
    }
    
    .container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* Mobile responsive fixes for CHA₂DS₂-VASc */
@media (max-width: 768px) {
    .max-w-4xl {
        max-width: 100%;
        padding: 0 1rem;
    }
    
    .grid.lg\\:grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .lg\\:sticky {
        position: static;
    }
    
    .text-3xl {
        font-size: 1.5rem;
        line-height: 2rem;
    }
    
    /* Fix button layouts */
    .age-btn, .sex-btn, .chf-btn, .hypertension-btn, .stroke-btn, .vascular-btn, .diabetes-btn {
        min-height: 44px;
        min-width: 44px;
        font-size: 0.875rem;
        padding: 0.75rem;
        word-wrap: break-word;
        hyphens: auto;
    }
    
    /* Age buttons - better mobile layout */
    .age-btn {
        flex: 1 1 30%;
        min-width: 100px;
    }
    
    /* Two column layout for yes/no buttons */
    .chf-btn, .hypertension-btn, .stroke-btn, .vascular-btn, .diabetes-btn, .sex-btn {
        flex: 1 1 45%;
        min-width: 140px;
    }
    
    /* Improve button spacing */
    .flex.gap-2 {
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    /* Fix text overflow */
    .block.text-base.sm\\:text-lg.font-medium.text-gray-700.mb-2.sm\\:mb-3,
    .block.text-base.sm\\:text-lg.font-medium.text-gray-700.mb-2.sm\\:mb-3.break-words {
        font-size: 0.875rem;
        line-height: 1.25rem;
        word-wrap: break-word;
        hyphens: auto;
        overflow-wrap: break-word;
    }
    
    /* Results panel mobile optimization */
    .bg-primary-600.text-white.rounded-lg.p-4.sm\\:p-6 {
        padding: 1rem;
    }
    
    .text-4xl {
        font-size: 2rem;
        line-height: 2.25rem;
    }
    
    /* Better mobile spacing */
    .space-y-4.sm\\:space-y-6 > * + * {
        margin-top: 1rem;
    }
    
    .border-b.border-gray-200.pb-3.sm\\:pb-4 {
        padding-bottom: 1rem;
        margin-bottom: 1rem;
    }
}

@media (max-width: 480px) {
    .max-w-4xl {
        padding: 0 0.75rem;
    }
    
    .mb-6.sm\\:mb-8 {
        margin-bottom: 1.5rem;
    }
    
    .text-2xl.sm\\:text-3xl {
        font-size: 1.25rem;
        line-height: 1.75rem;
    }
    
    /* Stack buttons vertically on very small screens */
    .age-btn, .sex-btn, .chf-btn, .hypertension-btn, .stroke-btn, .vascular-btn, .diabetes-btn {
        flex: 1 1 100%;
        margin-bottom: 0.5rem;
        min-width: auto;
    }
    
    .flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* Age buttons special handling */
    .flex.flex-wrap.gap-2:has(.age-btn) {
        flex-direction: row;
    }
    
    .age-btn {
        flex: 1 1 30%;
        min-width: 80px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .age-btn, .sex-btn, .chf-btn, .hypertension-btn, .stroke-btn, .vascular-btn, .diabetes-btn {
        min-height: 48px;
        padding: 0.875rem;
    }
    
    .age-btn:active, .sex-btn:active, .chf-btn:active, .hypertension-btn:active, 
    .stroke-btn:active, .vascular-btn:active, .diabetes-btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Print styles */
@media print {
    .nav-bar, .footer, .button-group, .dropdown {
        display: none;
    }
    
    .calculator-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus improvements for accessibility */
.age-btn:focus, .sex-btn:focus, .chf-btn:focus, .hypertension-btn:focus, 
.stroke-btn:focus, .vascular-btn:focus, .diabetes-btn:focus {
    outline: 2px solid #4361ee;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .age-btn, .sex-btn, .chf-btn, .hypertension-btn, 
    .stroke-btn, .vascular-btn, .diabetes-btn {
        border-width: 2px;
    }
    
    .selected {
        border-color: #000;
        background-color: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .age-btn, .sex-btn, .chf-btn, .hypertension-btn, 
    .stroke-btn, .vascular-btn, .diabetes-btn {
        transition: none;
    }
    
    .calculator-card {
        transition: none;
    }
    
    .btn:active {
        transform: none;
    }
}
