:root {
    --bg-primary: #0F0F0F;
    --bg-secondary: #1A1A1A;
    --bg-tertiary: #242424;
    --text-primary: #ECECEC;
    --text-secondary: #8E8E8E;
    --border-color: #2A2A2A;
    --accent: #6366F1;
    --accent-hover: #5558E3;
    --danger: #EF4444;
    --danger-hover: #DC2626;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Auth Screen */
.screen {
    width: 100%;
    height: 100%;
}

#auth-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 48px 40px;
    text-align: center;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.auth-logo {
    font-size: 48px;
    margin-bottom: 16px;
}

.auth-container h1 {
    margin-bottom: 8px;
    font-size: 28px;
    font-weight: 600;
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

.tabs {
    display: flex;
    margin-bottom: 24px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: 8px;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

input, textarea {
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.primary-btn {
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

.secondary-btn {
    padding: 14px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.danger-btn {
    padding: 14px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* App Screen */
#app-screen {
    display: flex;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--bg-tertiary);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.thread-item {
    position: relative;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
}

.thread-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.thread-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.thread-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-delete {
    opacity: 0;
    padding: 4px 8px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.thread-item:hover .thread-delete {
    opacity: 1;
}

.thread-delete:hover {
    background: var(--danger);
    color: white;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.footer-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.2s;
}

.footer-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 120px;
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h2 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 24px;
    font-weight: 500;
}

.empty-state p {
    font-size: 14px;
}

.message {
    padding: 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.message.assistant {
    background: var(--bg-secondary);
}

.message-content {
    max-width: 768px;
    margin: 0 auto;
    display: flex;
    gap: 16px;
    line-height: 1.6;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 13px;
}

.user .avatar {
    background: linear-gradient(135deg, var(--accent) 0%, #8B5CF6 100%);
    color: white;
}

.assistant .avatar {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
}

.text {
    flex: 1;
    overflow-wrap: break-word;
    font-size: 15px;
}

/* Input Area */
.input-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(180deg, transparent, var(--bg-primary) 40%);
    padding: 24px 16px;
}

.input-box {
    max-width: 768px;
    margin: 0 auto;
    position: relative;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    padding: 12px;
    gap: 8px;
}

textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    max-height: 200px;
    padding: 4px 8px;
    line-height: 1.5;
}

.send-btn {
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:not(:disabled):hover {
    background: var(--accent-hover);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: default;
    background: var(--bg-tertiary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.setting-item label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 14px;
}

.setting-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.confirm-modal {
    max-width: 400px;
}

.confirm-modal .modal-body p {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Notification */
.notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 14px;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

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

/* Markdown Styles */
.text p { margin-bottom: 1em; }
.text p:last-child { margin-bottom: 0; }
.text code { 
    background: var(--bg-tertiary); 
    padding: 2px 6px; 
    border-radius: 4px; 
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}
.text pre { 
    background: var(--bg-tertiary); 
    padding: 16px; 
    border-radius: 8px; 
    overflow-x: auto; 
    margin: 12px 0;
    border: 1px solid var(--border-color);
}
.text pre code { 
    background: transparent; 
    padding: 0; 
}
.text ul, .text ol {
    margin-left: 20px;
    margin-bottom: 1em;
}
.text li {
    margin-bottom: 0.5em;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
