/* Chat Auth Pages */
.chat-auth-page {
    max-width: 420px;
    margin: 2rem auto;
}
.chat-auth-page h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}
.chat-auth-intro {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}
.chat-auth-form {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}
.chat-auth-form .btn {
    width: 100%;
    margin-top: 0.5rem;
}
.chat-auth-link {
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-600);
}
.form-error {
    display: block;
    font-size: 0.8rem;
    color: #c5221f;
    margin-top: 0.25rem;
}

/* ===== Chat Layout (fixed full-height) ===== */
.body-chat {
    overflow: hidden;
    height: 100vh;
}

.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 49px); /* viewport minus header */
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
}

.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    overflow: hidden;
}

.chat-sidebar {
    width: 300px;
    flex-shrink: 0;
    padding: 1rem;
    overflow-y: auto;
    border-left: 1px solid var(--gray-200);
}
.chat-sidebar .ad-slot {
    margin: 0;
}
.chat-sidebar .ad-slot img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
}

/* ===== Chat Page (inside chat-main) ===== */
.chat-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0.75rem 1.5rem;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.chat-header h1 {
    font-size: 1.25rem;
}
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.chat-user {
    font-size: 0.85rem;
    color: var(--gray-600);
}
.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}
.btn-outline {
    background: transparent;
    color: var(--gray-600);
    border-color: var(--gray-200);
}
.btn-outline:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem 0.75rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}
.chat-welcome {
    text-align: center;
    color: var(--gray-600);
    padding: 3rem 1rem;
    font-size: 0.95rem;
}
.chat-msg {
    max-width: 80%;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    line-height: 1.5;
    font-size: 0.9rem;
}
.chat-msg--user {
    align-self: flex-end;
    background: var(--blue);
    color: var(--white);
}
.chat-msg--user .chat-msg-label {
    color: rgba(255,255,255,0.7);
}
.chat-msg--assistant {
    align-self: flex-start;
    background: var(--gray-100);
    color: var(--gray-900);
}
.chat-msg-label {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.chat-msg-content {
    word-break: break-word;
}

/* Thinking Indicator */
.thinking-dots span {
    display: inline-block;
    font-size: 1.5rem;
    line-height: 1;
    animation: thinkBounce 1.4s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinkBounce {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-4px); }
}

/* Input Form */
.chat-input-form {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition);
}
.chat-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26,115,232,.15);
}
.chat-send {
    flex-shrink: 0;
}
.chat-send:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ===== Responsive ===== */

/* Tablet & mobile: hide sidebar */
@media (max-width: 1024px) {
    .chat-sidebar {
        display: none;
    }
}

@media (max-width: 768px) {
    .chat-layout {
        height: calc(100vh - 45px);
    }
    .chat-page {
        padding: 0.5rem 0.5rem;
    }
    .chat-msg {
        max-width: 90%;
    }
    .chat-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .chat-user {
        display: none;
    }
}
