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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft JhengHei", sans-serif;
    background: #f0f4f8;
    color: #1a202c;
    line-height: 1.6;
    min-height: 100vh;
}

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

/* Header */
header {
    text-align: center;
    padding: 40px 0 30px;
}

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

.user-info {
    font-size: 0.85rem;
    color: #718096;
}

.btn-logout {
    font-size: 0.8rem;
    color: #e53e3e;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid #fed7d7;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-logout:hover {
    background: #fff5f5;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

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

.login-card h1 {
    font-size: 1.4rem;
    color: #2d3748;
    margin-bottom: 5px;
}

.login-subtitle {
    color: #a0aec0;
    font-size: 0.85rem;
    margin-bottom: 25px;
}

.login-error {
    background: #fff5f5;
    color: #c53030;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.form-group {
    text-align: left;
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: #4a5568;
    margin-bottom: 5px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: #3182ce;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.btn-full {
    width: 100%;
    margin-top: 8px;
}

header h1 {
    font-size: 1.8rem;
    color: #2d3748;
    margin-bottom: 5px;
}

header .subtitle {
    color: #718096;
    font-size: 0.95rem;
}

/* Card */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: #2d3748;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: #3182ce;
    color: #fff;
}

.btn-primary:hover {
    background: #2b6cb0;
}

.btn-secondary {
    background: #edf2f7;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: #fc8181;
    color: #fff;
}

.btn-danger:hover {
    background: #f56565;
}

.btn-large {
    padding: 14px 36px;
    font-size: 1.1rem;
}

/* Finger selection */
.finger-select {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.select-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.select-group > label {
    font-weight: 600;
    color: #4a5568;
    white-space: nowrap;
}

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

.radio-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.radio-label:has(input:checked) {
    background: #ebf8ff;
    border-color: #3182ce;
    color: #2b6cb0;
    font-weight: 500;
}

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

/* Upload section */
.upload-methods {
    text-align: center;
}

.upload-btn-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.hint {
    margin-top: 12px;
    color: #a0aec0;
    font-size: 0.85rem;
}

/* Camera */
#camera-container {
    margin-top: 20px;
    text-align: center;
}

#camera-video {
    width: 100%;
    max-width: 640px;
    border-radius: 8px;
    background: #000;
}

.camera-controls {
    margin-top: 15px;
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Preview */
#preview-container {
    margin-top: 20px;
    text-align: center;
}

#preview-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.preview-controls {
    margin-top: 15px;
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Loading */
#loading {
    text-align: center;
    padding: 40px 0;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top-color: #3182ce;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Result section */
#result-section {
    animation: fadeIn 0.4s ease;
}

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

.result-header {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.result-image {
    flex: 0 0 280px;
}

.result-image img {
    width: 100%;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.result-summary {
    flex: 1;
    min-width: 250px;
}

.result-summary h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #2d3748;
}

.result-summary p {
    color: #4a5568;
    line-height: 1.7;
}

.confidence-badge {
    display: inline-block;
    background: #ebf8ff;
    color: #2b6cb0;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 10px;
}

/* Organ correspondence */
.organ-badge {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.finger-tag {
    background: #fefcbf;
    color: #975a16;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.organ-tag {
    background: #c6f6d5;
    color: #276749;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.organ-description {
    color: #718096;
    font-size: 0.85rem;
    margin-bottom: 10px;
    font-style: italic;
}

.organ-assessment-card {
    border: 2px solid #c6f6d5;
    background: #f0fff4;
}

.analysis-card .description {
    margin-top: 4px;
}

/* Analysis cards */
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.analysis-card {
    background: #f7fafc;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
}

.analysis-card h4 {
    font-size: 0.95rem;
    color: #718096;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.analysis-card .score {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 5px;
}

.analysis-card .description {
    color: #4a5568;
    font-size: 0.9rem;
}

/* Abnormalities */
.abnormality-list {
    margin-top: 20px;
}

.abnormality-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: #fff5f5;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid #fc8181;
}

.abnormality-item.mild {
    background: #fffff0;
    border-left-color: #ecc94b;
}

.abnormality-item.moderate {
    background: #fffaf0;
    border-left-color: #ed8936;
}

.abnormality-item.severe {
    background: #fff5f5;
    border-left-color: #e53e3e;
}

.severity-tag {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.severity-mild { background: #fefcbf; color: #975a16; }
.severity-moderate { background: #feebc8; color: #9c4221; }
.severity-severe { background: #fed7d7; color: #9b2c2c; }

/* Recommendations */
.recommendations {
    margin-top: 20px;
}

.recommendations ul {
    list-style: none;
    padding: 0;
}

.recommendations li {
    padding: 8px 0 8px 24px;
    position: relative;
    color: #4a5568;
}

.recommendations li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: #38a169;
    font-weight: bold;
}

/* New analysis button */
.new-analysis {
    text-align: center;
    margin-top: 25px;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 0;
}

.disclaimer {
    color: #a0aec0;
    font-size: 0.8rem;
    max-width: 500px;
    margin: 0 auto;
}

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

/* Error message */
.error-message {
    background: #fff5f5;
    color: #c53030;
    padding: 15px 20px;
    border-radius: 8px;
    border: 1px solid #fed7d7;
    margin-top: 15px;
    text-align: center;
}

/* History button */
.btn-history {
    font-size: 0.8rem;
    color: #3182ce;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid #bee3f8;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-history:hover {
    background: #ebf8ff;
}

/* History list */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.history-item.expanded {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.history-item-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.history-item-header:hover {
    background: #f7fafc;
}

.history-item-date {
    font-size: 0.9rem;
    color: #4a5568;
    font-weight: 500;
    white-space: nowrap;
}

.history-item-meta {
    font-size: 0.85rem;
    color: #718096;
}

/* Delete button */
.btn-delete {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: #cbd5e0;
    border-radius: 50%;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-delete:hover {
    background: #fed7d7;
    color: #c53030;
}

/* Detail expand area */
.history-item-detail {
    border-top: 1px solid #edf2f7;
    padding: 20px;
}

.detail-loading {
    text-align: center;
    color: #a0aec0;
    padding: 20px 0;
}

.detail-content {
    animation: fadeIn 0.3s ease;
}

.detail-image {
    margin-bottom: 16px;
}

.detail-image img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    display: block;
}

.detail-summary {
    margin-bottom: 16px;
}

.detail-summary h3 {
    font-size: 1.05rem;
    margin-bottom: 8px;
    color: #2d3748;
}

.detail-summary p {
    color: #4a5568;
    line-height: 1.7;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.page-btn {
    padding: 8px 14px;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.page-btn:hover:not(:disabled):not(.active) {
    background: #ebf8ff;
    border-color: #bee3f8;
}

.page-btn.active {
    background: #3182ce;
    color: #fff;
    border-color: #3182ce;
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-ellipsis {
    padding: 0 4px;
    color: #a0aec0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #a0aec0;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .card {
        padding: 20px;
    }

    .result-image {
        flex: 0 0 100%;
    }

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

    .history-item-header {
        padding: 12px 14px;
        gap: 10px;
    }

    .history-item-detail {
        padding: 14px;
    }
}
