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

body {
    background-color: #f8fafc;
    display: flex;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
    color: #1e293b;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-family: 'Tajawal', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px; 
}

textarea, input[type="text"] {
    font-family: 'Tajawal', 'Inter', sans-serif !important;
    font-size: 16px !important;
}

.chat-message, .message-content {
    font-weight: 500;
    font-size: 16px;
    line-height: 1.7;
}

body, input, textarea, .chat-message, .message-content, .chat-box *, p, span, div {
    font-family: 'Tajawal', 'Inter', sans-serif !important;
}

/* === ?????? ????? === */
.circle1, .circle2 {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.25;
    z-index: 1;
    pointer-events: none;
}
.circle1 {
    width: clamp(250px, 40vw, 450px);
    height: clamp(250px, 40vw, 450px);
    top: -120px;
    left: -120px;
    background: radial-gradient(circle, #3b82f6, #4f46e5);
}
.circle2 {
    width: clamp(300px, 50vw, 550px);
    height: clamp(300px, 50vw, 550px);
    bottom: -180px;
    right: -120px;
    background: radial-gradient(circle, #60a5fa, #a5f3fc);
}

/* === ?????? ??????? Sidebar === */
#sidebar {
    width: 270px;
    height: 100%;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    border-right: 1px solid rgba(226, 232, 240, 0.8);
    display: flex; 
    flex-direction: column;
    padding: 16px;
    z-index: 100;
    overflow: hidden !important;
    white-space: nowrap !important;
    will-change: transform, opacity;
    transform: translateX(0);
    opacity: 1;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                width 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.2s ease,
                visibility 0.25s;
    visibility: visible;
    flex-shrink: 0;
}

#sidebar.closed, #sidebar:not(.open) {
    transform: translateX(-100%);
    width: 0;
    opacity: 0;
    visibility: hidden;
    border: none;
    margin: 0;
    padding: 0;
}

#sidebar.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.history-item, #sidebar span, #sidebar button {
    transition: opacity 0.2s ease-in-out;
}

.new-chat-btn {
    background: #f1f5f9;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    margin-bottom: 20px;
    caret-color: transparent;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
}
.new-chat-btn:hover { 
    background: #e2e8f0; 
}

.recent-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100%; 
}
.recent-title {
    caret-color: transparent;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 10px;
    color: #64748b;
    text-align: right;
    padding-right: 4px;
    letter-spacing: 0.3px;
}

.chat-history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    height: max-content; 
    margin-bottom: auto; 
}
.history-item {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: all 0.2s ease;
}
.history-item:hover { 
    background: rgba(241, 245, 249, 0.8);
}
.history-item.active-chat {
    background: #e2e8f0;
    font-weight: 600; 
    caret-color: transparent;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.delete-chat-btn {
  opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.history-item:hover .delete-chat-btn {
    opacity: 1;
}
.delete-chat-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
}

.login-section {
    border-top: 1px solid #e2e8f0;
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.login-btn {
    width: 100%;
    background: none;
    border: none;
    padding: 10px;
    border-radius: 10px;
    color: #1e3a8a;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s ease;
    caret-color: transparent;
}
.login-btn:hover {
    background: rgba(59, 130, 246, 0.08);
}

/* === ????? ?????? ??????? Main Content === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#menu-toggle, #chat-menu-toggle {
    position: absolute;
    top: 8px;
    left: 12px;
    z-index: 30;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: none; 
    justify-content: center;
    align-items: center;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    transition: transform 0.2s ease, background-color 0.2s ease;
}
#menu-toggle:hover, #chat-menu-toggle:hover {
    transform: scale(1.05);
}
body.has-chats #menu-toggle {
    display: flex !important;
}


/* === ???? ??????? Welcome Screen === */
#welcome-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    width: 90%;
    max-width: 680px;
    padding: 20px;
    text-align: center;
    transition: opacity 0.4s ease, transform 0.4s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#welcome-screen h1 {
    color: #1e3a8a; 
    margin-bottom: 10px; 
    font-weight: 700;
    user-select: none;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    letter-spacing: -0.5px;
}

.search-box-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.search-box {
    display: flex;
    align-items: flex-end; 
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 10px 14px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.07);
    transition: all 0.25s ease;
    gap: 10px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    width: 100%;
}
.search-box:focus-within {
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.1);
}
.search-box.error, 
.input-wrapper.error,
#inputWrapper.error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.25);
}

