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

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

header {
    background: #1a1a2e;
    color: #fff;
    padding: 0 1rem;
}

.nav-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.nav-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links a {
    color: #ccc;
    text-decoration: none;
}

.nav-links a:hover {
    color: #fff;
}

.nav-user {
    color: #ccc;
}

.nav-logout button {
    background: none;
    border: 1px solid #555;
    color: #ccc;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.nav-logout button:hover {
    border-color: #fff;
    color: #fff;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.auth-form {
    max-width: 420px;
    margin: 2rem auto;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.auth-form h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.auth-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.auth-form input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.auth-form input:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.2);
}

.auth-form button {
    width: 100%;
    padding: 0.625rem;
    background: #4361ee;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

.auth-form button:hover {
    background: #3651d4;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #666;
}

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

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

.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fdecea;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-error p {
    margin: 0.25rem 0;
}

.alert-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: #4361ee;
    color: #fff;
}

.btn-primary:hover {
    background: #3651d4;
}

.pipeline-section {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.pipeline-section h2 {
    margin-bottom: 1rem;
}

.pipeline-run-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.pipeline-run-form label {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
}

.days-back-input {
    width: 4rem;
    padding: 0.4rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
    text-align: center;
}

.days-back-input:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.2);
}

.pipeline-running {
    color: #856404;
    font-weight: 500;
}

.pipeline-running .step-label {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.progress-bar {
    background: #e9ecef;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    background: #4361ee;
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}

.digest-list {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.digest-list h2 {
    margin-bottom: 1rem;
}

.digest-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: #333;
}

.digest-item:hover {
    background: #f8f9fa;
    border-color: #4361ee;
}

.empty-state {
    color: #6c757d;
    font-style: italic;
}

.digest-back {
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.digest-back a {
    color: #4361ee;
    text-decoration: none;
}

.digest-back a:hover {
    text-decoration: underline;
}

.digest-header {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}

.digest-header h1 {
    font-size: 1.4rem;
    margin-bottom: 0.375rem;
}

.digest-stats {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.75rem;
}

.digest-stat-sep {
    color: #adb5bd;
}

.digest-overview {
    color: #444;
    font-size: 0.95rem;
    line-height: 1.6;
    border-left: 3px solid #4361ee;
    padding-left: 0.875rem;
    margin-top: 0.5rem;
}

.digest-paper {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
}

.digest-paper-head {
    margin-bottom: 0.875rem;
}

.digest-paper-title {
    display: block;
    font-size: 1.05rem;
    font-weight: 600;
    color: #1a1a2e;
    text-decoration: none;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

a.digest-paper-title:hover {
    color: #4361ee;
    text-decoration: underline;
}

.digest-paper-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    margin-bottom: 0.375rem;
}

.digest-paper-authors {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.digest-authors-more {
    color: #adb5bd;
}

.digest-arxiv-id {
    color: #adb5bd;
}

.digest-section {
    margin-top: 0.75rem;
}

.digest-section p {
    font-size: 0.9rem;
    color: #444;
    line-height: 1.6;
    margin-top: 0.25rem;
}

.digest-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6c757d;
}

.score-high  { background: #1b5e20; }
.score-good  { background: #2e7d32; }
.score-mid   { background: #e65100; }
.score-low   { background: #c62828; }

/* Account settings */
.settings-section {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.settings-section h2 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.settings-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.settings-form input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.settings-form input:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.2);
}

.radio-group {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-weight: 500;
}

.radio-label input[type="radio"] {
    width: auto;
    margin-bottom: 0;
}

.form-hint {
    color: #6c757d;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.status-ok {
    color: #28a745;
    font-weight: 600;
}

.status-missing {
    color: #dc3545;
    font-weight: 600;
}

.prefs-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.btn-secondary {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    color: #333;
    background: #fff;
}

.btn-secondary:hover {
    border-color: #4361ee;
    color: #4361ee;
}

.prefs-json {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 1rem;
    font-size: 0.85rem;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}

/* ── Preferences display ──────────────────────────────────────────── */

.prefs-display h3 {
    font-size: 0.95rem;
    margin: 1rem 0 0.5rem;
    color: #333;
}

.prefs-display h3:first-child {
    margin-top: 0.5rem;
}

.prefs-areas {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.pref-area {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 0.625rem 0.875rem;
}

.pref-category {
    font-weight: 600;
    font-size: 0.95rem;
    color: #3949ab;
}

.pref-weight {
    font-size: 0.8rem;
    color: #6c757d;
    margin-left: 0.5rem;
}

.pref-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.375rem;
}

.pref-keyword {
    display: inline-block;
    background: #e8eaf6;
    color: #3949ab;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.pref-keyword.interest {
    background: #d4edda;
    color: #155724;
}

.pref-keyword.avoid {
    background: #fdecea;
    color: #721c24;
}

/* ── Setup form in wizard ──────────────────────────────────────────── */

.setup-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    margin-bottom: 1rem;
}

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

select.setup-input {
    appearance: auto;
    background: #fff;
}

select.setup-input:disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
}

.model-fetch-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.model-fetch-row .btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.form-label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

/* ── Chat UI ───────────────────────────────────────────────────────── */

.chat-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px - 4rem);
    overflow: hidden;
}

.chat-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    color: #6c757d;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-bubble {
    max-width: 80%;
    padding: 0.625rem 0.875rem;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.5;
}

