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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1117;
    color: #e4e4e7;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── Login Form ──────────────────────────────────────────────── */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
}

.login-form {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-form h1 {
    font-size: 1.5rem;
    color: #fafafa;
    margin-bottom: 8px;
}

.login-subtitle {
    color: #71717a;
    font-size: 0.9rem;
    margin-bottom: 24px;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: #a1a1aa;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    background: #0f1117;
    border: 1px solid #3f3f46;
    border-radius: 8px;
    padding: 12px 14px;
    color: #fafafa;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus {
    border-color: #60a5fa;
}

.form-group input::placeholder {
    color: #52525b;
}

.login-error {
    color: #ef4444;
    font-size: 0.85rem;
    margin-bottom: 12px;
    min-height: 20px;
}

.login-submit-btn {
    width: 100%;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.login-submit-btn:hover {
    background: #1d4ed8;
}

.login-submit-btn:disabled {
    background: #1e3a5f;
    cursor: not-allowed;
    opacity: 0.6;
}

.password-field {
    -webkit-text-security: disc;
    text-security: disc;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    padding: 0 16px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid #27272a;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #fafafa;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-selector label {
    font-size: 0.8rem;
    color: #a1a1aa;
    font-weight: 500;
}

.model-selector select {
    background: #18181b;
    border: 1px solid #3f3f46;
    color: #fafafa;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}

.model-selector select:hover {
    border-color: #60a5fa;
}

.model-selector select:focus {
    border-color: #60a5fa;
}

.logout-btn {
    background: transparent;
    border: 1px solid #3f3f46;
    color: #a1a1aa;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.logout-btn:hover {
    background: #27272a;
    color: #fafafa;
}

.nav-link {
    color: #60a5fa;
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.15s;
}

.nav-link:hover {
    color: #93c5fd;
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 0;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 16px;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.2s ease-in;
}

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

.message-role {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.message-role.user {
    color: #60a5fa;
}

.message-role.assistant {
    color: #34d399;
}

.message-content {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 10px;
    padding: 14px 18px;
    line-height: 1.6;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content.user {
    background: #1e293b;
    border-color: #334155;
}

.message-content.error {
    background: #2d1b1b;
    border-color: #7f1d1d;
    color: #fca5a5;
}

/* ─── Metrics Panel ─────────────────────────────────────────────── */

.metrics-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 8px 12px;
    background: #1a1a2e;
    border: 1px solid #2d2d44;
    border-radius: 8px;
    font-size: 0.78rem;
}

.metric-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.metric-badge.model {
    background: #1e3a5f;
    color: #60a5fa;
    border: 1px solid #2563eb33;
}

.metric-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.metric-label {
    color: #71717a;
    font-weight: 500;
}

.metric-value {
    color: #d4d4d8;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
}

/* ─── Form ──────────────────────────────────────────────────────── */

#chat-form {
    border-top: 1px solid #27272a;
    padding-top: 16px;
}

.input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#prompt-input {
    flex: 1;
    background: #18181b;
    border: 1px solid #3f3f46;
    border-radius: 10px;
    padding: 12px 16px;
    color: #fafafa;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
}

#prompt-input:focus {
    border-color: #60a5fa;
}

#prompt-input::placeholder {
    color: #52525b;
}

#send-btn {
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

#send-btn:hover {
    background: #1d4ed8;
}

#send-btn:disabled {
    background: #1e3a5f;
    cursor: not-allowed;
    opacity: 0.6;
}

.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #52525b;
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Scrollbar */
#messages::-webkit-scrollbar {
    width: 6px;
}

#messages::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb {
    background: #3f3f46;
    border-radius: 3px;
}

@media (max-width: 600px) {
    #app {
        padding: 0 10px;
    }
    header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    .header-controls {
        width: 100%;
        justify-content: space-between;
    }
    #send-btn {
        padding: 12px 16px;
    }
    .metrics-panel {
        gap: 8px;
    }
}


/* ─── PDF Upload ──────────────────────────────────────────────── */

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: #18181b;
    border: 1px solid #3f3f46;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: border-color 0.15s;
}

.upload-btn:hover {
    border-color: #60a5fa;
}

.doc-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    font-size: 0.85rem;
}

.doc-badge {
    color: #60a5fa;
    font-weight: 500;
}

.doc-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.doc-remove:hover {
    background: #7f1d1d33;
}

/* ─── Cache Metrics ───────────────────────────────────────────── */

.cache-hit .metric-label {
    color: #34d399 !important;
}

.cache-write .metric-label {
    color: #fbbf24 !important;
}
