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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f0f0f0;
    color: #1a1a1a;
    min-height: 100vh;
}

/* ── Login page ──────────────────────────────────── */

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.login-card .subtitle {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus {
    border-color: #4a90d9;
}

.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    background: #4a90d9;
    color: #fff;
    width: 100%;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    background: #3a7bc8;
}

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

.error-msg {
    color: #d9534f;
    font-size: 0.8rem;
    margin-top: 0.75rem;
    display: none;
}

/* ── App page ────────────────────────────────────── */

.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

.app-header h1 {
    font-size: 1rem;
    font-weight: 600;
}

.app-header .edition {
    font-size: 0.75rem;
    color: #999;
}

.btn-logout {
    background: none;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    color: #666;
    cursor: pointer;
}

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

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    gap: 1rem;
    overflow: hidden;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

/* Question area */
.question-section {
    display: flex;
    gap: 0.5rem;
}

.question-section textarea {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    background: #fff;
    min-height: 80px;
}

.question-section textarea:focus {
    border-color: #4a90d9;
}

.btn-search {
    background: #4a90d9;
    color: #fff;
    border-radius: 8px;
    padding: 0 1.25rem;
    align-self: stretch;
}

.btn-search:hover {
    background: #3a7bc8;
}

.btn-search:disabled {
    background: #a0c4e8;
    cursor: not-allowed;
}

/* Answer area */
.answer-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
    min-height: 0;
}

.answer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #eee;
}

.answer-header .label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #888;
}

.answer-header .status {
    font-size: 0.75rem;
    color: #aaa;
}

.answer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    line-height: 1.65;
    font-size: 0.9rem;
}

.answer-body.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bbb;
    font-size: 0.85rem;
}

/* Markdown content styles */
.answer-body h1 { font-size: 1.2rem; font-weight: 600; margin: 1rem 0 0.5rem; }
.answer-body h2 { font-size: 1.1rem; font-weight: 600; margin: 0.9rem 0 0.4rem; }
.answer-body h3 { font-size: 1rem; font-weight: 600; margin: 0.8rem 0 0.3rem; }
.answer-body h4 { font-size: 0.95rem; font-weight: 600; margin: 0.7rem 0 0.3rem; }
.answer-body p { margin-bottom: 0.6rem; }
.answer-body ul, .answer-body ol { margin: 0.4rem 0 0.6rem 1.5rem; }
.answer-body li { margin-bottom: 0.25rem; }
.answer-body strong { font-weight: 600; }
.answer-body code {
    background: #f4f4f4;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}

/* Page reference pills */
.page-refs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
    border-top: 1px solid #eee;
}

.page-pill {
    display: inline-block;
    background: #e8f0fe;
    color: #3a7bc8;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top-color: #4a90d9;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 600px) {
    .app-main {
        padding: 0.75rem;
    }

    .question-section {
        flex-direction: column;
    }

    .btn-search {
        align-self: stretch;
        padding: 0.6rem;
    }
}

/* Stop and Clear buttons */
.action-buttons { display: flex; gap: 8px; }
.btn-stop { background: #d9534f; color: #fff; border: none; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem; cursor: pointer; font-weight: 500; }
.btn-stop:hover { background: #c9302c; }
.btn-clear { background: #e8e8ed; color: #1d1d1f; border: none; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem; cursor: pointer; font-weight: 500; }
.btn-clear:hover { background: #d2d2d7; }