.plus-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #64748b;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    caret-color: transparent;
    flex-shrink: 0;
    margin-bottom: 2px;
}
.plus-btn:hover { 
    background: rgba(241, 245, 249, 0.9); 
    color: #1e293b; 
    transform: scale(1.05);
}

.popup-menu {
    position: absolute;
    bottom: 70px;
    left: 0;
    width: 100%;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.12);
    border: 1px solid #e2e8f0;
    display: none;
    flex-direction: column;
    padding: 8px;
    z-index: 100;
    text-align: left;
    animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.popup-menu.active {
    display: flex; 
}
.popup-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    color: #334155;
    cursor: pointer;
    transition: background 0.2s;
    caret-color: transparent;
}
.popup-item:hover { 
    background: #f8fafc; color: #000; 
}
.popup-item span.icon { 
    font-size: 18px; 
}

.input-field {
    flex-grow: 1;
    border: none;
    outline: none;
    padding: 6px 4px;
    font-size: 1rem;
    color: #1e293b;
    background: transparent;
    resize: none;
    max-height: 180px;
    overflow-y: auto;
    word-break: break-word;
    line-height: 1.5;
    direction: auto;
    unicode-bidi: plaintext;
    

    
}
.input-field::placeholder {
    color: #94a3b8;
    opacity: 1;
  
}

/* === ????? ???????? Chat Screen === */
#chat-screen {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    position: relative;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.4s ease;
    background-color: transparent; 
}

.chat-header {
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    padding: 16px 20px;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    color: #1e293b;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
        user-select: none; 
    caret-color: transparent;
}

.chat-scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    caret-color: transparent;
}

#chat-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
}

.message {
    width: fit-content; 
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    direction: auto;
    unicode-bidi: plaintext;
    text-align: start;
}

.user-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    word-break: break-word;
    white-space: pre-wrap;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: #ffffff;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.25);
}

.bot-message, .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    word-break: break-word;
    white-space: normal !important;
    background-color: #ffffff;
    color: #1e293b;
    align-self: flex-start;
    margin-right: auto;
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
    direction: auto !important;         
    unicode-bidi: plaintext !important;
    text-align: start !important;       
    /* width: 100% !important; */
    overflow-x: auto !important;
}

/* === ?????? ?????? ???????? === */
.preview-thumb { 
    max-width: 140px; 
    max-height: 140px; 
    border-radius: 10px; 
    margin-bottom: 6px; 
    display: block; 
    cursor: pointer; 
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.preview-thumb:hover {
    opacity: 0.92; 
}

#imageModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 7, 12, 0.92);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    overflow: hidden;
    animation: fadeIn 0.2s ease;
}
#imageModal.active { 
    display: flex; 
}

.modal-close-fixed {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 100000;
}
.modal-close-fixed:hover { 
    background: rgba(239, 68, 68, 0.9); 
    border-color: #ef4444;
}

.modal-content-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: auto;
    height: auto;
}

#modalImage {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.7);
    object-fit: contain;
}

.modal-zoom-controls {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: rgba(15, 23, 42, 0.85);
    padding: 8px 16px;
    border-radius: 30px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 100000;
}
.zoom-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}
.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}


.input-area {
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    padding: 14px 16px;
    border-top: 1px solid rgba(226, 232, 240, 0.8);
}

.input-wrapper {
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    background-color: #f1f5f9;
    padding: 8px 12px;
    border-radius: 24px;
    align-items: flex-end;
    border: 1px solid rgba(226, 232, 240, 0.8);
    transition: all 0.25s ease;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.03);
    position: relative;
}
.input-wrapper:focus-within {
    background-color: #ffffff;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}

#send-btn-welcome, #send-btn-chat {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: #ffffff;
    border: none;
    font-size: 20px;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#send-btn-welcome:hover, #send-btn-chat:hover { 
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4) !important;
}