.chat-bubble ul, .chat-bubble ol {
    margin: 0.25rem 0 0.25rem 1.25rem;
}

.chat-bubble li {
    margin-bottom: 0.15rem;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: #f0f0f0;
    color: #333;
}

.chat-bubble.user {
    align-self: flex-end;
    background: #4361ee;
    color: #fff;
}

.chat-bubble.system {
    align-self: center;
    font-style: italic;
    color: #6c757d;
    background: none;
    font-size: 0.9rem;
}

.chat-input-area {
    display: flex;
    border-top: 1px solid #e9ecef;
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    border: none;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    line-height: 1.5;
    max-height: calc(1.5em * 4 + 1rem);
    outline: none;
}

.chat-input-area button {
    padding: 0.75rem 1.25rem;
    border-radius: 0;
    border-bottom-right-radius: 8px;
    white-space: nowrap;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
    align-items: center;
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing-pulse 1.2s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-pulse {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

.chat-footer {
    text-align: center;
    padding: 0.5rem 0;
}

.btn-link {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    text-decoration: underline;
}

.btn-link:hover {
    color: #dc3545;
}

.confirm-bar {
    border-top: 1px solid #e9ecef;
    padding: 1rem;
    background: #fff;
    animation: slide-up 0.3s ease;
}

.confirm-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

@keyframes slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.prefs-summary h4 {
    margin: 0.5rem 0 0.25rem;
    font-size: 0.9rem;
    color: #333;
}

.prefs-summary ul {
    margin: 0 0 0.25rem 1.25rem;
    font-size: 0.9rem;
}

/* ── Feedback wizard ───────────────────────────────────────────────── */

.wizard-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 1.5rem;
}

.wizard-step-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.wizard-step-indicator .step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    border: 2px solid #ccc;
    color: #999;
    background: #fff;
}

.wizard-step-indicator .step-label {
    font-size: 0.75rem;
    color: #999;
}

.wizard-step-indicator.active .step-num {
    border-color: #4361ee;
    background: #4361ee;
    color: #fff;
}

.wizard-step-indicator.active .step-label {
    color: #4361ee;
    font-weight: 600;
}

.wizard-step-indicator.completed .step-num {
    border-color: #28a745;
    background: #28a745;
    color: #fff;
}

.wizard-step-indicator.completed .step-label {
    color: #28a745;
}

.wizard-step-connector {
    flex: 1;
    height: 2px;
    background: #e9ecef;
    max-width: 80px;
    margin: 0 0.5rem;
    margin-bottom: 1.25rem;
}

.wizard-card {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.wizard-card h2 {
    margin-bottom: 0.5rem;
}

.wizard-card-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.date-option {
    display: block;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-radius: 4px;
}

.date-option:hover {
    background: #f8f9fa;
}

.date-option input {
    margin-right: 0.5rem;
}

.paper-card {
    padding: 1rem 0;
    border-bottom: 1px solid #e9ecef;
}

.paper-card:last-child {
    border-bottom: none;
}

.paper-title {
    font-weight: 600;
    margin-bottom: 0.375rem;
}

.paper-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    margin-bottom: 0.375rem;
}

.paper-summary {
    font-size: 0.875rem;
    color: #555;
    margin-bottom: 0.5rem;
}

.category-pill {
    display: inline-block;
    background: #e8eaf6;
    color: #3949ab;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}

.score-badge {
    display: inline-block;
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.rating-buttons {
    display: flex;
    gap: 0.5rem;
}

.rating-btn {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0.375rem 0.625rem;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.rating-btn:hover {
    border-color: #aaa;
}

.rating-btn.good.active {
    border-color: #28a745;
    background: #d4edda;
}

.rating-btn.bad.active {
    border-color: #dc3545;
    background: #fdecea;
}

.rating-btn.verbal.active {
    border-color: #4361ee;
    background: #d1e0ff;
}

.paper-comment textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    resize: vertical;
}

.delta-reasoning {
    border-left: 4px solid #4361ee;
    background: #f8f9fa;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 0 4px 4px 0;
    white-space: pre-wrap;
}

.delta-changes h4 {
    margin: 0.75rem 0 0.25rem;
    font-size: 0.95rem;
}

.delta-changes ul {
    margin: 0 0 0.5rem 1rem;
}

.delta-changes li {
    margin-bottom: 0.25rem;
}

.badge-add {
    display: inline-block;
    background: #d4edda;
    color: #155724;
    padding: 0 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

.badge-remove {
    display: inline-block;
    background: #fdecea;
    color: #721c24;
    padding: 0 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ── Spinner ───────────────────────────────────────────────────────── */

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e9ecef;
    border-top-color: #4361ee;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* ── Responsive (mobile) ───────────────────────────────────────────── */

@media (max-width: 600px) {
    .chat-container {
        height: calc(100vh - 56px - 2rem);
        border-radius: 0;
    }

    .chat-bubble {
        max-width: 90%;
    }

    .paper-card {
        padding: 0.75rem 0;
    }

    .paper-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    .rating-buttons {
        gap: 0.375rem;
    }

    .rating-btn {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
    }

    .wizard-step-indicator .step-label {
        font-size: 0.65rem;
    }

    .wizard-step-indicator .step-num {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .wizard-step-connector {
        max-width: 40px;
    }

    .confirm-actions {
        flex-direction: column;
    }
}
