/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #0d0d0f;
    --bg2:       #141416;
    --bg3:       #1c1c1f;
    --border:    #2a2a2e;
    --accent:    #7c6af7;
    --accent2:   #5b4de0;
    --text:      #e8e8f0;
    --text-muted:#8888a0;
    --user-msg:  #1e1b3a;
    --ai-msg:    #141416;
    --radius:    12px;
    --sidebar-w: 260px;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ===== AUTH PAGE ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 0%, #1a1040 0%, var(--bg) 70%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 40px 32px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 28px;
}

.logo-icon {
    font-size: 2rem;
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent));
}

.logo-icon.big { font-size: 4rem; }

.logo-img {
    display: block;
    height: auto;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(124, 106, 247, 0.45));
}

.logo-img--sidebar {
    max-height: 32px;
}

.logo-img--big {
    max-height: 96px;
    max-width: min(280px, 90vw);
}

.logo-img--auth {
    max-height: 44px;
    max-width: min(140px, 55vw);
    margin: 0 auto;
}

.auth-tabs {
    display: flex;
    background: var(--bg3);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 24px;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    padding: 9px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.auth-error {
    background: rgba(220, 60, 60, 0.15);
    border: 1px solid rgba(220, 60, 60, 0.4);
    color: #ff7070;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    padding: 11px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus { border-color: var(--accent); }

.btn-primary {
    margin-top: 4px;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: var(--accent2); }
.btn-primary:active { transform: scale(0.98); }

/* ===== CHAT LAYOUT ===== */
.chat-page {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
}

.logo-text {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #a89af7, #7c6af7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 10px;
    padding: 10px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-new-chat:hover { background: var(--accent2); }

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 6px;
}

.history-item:hover { background: var(--bg3); }
.history-item.active { background: rgba(124, 106, 247, 0.15); border: 1px solid rgba(124,106,247,0.3); }

.history-title {
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.history-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    font-size: 0.8rem;
}

.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: #ff6060; }

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.user-avatar {
    width: 30px;
    height: 30px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
}

.btn-logout {
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    transition: color 0.2s, background 0.2s;
}

.btn-logout:hover { color: #ff6060; background: rgba(255,96,96,0.1); }

/* ===== MAIN CHAT ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: var(--text-muted);
    padding: 60px 20px;
}

.welcome-screen h2 {
    font-size: 1.5rem;
    color: var(--text);
    font-weight: 600;
}

.welcome-screen p { font-size: 0.95rem; }

/* Messages */
.message {
    padding: 16px 24px;
    display: flex;
    gap: 14px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.message.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .msg-avatar {
    background: var(--accent);
    color: #fff;
}

.message.assistant .msg-avatar {
    background: var(--bg3);
    color: var(--accent);
    border: 1px solid var(--border);
    font-size: 1rem;
}

.msg-content {
    max-width: calc(100% - 50px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user .msg-bubble {
    background: var(--user-msg);
    border: 1px solid rgba(124,106,247,0.25);
    border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
    background: var(--ai-msg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-image {
    max-width: 280px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 16px;
    align-items: center;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    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); }
}

/* ===== INPUT AREA ===== */
.chat-input-area {
    padding: 16px 24px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    max-width: 860px;
    margin: 0 auto;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within { border-color: var(--accent); }

.image-preview {
    padding: 10px 14px 0;
    position: relative;
    display: inline-block;
}

.image-preview img {
    height: 80px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.remove-image {
    position: absolute;
    top: 6px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
}

.attach-btn {
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.attach-btn:hover { color: var(--accent); background: rgba(124,106,247,0.1); }

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 0.95rem;
    resize: none;
    max-height: 160px;
    line-height: 1.5;
    padding: 6px 0;
    font-family: inherit;
}

#messageInput::placeholder { color: var(--text-muted); }

.send-btn {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.send-btn:hover { background: var(--accent2); }
.send-btn:active { transform: scale(0.95); }
.send-btn.stop { background: #c0392b; }
.send-btn.stop:hover { background: #a93226; }

/* ===== CUSTOM MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.visible { opacity: 1; }

.modal-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px 28px 24px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
    transform: translateY(12px) scale(0.97);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.visible .modal-box {
    transform: translateY(0) scale(1);
}

.modal-icon {
    font-size: 2.2rem;
    line-height: 1;
    margin-bottom: 4px;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
}

.modal-message {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    width: 100%;
}

.modal-btn {
    flex: 1;
    padding: 11px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.modal-btn:active { transform: scale(0.97); }

.btn-cancel {
    background: var(--bg3);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-cancel:hover { background: var(--border); color: var(--text); }

.btn-danger {
    background: rgba(192, 57, 43, 0.85);
    color: #fff;
}

.btn-danger:hover { background: #c0392b; }