#send-btn-chat.stop-mode {
    border-radius: 50% !important; 
    background: #ef4444 !important;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#send-btn-chat.stop-mode svg {
    width: 16px !important;
    height: 16px !important;
}

.image-preview-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.loading-dots { 
    display: flex; 
    gap: 5px; 
    justify-content: center; 
    align-items: center; 
    padding: 6px 0;
}
.loading-dots span {
    width: 8px; 
    height: 8px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

/* === Scrollbars === */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}

/* === Animations === */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.bot-message p, .message-content p {
    margin-top: 0 !important;
    margin-bottom: 2px !important;
    line-height: 1.5 !important;
}

.bot-message ul, .message-content ul,
.bot-message ol, .message-content ol {
    list-style-position: inside !important; 
    padding-inline-start: 0 !important;  
    margin-top: 2px !important;
    margin-bottom: 4px !important;
}  

.bot-message li, .message-content li {
    margin-top: 0 !important;
    margin-bottom: 2px !important; 
    padding-right: 0 !important; 
    line-height: 1.4 !important;
    display: list-item !important;
    text-align: start !important;
    unicode-bidi: plaintext !important;
}

.bot-message li p, .message-content li p {
    margin: 0 !important;
    display: inline !important;
}

.bot-message h1, .bot-message h2, .bot-message h3, .bot-message h4,
.message-content h1, .message-content h2, .message-content h3, .message-content h4 {
margin-top: 6px !important;
    margin-bottom: 2px !important;
    line-height: 1.3 !important;
}

table {
  width: 100%;
  table-layout: fixed; 
  border-collapse: collapse;
}

th, td {
  padding: 12px 10px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-align: center; 
  vertical-align: middle;
}

.bot-message table, .message-content table {
    display: table !important;          
    border-spacing: 0 !important;
margin: 4px 0 8px 0 !important;
    width: max-content !important;        /* ?????? ?????? ??????? ???? ?????? ????? ?????? ??????? */
    min-width: 100% !important;           /* ??? ??? ?? ??? ??????? */
    table-layout: auto !important;                
    border-collapse: collapse !important;
    font-size: 14px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}
.bot-message th, .message-content th,
.bot-message td, .message-content td {
    white-space: nowrap !important;
}
.bot-message p:has(+ table), 
.message-content p:has(+ table) {
    margin-bottom: 2px !important;
}

.bot-message th, .message-content th {
    background-color: #f1f5f9;
    color: #0f172a;
    font-weight: 700;
    padding: 12px 11px !important;
    text-align: right !important;
    border-bottom: 2px solid #cbd5e1;
    white-space: nowrap !important;
}

.bot-message td, .message-content td {
    padding: 12px 16px !important;
    text-align: right !important;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.2s ease;
    direction: rtl;
white-space: nowrap !important;
}

.bot-message tr:nth-child(even), .message-content tr:nth-child(even) {
    background-color: #f8fafc;
}

.bot-message tr:hover td, .message-content tr:hover td {
    background-color: #e2e8f0;
}

.bot-message tr:last-child td, .message-content tr:last-child td {
    border-bottom: none;
}

.bot-message td *, .message-content td * {
    unicode-bidi: isolate; 
}


