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

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --success: #34a853;
    --warning: #fbbc04;
    --error: #ea4335;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.header-logo svg {
    width: 32px;
    height: 32px;
    fill: var(--primary);
}

.header-nav {
    display: flex;
    gap: 8px;
}

.header-nav a {
    padding: 8px 16px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s;
}

.header-nav a:hover {
    background: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}

.header-nav a.active {
    background: var(--primary);
    color: white;
}

/* Main content */
.main {
    flex: 1;
    padding: 32px 24px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Hero section */
.hero {
    text-align: center;
    padding: 48px 24px;
    margin-bottom: 48px;
}

.hero h1 {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

.hero p {
    font-size: 18px;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Cards grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 48px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 32px;
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.card-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.card-icon svg {
    width: 32px;
    height: 32px;
    fill: var(--primary);
}

.card h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.card p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Query page */
.query-container {
    max-width: 800px;
    margin: 0 auto;
}

.query-form {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 32px;
    margin-bottom: 24px;
}

.query-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.query-form textarea {
    width: 100%;
    min-height: 120px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

.query-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.query-options {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.query-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    cursor: pointer;
}

.query-options input[type="range"] {
    width: 100px;
}

.query-options input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: #94baf7;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: white;
}

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

.query-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

/* Answer section */
.answer-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    display: none;
}

.answer-section.visible {
    display: block;
}

.answer-header {
    background: var(--primary-light);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.answer-body {
    padding: 24px;
}

.answer-text {
    font-size: 16px;
    line-height: 1.8;
    white-space: pre-wrap;
}

.answer-sources {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.answer-sources h4 {
    font-size: 14px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.source-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 8px;
    align-items: flex-start;
}

.source-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}

.source-badge.text {
    background: #e3f2fd;
    color: #1565c0;
}

.source-badge.image {
    background: #fce4ec;
    color: #c62828;
}

.source-info {
    flex: 1;
    min-width: 0;
}

.source-chapter {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.source-excerpt {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.source-image {
    margin-top: 8px;
}

.source-image img {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Answer images */
.answer-images {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.answer-images h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.image-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.image-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s;
}

.image-card:hover {
    border-color: var(--primary);
}

.image-card img {
    width: 100%;
    display: block;
}

.image-card-info {
    padding: 8px 12px;
}

.image-card-chapter {
    font-size: 11px;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-card-desc {
    font-size: 12px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Image lightbox modal */
.image-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
}

.image-modal-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.image-modal-close {
    position: absolute;
    top: 16px;
    right: 24px;
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    z-index: 1001;
}

/* Stats page */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    text-align: center;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

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

/* About page */
.about-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 32px;
    margin-bottom: 24px;
}

.about-section h2 {
    font-size: 24px;
    margin-bottom: 16px;
    color: var(--text);
}

.about-section p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.8;
}

.tech-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.tech-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 14px;
}

.tech-item svg {
    width: 20px;
    height: 20px;
    fill: var(--primary);
    flex-shrink: 0;
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 48px;
}

.loading.visible {
    display: block;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: auto;
}

/* Error message */
.error-message {
    background: #fce4ec;
    color: #c62828;
    padding: 16px 24px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: none;
}

.error-message.visible {
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        padding: 0 16px;
    }

    .header-nav {
        gap: 4px;
    }

    .header-nav a {
        padding: 6px 10px;
        font-size: 14px;
    }

    .main {
        padding: 24px 16px;
    }

    .hero h1 {
        font-size: 28px;
    }

    .hero p {
        font-size: 16px;
    }

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

    .query-options {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-value {
        font-size: 28px;
    }
}

/* Test images page */
.test-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.test-image-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.test-image-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    word-break: break-all;
}

.test-image-card img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
}
