* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    height: 100vh;
    background: #f5f5f5;
    color: #333;
}

.auth-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
}

.auth-toggle-btn {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #666;
    transition: all 0.2s;
    border-radius: 8px;
}

.auth-toggle-btn.active {
    color: #0070f3;
    background: #f0f7ff;
}

.auth-toggle-btn:hover {
    color: #0070f3;
    background: #f5f5f5;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: 320px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.user-info {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.user-info h2 {
    font-size: 1.4rem;
    color: #1a1a1a;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-email {
    font-size: 0.9rem;
    color: #666;
    background: #f5f5f5;
    padding: 8px 12px;
    border-radius: 20px;
    word-break: break-all;
}

.memory-toggle {
    margin-bottom: 20px;
    padding: 15px;
    background: #f0f7ff;
    border-radius: 12px;
    border: 1px solid #e1f0ff;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: #1a1a1a;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.toggle-text {
    font-size: 1rem;
}

.toggle-hint {
    font-size: 0.8rem;
    color: #666;
    margin-top: 8px;
    margin-left: 28px;
}

.pdf-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

.pdf-list h3 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pdf-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pdf-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    background: #f8f9fa;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.pdf-item:hover {
    background: #e9ecef;
    border-color: #0070f3;
    transform: translateX(2px);
}

.pdf-icon {
    font-size: 1.5rem;
}

.pdf-details {
    flex: 1;
}

.pdf-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.pdf-date {
    font-size: 0.75rem;
    color: #999;
    margin-bottom: 4px;
}

.pdf-tags {
    font-size: 0.7rem;
    color: #0070f3;
    background: #e6f2ff;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 30px 20px;
    font-style: italic;
    background: #fafafa;
    border-radius: 8px;
}

.error-state {
    text-align: center;
    color: #dc3545;
    padding: 20px;
    background: #ffe6e6;
    border-radius: 8px;
}

.new-chat-btn {
    padding: 14px;
    background: #0070f3;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.new-chat-btn:hover {
    background: #0051b3;
}

.logout-btn {
    width: 100%;
    padding: 10px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 15px;
    font-weight: 500;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: #d32f2f;
}

/* ==================== CHAT AREA ==================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-header {
    padding: 20px 30px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.chat-header h3 {
    font-size: 1.2rem;
    color: #333;
}

.memory-indicator {
    font-size: 0.85rem;
    color: #28a745;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: fadeInOut 3s ease;
}

@keyframes fadeInOut {
    0% { opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { opacity: 0; }
}

.save-btn {
    padding: 10px 20px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-btn:hover {
    background: #218838;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #fafafa;
}

.welcome-message {
    text-align: center;
    max-width: 500px;
    margin: 50px auto;
    padding: 40px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.welcome-message h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.welcome-message p {
    color: #666;
    line-height: 1.6;
    margin-bottom: 15px;
}

.message {
    max-width: 70%;
    padding: 15px 20px;
    border-radius: 18px;
    line-height: 1.5;
    position: relative;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: #0070f3;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ai-message {
    background: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.message-content {
    font-size: 1rem;
    white-space: pre-wrap;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 5px;
    text-align: right;
}

.typing-indicator {
    background: #e9ecef;
    color: #666;
    padding: 15px 25px;
}

.typing-indicator .dots {
    animation: blink 1.4s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

.input-area {
    padding: 20px 30px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 15px;
    background: white;
}

textarea {
    flex: 1;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: #0070f3;
    box-shadow: 0 0 0 3px rgba(0,112,243,0.1);
}

.send-btn {
    padding: 0 35px;
    background: #0070f3;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: background 0.2s;
}

.send-btn:hover {
    background: #0051b3;
}

/* ==================== MODAL ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 24px;
    width: 700px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 10px;
    color: #1a1a1a;
}

.modal-subtitle {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.tier-cards {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.tier-card {
    flex: 1;
    min-width: 150px;
    padding: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tier-card:hover {
    border-color: #0070f3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.tier-card.selected {
    border-color: #0070f3;
    background: #f0f7ff;
}

.tier-card.popular {
    border-color: #0070f3;
    background: #f8fbff;
}

.popular-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #0070f3;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.tier-card h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #333;
}

.price {
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 15px;
}

.price span {
    font-size: 0.9rem;
    font-weight: normal;
    color: #666;
}

.tier-card ul {
    list-style: none;
    padding: 0;
}

.tier-card li {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.email-input {
    width: 100%;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.email-input:focus {
    outline: none;
    border-color: #0070f3;
}

.start-btn {
    width: 100%;
    padding: 15px;
    background: #0070f3;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
    transition: background 0.2s;
    margin-bottom: 15px;
}

.start-btn:hover {
    background: #0051b3;
}

.terms {
    text-align: center;
    color: #999;
    font-size: 0.85rem;
}

/* ==================== TEST PANEL ==================== */
.test-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    z-index: 100;
    width: 300px;
    border: 1px solid #e0e0e0;
}

.test-header {
    padding: 12px 15px;
    background: #f5f5f5;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    border-bottom: 1px solid #e0e0e0;
}

.test-header button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #666;
}

.test-content {
    padding: 15px;
}

.test-content button {
    width: 100%;
    padding: 10px;
    background: #0070f3;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 10px;
}

.test-result {
    padding: 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    word-break: break-all;
    max-height: 100px;
    overflow-y: auto;
}

.test-result.testing {
    background: #fff3cd;
    color: #856404;
}

.test-result.success {
    background: #d4edda;
    color: #155724;
}

.test-result.error {
    background: #f8d7da;
    color: #721c24;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .messages {
        padding: 15px;
    }
    
    .input-area {
        padding: 15px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .tier-cards {
        flex-direction: column;
    }
    
    .tier-card {
        width: 100%;
    }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}