@media (max-width: 768px) {
    #sidebar { 
        position: fixed; 
        top: 0; 
        left: 0; 
        bottom: 0;
        height: 100%;
        box-shadow: 4px 0 25px rgba(0,0,0,0.15);
        z-index: 1000;
    }

    .chat-header { 
        padding-left: 55px; 
        padding-right: 55px; 
        font-size: 15px;
    caret-color: transparent;
    }

    .message {
        max-width: 90%;
        font-size: 15px;
    }

    .input-area {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 15px;
    }

    .circle1, .circle2 {
        display: none;
    }

    .message {
        max-width: 94%;
        padding: 10px 14px;
        font-size: 14.5px;
    }

    .chat-scroll-wrapper {
        padding: 12px 8px;
    }

    #welcome-screen {
        width: 95%;
        padding: 10px;
    }

    .search-box, .input-wrapper {
        padding: 8px 10px;
        user-select: none;
 
    }

    .plus-btn {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    #send-btn-welcome, #send-btn-chat {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

@media (min-width: 1400px) {
    #chat-container, .input-wrapper, .search-box-container {
        max-width: 960px;
        user-select: none;

    }
}

/* ???? ???? ???? ???????? ?????? ????? ?????? */
#welcomeForm.input-error,
.search-box.input-error {
    border: 1.5px solid #ef4444 !important;
    box-shadow: none !important;
    animation: none !important;
    user-select: none;
}

#welcomeForm.input-error .input-field::placeholder,
.search-box.input-error .input-field::placeholder {
    color: #ef4444 !important;
    opacity: 1 !important;
 user-select: none;
}
.auth-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.auth-modal-card {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  color: #f8fafc;
  direction: rtl;
}

.auth-header h2 {
  margin: 0 0 6px 0;
  font-size: 1.5rem;
  color: #fff;
}

.auth-header p {
  margin: 0 0 20px 0;
  font-size: 0.875rem;
  color: #94a3b8;
}

.auth-field {
  margin-bottom: 16px;
  text-align: right;
}

.auth-field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: #cbd5e1;
}

.auth-field input {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.auth-field input:focus {
  border-color: #3b82f6;
}

.auth-btn {
  width: 100%;
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}

.auth-btn:hover {
  background: #1d4ed8;
}

.auth-error-msg {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #ef4444;
  color: #fca5a5;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  text-align: center;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 0.875rem;
  color: #94a3b8;
}

.auth-footer a {
  color: #3b82f6;
  text-decoration: none;
  font-weight: 600;
  margin-right: 6px;
}

.auth-footer a:hover {
  text-decoration: underline;
}


/* Message question navigator */
.message-navigator {
    position: fixed;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 80;

    display: flex;
    align-items: center;

    padding: 16px 4px 16px 24px;
}

/* فقط الخطوط تكون ظاهرة */
.message-nav-lines {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 7px;

    padding: 8px 2px;
}

.message-nav-marker {
    width: 24px;
    height: 4px;

    padding: 0;
    margin: 0;

    border: 0;
    border-radius: 999px;

    background: rgba(8, 125, 241, 0.28);

    cursor: pointer;

    transition:
        width 0.18s ease,
        height 0.18s ease,
        background 0.18s ease,
        box-shadow 0.18s ease;
}

.message-nav-marker:hover {
    width: 32px;
    background: rgba(8, 125, 241, 0.65);
}

.message-nav-marker.active {
    width: 38px;
    height: 5px;

    background: #087df1;

    box-shadow:
        0 0 0 3px rgba(8, 125, 241, 0.10),
        0 4px 12px rgba(8, 125, 241, 0.25);
}


/* المربع مخفي افتراضيًا */
.message-nav-panel {
    position: absolute;

    right: 54px;
    top: 50%;

    width: 320px;
    max-height: 420px;

    transform: translateY(-50%) translateX(10px);

    background: rgba(255, 255, 255, 0.98);

    border: 1px solid rgba(90, 120, 160, 0.18);
    border-radius: 16px;

    box-shadow:
        0 12px 36px rgba(40, 70, 110, 0.17);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition:
        opacity 0.18s ease,
        transform 0.18s ease,
        visibility 0.18s ease;

    overflow: hidden;
}


/* يظهر فقط عند وضع الماوس على منطقة الخطوط */
.message-navigator:hover .message-nav-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;

    transform: translateY(-50%) translateX(0);
}


