/* chat.css — Chat UI styling */

.guest-notice {
    background: rgba(184, 132, 43, 0.1);
    border-bottom: 1px solid rgba(184, 132, 43, 0.4);
    padding: 0.65rem 1.5rem;
    text-align: center;
    font-size: 0.95rem;
    color: var(--status-pending);
}

.guest-notice a {
    color: var(--adl-green);
    font-weight: 600;
    text-decoration: underline;
}

.chat-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-page);
    direction: rtl;
    overflow: hidden;
}

body[dir="ltr"] .chat-page {
    direction: ltr;
}

/* ── Header ── */
.chat-header {
    background: var(--white);
    border-bottom: 1px solid var(--border-light);
    padding: 12px 24px;
}

.chat-header .header-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header .logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.chat-header .header-logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.chat-header .header-titles {
    display: flex;
    flex-direction: column;
}

.chat-header .title-ar {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.3;
}

.chat-header .title-en {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.chat-header .header-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chat-header .header-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.chat-header .header-link:hover {
    color: var(--primary);
}

/* ── Container ── */
.chat-container {
    flex: 1;
    display: flex;
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
    padding: 0 16px;
}

/* ── Sidebar ── */
.chat-sidebar {
    width: 300px;
    background: var(--white);
    border-left: 1px solid var(--border-light);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

body[dir="ltr"] .chat-sidebar {
    border-left: none;
    border-right: 1px solid var(--border-light);
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.collected-info {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sidebar-empty {
    font-style: italic;
    color: var(--text-muted);
}

.sidebar-section {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
}

.sidebar-fields {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: 0.8rem;
}

.sidebar-fields dt {
    color: var(--text-secondary);
    font-weight: 500;
}

.sidebar-fields dd {
    color: var(--text-primary);
    margin: 0;
}

.sidebar-actions {
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

/* ── Main chat ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    margin: 16px 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

/* ── Messages area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* ── Message bubbles ── */
.chat-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.chat-message.user {
    align-self: flex-start;
}

body[dir="ltr"] .chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-end;
}

body[dir="ltr"] .chat-message.assistant {
    align-self: flex-start;
}

.chat-message.system {
    align-self: center;
    max-width: 90%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.user .message-bubble {
    background: var(--primary);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

body[dir="ltr"] .user .message-bubble {
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 12px;
}

.assistant .message-bubble {
    background: var(--bg-section);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

body[dir="ltr"] .assistant .message-bubble {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 12px;
}

.system .message-bubble {
    background: #EBF8FF;
    color: var(--info);
    font-size: 0.85rem;
    border-radius: 8px;
    text-align: center;
}

/* Markdown-rendered assistant bubbles */
.message-bubble.markdown-body {
    white-space: normal;
}

.message-bubble.markdown-body p {
    margin: 0 0 8px;
}

.message-bubble.markdown-body p:last-child {
    margin-bottom: 0;
}

.message-bubble.markdown-body strong {
    font-weight: 700;
}

.message-bubble.markdown-body em {
    font-style: italic;
}

.message-bubble.markdown-body ul,
.message-bubble.markdown-body ol {
    margin: 4px 0 8px;
    padding-right: 20px;
    padding-left: 0;
}

body[dir="ltr"] .message-bubble.markdown-body ul,
body[dir="ltr"] .message-bubble.markdown-body ol {
    padding-right: 0;
    padding-left: 20px;
}

.message-bubble.markdown-body li {
    margin-bottom: 4px;
}

.message-bubble.markdown-body li:last-child {
    margin-bottom: 0;
}

.message-bubble.markdown-body h1,
.message-bubble.markdown-body h2,
.message-bubble.markdown-body h3,
.message-bubble.markdown-body h4 {
    font-weight: 700;
    margin: 12px 0 6px;
    line-height: 1.4;
}

.message-bubble.markdown-body h1:first-child,
.message-bubble.markdown-body h2:first-child,
.message-bubble.markdown-body h3:first-child,
.message-bubble.markdown-body h4:first-child {
    margin-top: 0;
}

.message-bubble.markdown-body h1 { font-size: 1.15rem; }
.message-bubble.markdown-body h2 { font-size: 1.08rem; }
.message-bubble.markdown-body h3 { font-size: 1.02rem; }
.message-bubble.markdown-body h4 { font-size: 0.95rem; }

.message-bubble.markdown-body code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: monospace;
}

.message-bubble.markdown-body pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble.markdown-body pre code {
    background: none;
    padding: 0;
}

.message-bubble.markdown-body blockquote {
    border-right: 3px solid var(--primary);
    margin: 8px 0;
    padding: 4px 12px 4px 0;
    color: var(--text-secondary);
}

body[dir="ltr"] .message-bubble.markdown-body blockquote {
    border-right: none;
    border-left: 3px solid var(--primary);
    padding: 4px 0 4px 12px;
}

.message-bubble.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 10px 0;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Typing indicator ── */
.typing-indicator .typing-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 10px 16px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ── Input area ── */
.chat-input-area {
    background: var(--bg-section, #f9fafb);
    border-top: 1px solid var(--border-light);
    padding: 12px 20px;
}

.upload-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.upload-trigger {
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.upload-trigger:hover {
    color: var(--primary);
}

.doc-type-select {
    padding: 4px 8px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--white);
    font-family: inherit;
}

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

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-default);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
    direction: rtl;
}

body[dir="ltr"] .chat-input {
    direction: ltr;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

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

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* ── Success panel ── */
.chat-success {
    text-align: center;
    padding: 60px 24px;
}

.chat-success .success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--success);
    color: var(--white);
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.chat-success h2 {
    color: var(--text-primary);
    margin-bottom: 12px;
}

.chat-success p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.success-case-number {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    direction: ltr;
    unicode-bidi: plaintext;
}

.success-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .chat-sidebar {
        display: none;
    }

    .chat-container {
        padding: 0 8px;
    }

    .chat-main {
        margin: 8px 0;
        border-radius: 8px;
    }

    .chat-header .header-inner {
        flex-wrap: wrap;
        gap: 8px;
    }

    .chat-header .header-nav {
        gap: 8px;
        flex-wrap: wrap;
    }

    .chat-header .header-link {
        font-size: 0.8rem;
    }

    .chat-messages {
        padding: 14px 12px;
    }

    .chat-message {
        max-width: 92%;
    }

    .chat-input-area {
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 0 4px;
    }

    .chat-main {
        margin: 4px 0;
        border-radius: 6px;
    }

    .chat-header .header-titles {
        display: none;
    }

    .chat-header .header-logo-img {
        width: 36px;
        height: 36px;
    }
}