/* رأس المربع */
.message-nav-panel-header {
    padding: 13px 15px;

    font-size: 13px;
    font-weight: 700;

    color: #27384f;

    border-bottom: 1px solid rgba(90, 120, 160, 0.10);

    background: rgba(248, 251, 255, 0.95);
}


/* قائمة الرسائل */
.message-nav-panel-list {
    max-height: 355px;

    overflow-y: auto;
    overflow-x: hidden;

    padding: 6px;
}


/* كل رسالة كسطر مستقل */
.message-nav-list-item {
    width: 100%;

    display: flex;
    align-items: center;

    gap: 9px;

    padding: 10px 11px;
    margin: 0;

    border: 0;
    border-radius: 10px;

    background: transparent;

    cursor: pointer;

    text-align: start;

    font-family: inherit;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.message-nav-list-item:hover {
    background: rgba(8, 125, 241, 0.07);
}

.message-nav-list-item.active {
    background: rgba(8, 125, 241, 0.11);
}


/* رقم الرسالة */
.message-nav-list-number {
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 24px;
    height: 24px;

    border-radius: 7px;

    background: rgba(8, 125, 241, 0.10);

    color: #087df1;

    font-size: 11px;
    font-weight: 700;
}

.message-nav-list-item.active .message-nav-list-number {
    background: #087df1;
    color: #fff;
}


/* نص رسالة المستخدم */
.message-nav-list-text {
    flex: 1;
    min-width: 0;

    font-size: 13px;
    line-height: 1.4;

    color: #33445c;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-nav-list-item.active .message-nav-list-text {
    color: #087df1;
    font-weight: 600;
}


/* Scrollbar */
.message-nav-panel-list::-webkit-scrollbar {
    width: 5px;
}

.message-nav-panel-list::-webkit-scrollbar-track {
    background: transparent;
}

.message-nav-panel-list::-webkit-scrollbar-thumb {
    background: rgba(90, 120, 160, 0.28);
    border-radius: 999px;
}


/* Mobile */
@media (max-width: 768px) {
    .message-navigator {
        right: 6px;
        padding-left: 18px;
    }

    .message-nav-panel {
        width: 250px;
        right: 44px;
    }

    .message-nav-marker {
        width: 18px;
    }

    .message-nav-marker:hover {
        width: 23px;
    }

    .message-nav-marker.active {
        width: 28px;
    }

    .message-nav-list-text {
        font-size: 12px;
    }
}


/* ===== Chat 3-dot options menu ===== */

.chat-menu-wrapper {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
}

.chat-menu-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #64748b;
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-menu-btn:hover {
    background: rgba(8, 125, 241, 0.08);
    color: #087df1;
}

.chat-options-menu {
    position: absolute;
    right: 0;
    top: 31px;
    width: 150px;
    padding: 5px;
    display: none;
    background: #ffffff;
    border: 1px solid rgba(100, 116, 139, 0.18);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(30, 50, 80, 0.18);
    z-index: 500;
}

.chat-options-menu.open {
    display: block;
}

.chat-option-item {
    width: 100%;
    padding: 9px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #334155;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.chat-option-item:hover {
    background: rgba(8, 125, 241, 0.08);
}

.chat-option-item.delete-option {
    color: #dc2626;
    margin-top: 3px;
    border-top: 1px solid rgba(100, 116, 139, 0.12);
}

.chat-option-item.delete-option:hover {
    background: rgba(220, 38, 38, 0.08);
}

.history-item {
    overflow: visible;
}

/* Show chat menu button only on hover */
.history-item .chat-menu-btn {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease, background 0.15s ease;
}

.history-item:hover .chat-menu-btn,
.history-item .chat-menu-btn:focus,
.history-item:focus-within .chat-menu-btn {
    opacity: 1;
    visibility: visible;
}

/* Keep the menu button visible while its popup is open */
.history-item:has(.chat-options-menu.open) .chat-menu-btn {
    opacity: 1;
    visibility: visible;
}

/* ===== Final chat menu fixes ===== */

.history-item .chat-menu-btn {
    opacity: 0;
    visibility: hidden;
}

.history-item:hover .chat-menu-btn,
.history-item:focus-within .chat-menu-btn {
    opacity: 1;
    visibility: visible;
}

.history-item:has(.chat-options-menu.open) .chat-menu-btn {
    opacity: 1;
    visibility: visible;
}

#sidebar .chat-options-menu {
    position: absolute;
    right: 0;
    top: 32px;
    width: 165px;
    height: auto;
    min-height: 0;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    overflow: visible;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    z-index: 9999;
}

#sidebar .chat-options-menu.open {
    display: flex;
}

#sidebar .chat-options-menu .chat-option-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    height: auto;
    min-height: 38px;
    margin: 0;
    padding: 9px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #334155;
    font-family: inherit;
    font-size: 13px;
    font-weight: 400;
    line-height: 20px;
    text-align: left;
    white-space: nowrap;
    opacity: 1;
    visibility: visible;
}

#sidebar .chat-options-menu .chat-option-item:hover {
    background: #f1f5f9;
}

#sidebar .chat-options-menu .delete-option {
    color: #dc2626;
    border-top: 1px solid #e2e8f0;
    margin-top: 3px;
    padding-top: 10px;
}

#sidebar .chat-options-menu .delete-option:hover {
    background: #fef2f2;
}

.chat-menu-wrapper {
    overflow: visible;
}

.history-item {
    overflow: visible;
}

/* Allow selecting and copying chat message text */
.message,
.message-content,
.user-message,
.bot-message,
.chat-message,
#chat-box,
#chat-container {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

/* Keep controls behaving like controls */
button,
.chat-menu-btn,
.chat-option-item,
.message-nav-marker,
.message-nav-list-item {
    user-select: none !important;
    -webkit-user-select: none !important;
}

/* ===== Mobile Sidebar Final Behavior ===== */
@media (max-width: 768px) {

    /* Sidebar becomes an overlay on mobile */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;

        width: min(82vw, 320px) !important;
        max-width: 320px !important;
        height: 100dvh !important;

        z-index: 1000 !important;

        background: rgba(255, 255, 255, 0.97) !important;
        box-shadow: 4px 0 25px rgba(15, 23, 42, 0.15);

        transform: translateX(-100%);
        opacity: 0;
        visibility: hidden;

        padding: 16px !important;
        border-right: 1px solid #e2e8f0 !important;
    }

    /* Sidebar open */
    #sidebar.open {
        width: min(82vw, 320px) !important;
        transform: translateX(0) !important;
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
    }

    /* Sidebar closed */
    #sidebar:not(.open),
    #sidebar.closed {
        width: min(82vw, 320px) !important;
        transform: translateX(-100%) !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    /* Always keep the existing sidebar button visible on mobile */
    #menu-toggle {
        display: flex !important;
        position: fixed !important;

        top: 10px !important;
        left: 12px !important;

        width: 44px !important;
        height: 44px !important;

        z-index: 1101 !important;

        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 50% !important;

        align-items: center !important;
        justify-content: center !important;

        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.10) !important;

        transition:
            left 0.25s cubic-bezier(0.4, 0, 0.2, 1),
            transform 0.2s ease !important;
    }

    /*
       When sidebar is open, move the SAME button
       beside the sidebar so it can always be clicked.
    */
    #menu-toggle.active {
        left: min(calc(82vw + 10px), 330px) !important;
    }

    /* Main chat always takes full mobile width */
    .main-content {
        width: 100% !important;
        min-width: 0 !important;
        flex: 1 1 100% !important;
    }

    /* Leave space for the button in header */
    .chat-header {
        padding-left: 68px !important;
        padding-right: 55px !important;
    }
}

@media (max-width: 480px) {

    #sidebar {
        width: 82vw !important;
        max-width: 300px !important;
    }

    #sidebar.open,
    #sidebar:not(.open),
    #sidebar.closed {
        width: 82vw !important;
        max-width: 300px !important;
    }

    #menu-toggle.active {
        left: calc(82vw + 8px) !important;
    }
}

