@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap');

/* --- THEME VARIABLES --- */
:root {
    /* Shared Variables */
    --font-main: "Open Sans", sans-serif;
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    --transition-speed: 0.3s;
    /* Light Theme (Default fallback) */
    --bg-main: #f8fafc;
    --bg-container: #ffffff;
    --sidebar-bg: rgba(255, 255, 255, 0.9);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --bubble-user-bg: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    --bubble-user-text: #ffffff;
    --bubble-ai-bg: rgba(255, 255, 255, 0.95);
    --bubble-ai-text: #1e293b;
    --shadow-main: 0 10px 30px rgba(0, 0, 0, 0.05);
    --input-bg: #ffffff;
    --input-focus-bg: #ffffff;
    --hover-bg: rgba(0, 0, 0, 0.03);
    --active-item-bg: rgba(14, 165, 233, 0.1);
    --accent-color: #0ea5e9;
    --table-header-bg: #f1f5f9;
    --table-row-bg: #ffffff;
    --table-row-hover: #f8fafc;
}

.dark-theme {
    /* Dark Theme */
    --bg-main: radial-gradient(circle at center, #0B1120 0%, #030712 100%);
    --bg-container: rgba(15, 23, 42, 0.5);
    --sidebar-bg: rgba(15, 23, 42, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --bubble-user-bg: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    --bubble-user-text: #ffffff;
    --bubble-ai-bg: rgba(30, 41, 59, 0.7);
    --bubble-ai-text: #e2e8f0;
    --shadow-main: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    --input-bg: rgba(30, 41, 59, 0.6);
    --input-focus-bg: rgba(30, 41, 59, 0.9);
    --hover-bg: rgba(255, 255, 255, 0.05);
    --active-item-bg: linear-gradient(90deg, rgba(14, 165, 233, 0.15) 0%, rgba(14, 165, 233, 0) 100%);
    --accent-color: #38bdf8;
    --table-header-bg: rgba(15, 23, 42, 0.9);
    --table-row-bg: rgba(15, 23, 42, 0.5);
    --table-row-hover: rgba(30, 41, 59, 0.8);
}

html, body {
    margin: 0;
    padding: 0;
    height: 100vh;        /* fallback for older browsers */
    height: 100dvh;       /* fit the VISIBLE viewport on mobile (excludes the browser address/nav bars) */
    width: 100vw;
    overflow: hidden; /* Prevent multi-scroll */
    font-family: var(--font-main);
    background: var(--bg-main);
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

.app-layout {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* Sidebar styling */
.sidebar {
    width: 300px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 30px rgba(0,0,0,0.1);
    z-index: 20;
    transition: transform var(--transition-speed) ease;
    flex-shrink: 0; 
    overflow: hidden; 
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), 
                transform var(--transition-speed) ease,
                border-color var(--transition-speed) ease;
}

.sidebar-header {
    padding: 0px 20px;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.border-b {
    border-bottom: 1px solid var(--border-color);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    padding: 3px 9px;
    transition: all 0.2s;
}

.btn-icon:hover {
        border: none;

    border-color: var(--accent-color);
}

.favorite-btn {
    color: var(--text-secondary);
    font-size: 15.2px;
    font-weight:500;
    white-space: nowrap;
}

/* Keep the favorites star + title + collapse chevron on one line (the chevron was
   wrapping below the title because the wrapper span was inline, not flex). */
.fav-title-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.btn-icon:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: var(--border-radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.sign-out-btn {
    margin:auto;
    padding: 6px 10px;
    font-size: 0.85rem;
    color: #ef4444;
}

.new-chat-btn:hover {
    border-color: var(--accent-color);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    min-height:120px;
}

.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    margin-bottom: 8px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    font-size: 0.95rem;
    border: 1px solid transparent;
}

.session-item:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    transform: translateX(4px);
}

.session-item.active {
    background: var(--active-item-bg);
    color: var(--accent-color);
    font-weight: 500;
}

.session-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-btn {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    opacity: 0;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.session-item:hover .delete-btn {
    opacity: 0.7;
}

.delete-btn:hover {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.1);
}

#app {
    flex: 1;
    display: flex;
    width: 100vw;
    height: 100vh;        /* fallback for older browsers */
    height: 100dvh;       /* fit the VISIBLE viewport on mobile (excludes the browser address/nav bars) */
    overflow: hidden;
}

.chat-container {
    flex: 1;
    height: 100%;
    background: var(--bg-container);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 8px 10px;
    background: var(--bg-container);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.hamburger {
    display: block;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-sm);
    transition: background var(--transition-speed);
}

.hamburger:hover {
    background: var(--hover-bg);
}

.brand-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start; 
    gap: 8px;
}

.brand-logo-wrapper {
    display: flex;
    align-items: center;
}

.brand-logo {
    max-width: 100px; 
    height: auto;
    display: block;
}

.brand-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 4px; 
}

.status-dot {
    width: 10px;
    height: 10px;
    background-color: var(--accent-color);
    border-radius: 50%;
    display: inline-block;
    position: relative;
}

    .status-dot::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: var(--accent-color);
        animation: pulse-live 2s infinite ease-in-out;
        opacity: 0.4;
    }

.status-text {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary); 
    font-family: var(--font-main);
}

@keyframes pulse-live {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(2.4);
        opacity: 0;
    }
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; box-shadow: 0 0 20px var(--accent-color); }
}
.chat-messages-container {
    overflow-y: auto;
    height :100%;
}
.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    display: flex;
    width: 80%;
    flex-direction: column;
    gap: 24px;
}
    .chat-messages::-webkit-scrollbar {
        display: none; 
    }

.message {
    max-width: 85%;
    animation: slideUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.bubble {
    padding: 16px 20px;
    border-radius: var(--border-radius-lg);
    font-size: 1rem;
    line-height: 1.6;
    word-break: break-word;
}

.bubble p {
    margin: 0 0 12px 0;
}
.bubble p:last-child {
    margin-bottom: 0;
}

.message.user .bubble {
    background: var(--bubble-user-bg);
    color: var(--bubble-user-text);
    border-bottom-right-radius: 4px;
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.2);
}

.message.assistant .bubble {
    background: var(--bubble-ai-bg);
    border: 1px solid var(--border-color);
    color: var(--bubble-ai-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

/* Image styling */
.bubble img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius-md);
    margin-top: 12px;
    border: 1px solid var(--border-color);
    display: block;
    cursor: zoom-in;   /* tap/click to enlarge in the lightbox */
}

/* Full-screen image lightbox (opened by tapping a chat image) */
.img-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.85);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    cursor: zoom-out;
}

.img-lightbox.open {
    display: flex;
}

.img-lightbox img {
    max-width: 95vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.img-lightbox-close {
    position: fixed;
    top: 14px;
    right: 18px;
    color: #fff;
    font-size: 2.2rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
    user-select: none;
}

.img-lightbox-close:hover {
    opacity: 1;
}

/* Link styling (for PDF downloads) */
.bubble a {
    display: inline-flex;
    align-items: center;
    margin-top: 10px;
    padding: 10px 16px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    transition: all var(--transition-speed);
}

.bubble a:hover {
    background: rgba(16, 185, 129, 0.2);
    transform: translateY(-2px);
}

/* Table styling */
.bubble table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 16px;
    margin-bottom: 16px;
    font-size: 0.95rem;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.bubble th, .bubble td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    color: var(--bubble-ai-text); /* Fix for dark text in dark mode */
}

.bubble td {
    background: var(--table-row-bg);
}

.bubble th {
    background: var(--table-header-bg);
    font-weight: 600;
    color: var(--accent-color);
}

.bubble tr:last-child td {
    border-bottom: none;
}

.bubble tr:hover td {
    background: var(--table-row-hover);
}

/* Wrap markdown tables so wide ones scroll horizontally instead of crushing their columns
   (which made headers wrap one character per line on phones). */
.table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 16px;
    margin-bottom: 16px;
}

.table-scroll table {
    margin-top: 0;
    margin-bottom: 0;
    width: auto;
    min-width: 100%;
}

/* Keep cell text on one line so columns size to content and the wrapper scrolls,
   instead of the inherited break-word splitting words/headers per character. */
.bubble th, .bubble td {
    word-break: normal;
    overflow-wrap: normal;
    white-space: nowrap;
}

.chat-input-container {
    padding: 20px 24px;
    background: var(--bg-container);
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input {
    flex: 1;
    max-width: 80%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 16px 20px;
    color: var(--text-primary);
    -webkit-text-fill-color: var(--text-primary);
    caret-color: var(--accent-color);
    font-size: 1rem;
    font-family: var(--font-main);
    outline: none;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.search-section-container {
    border-bottom:  1px solid var(--border-color);
}

.search-container {
    width: 250px;
}

.search-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 16px 20px;
    color: var(--text-primary);
    -webkit-text-fill-color: var(--text-secondary);
    caret-color: var(--accent-color);
    font-size: 1rem;
    font-family: var(--font-main);
    outline: none;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}
.chat-input::placeholder {
    color: var(--text-secondary);
}

.chat-input:focus {
    background: var(--input-focus-bg);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.send-button {
    background: var(--bubble-user-bg);
    border: none;
    border-radius: var(--border-radius-lg);
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.send-button svg {
    width: 24px;
    height: 24px;
}

.send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.3);
}

.send-button:disabled {
    background: #D1D5DC;
    cursor: not-allowed;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: typing-wave 1.5s infinite;
}

.typing-dot:nth-child(1) { animation-delay: -0.4s; }
.typing-dot:nth-child(2) { animation-delay: -0.2s; }

@keyframes typing-wave {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* Collapsible Thinking Logs */
.thinking-details {
    background: rgba(15, 23, 42, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    margin-bottom: 16px;
    overflow: hidden;
    transition: all var(--transition-speed);
}

/* Thinking panel rendered below the answer text: space it from the answer,
   tighten the gap before the copy bar that follows. */
.thinking-after {
    margin-top: 14px;
    margin-bottom: 4px;
}

.dark-theme .thinking-details {
    background: rgba(0, 0, 0, 0.2);
}

.thinking-summary {
    padding: 10px 14px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    background: rgba(0, 0, 0, 0.02);
}

.thinking-summary:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.brain-icon {
    display: inline-block;
    color: var(--primary-color);
}

.brain-icon.animating {
    animation: core-breathe-mini 1.5s ease-in-out infinite;
}

.brain-icon.stopped {
    opacity: 0.5;
    color: var(--text-secondary);
}

@keyframes core-breathe-mini {
    0%, 100% { transform: scale(1); box-shadow: 0 0 8px rgba(59, 130, 246, 0.6); }
    50% { transform: scale(1.2); box-shadow: 0 0 12px rgba(59, 130, 246, 0.9), inset 0 0 5px rgba(255,255,255,0.6); }
}

.thinking-content {
    padding: 12px 14px;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
    max-height: 250px;
    overflow-y: auto;
    background: rgba(0,0,0,0.02);
}

.thinking-content p {
    margin-bottom: 8px;
}
.thinking-content p:last-child {
    margin-bottom: 0;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 10px;
}

/* Mobile Responsiveness */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 15;
    backdrop-filter: blur(4px);
}

/* Sidebar collapsed state for desktop */
.sidebar {
    position: relative;
    left: 0;
    transition: all var(--transition-speed) ease;
}

    .sidebar.closed {
        width: 80px;
        border-right: none;
        overflow: hidden;
    }
        .sidebar.closed .mini-btn {
            width: 45px !important;
            height: 45px !important;
            padding: 0 !important;
            margin: 10px auto !important;
            border-radius: 50% !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
        }

        .sidebar.closed .mini-sidebar-btn {
            background: transparent;
            border: none;
            width: 45px;
            height: 30px;
            margin: 8px auto;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--text-secondary);
            border-radius: 50%;
            transition: background 0.2s;
        }


        .sidebar.closed .mini-fav {
            display: flex;
            justify-content: center;
            width: 100%;
        }

        .sidebar.closed .mini-btn-flat {
            background: transparent;
            border: none;
            width: 45px;
            height: 45px;
            margin: 0 auto;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #ef4444; 
            border-radius: 50%;
        }

            .sidebar.closed .mini-btn-flat:hover {
                background: rgba(239, 68, 68, 0.1);
            }

        .sidebar.closed .sidebar-header {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

/* تأكد إن الـ parent (الـ sidebar) مأخد position: relative; */
.close-sidebar-btn {
    position: absolute;
    top: 16px;
    right: 16px; /* لو الـ sidebar على الشمال، خليها left: 16px; */
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

    /* عشان نضمن إن الـ SVG يقرأ الحجم واللون صح */
    .close-sidebar-btn svg {
        width: 24px;
        height: 24px;
        /* هنا حط متغير اللون بتاعك، أو هيقرأ تلقائي لو الـ parent مأخد لون */
        color: var(--text-secondary);
    }

    .close-sidebar-btn:hover svg {
        color: var(--text-primary); /* تأثير عند الماوس ييجي عليه */
    }

/* إخفاء الزرار على الموبايل لو مش محتاجه هناك */
@media (max-width: 768px) {
    .close-sidebar-btn {
        display: none;
    }
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 20;
    }
    
    .sidebar.closed {
        width: 280px;
    }

    .sidebar.open {
        left: 0;
    }
    
    .sidebar.open + .sidebar-overlay {
        display: block;
    }

    /* Mobile chat sizing: use the full width so bubbles and tables aren't crushed into
       a narrow column (which forced text to wrap one word — or one character — per line). */
    .chat-messages {
        width: 100%;
        padding: 12px;
    }

    .message {
        max-width: 92%;
    }

    .bubble {
        padding: 12px 14px;
        font-size: 0.95rem;
    }

    .chat-input-container {
        padding: 12px 14px;
    }

    /* Declutter the header on phones: hide the "Connected to ..." status sentence. */
    .brand-status {
        display: none;
    }

    /* Proper flex sizing so the input and the disclaimer footer are never pushed off-screen. */
    .chat-messages-container {
        flex: 1;
        min-height: 0;
        height: auto;
    }

    /* Keep the bottom "AI can make mistakes" disclaimer snug and fully visible. */
    .chat-disclaimer {
        margin-bottom: 10px;
        padding: 0 12px;
    }
}
@media (min-width: 768px) {
    .hamburger {
        display: none
    }
}

    /* WASM boot / loading screen */
    .boot-screen {
        position: fixed;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 20px;
        background: var(--bg-main);
        color: var(--text-primary);
        z-index: 9999;
    }

    .boot-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        animation: boot-breathe 2.4s ease-in-out infinite;
    }

    .boot-img {
        width: 100px;
        height: 100px;
    }

    .boot-name {
        font-family: var(--font-main);
        font-size: 1.4rem;
        font-weight: 700;
        letter-spacing: 0.5px;
    }

    .boot-progress {
        width: 240px;
        max-width: 70vw;
        height: 6px;
        background: var(--border-color);
        border-radius: 999px;
        overflow: hidden;
    }

    .boot-progress-bar {
        height: 100%;
        width: var(--blazor-load-percentage, 0%);
        min-width: 8%;
        background: linear-gradient(90deg, #0ea5e9, #2563eb);
        border-radius: 999px;
        transition: width 0.25s ease;
    }

    .boot-percent {
        font-family: var(--font-main);
        font-size: 0.85rem;
        font-weight: 500;
        color: var(--text-secondary);
        letter-spacing: 0.5px;
        min-height: 1em;
    }

        .boot-percent::after {
            content: var(--blazor-load-percentage-text, "Loading…");
        }

    @keyframes boot-breathe {
        0%, 100% {
            transform: scale(1);
        }

        50% {
            transform: scale(1.06);
        }
    }

    /* =====================================================================
   New feature components: branding, saved chats, search, favorites
   ===================================================================== */

    /* Branding: license text pinned to the bottom of the sidebar */
    .sidebar-footer {
        padding: 12px 16px;
        font-size: 0.7rem;
        color: var(--text-secondary);
        border-top: 1px solid var(--border-color);
        text-align: center;
        letter-spacing: 0.3px;
    }

    /* Branding on the login screen */
    .login-logo {
        display: block;
        max-height: 40px;
        margin: 24px auto 6px;
        object-fit: contain;
    }

    .login-license {
        margin-top: 20px;
        text-align: center;
        font-size: 0.75rem;
        color: var(--text-secondary);
    }

    /* All / Saved tabs above the session list */
    .session-tabs {
        display: flex;
        background: var(--hover-bg);
        padding: 4px;
        border-radius: 8px;
        margin-top: 12px;
        border: 1px solid var(--border-color);
    }

        .session-tabs .tab {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            padding: 6px 12px;
            font-size: 0.78rem;
            font-weight: 500;
            border: none;
            background: transparent;
            color: var(--text-secondary);
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        }

            .session-tabs .tab:hover {
                color: var(--text-primary);
            }

            .session-tabs .tab.active {
                background: var(--active-item-bg);
                color: var(--accent-color);
                box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
            }

            .session-tabs .tab .count {
                background: rgba(0, 0, 0, 0.05);
                padding: 2px 6px;
                border-radius: 4px;
                font-size: 0.72rem;
                font-weight: 600;
                color: var(--text-secondary);
                transition: all 0.2s;
            }

            .session-tabs .tab.active .count {
                background: rgba(var(--accent-color-rgb), 0.1);
                color: var(--accent-color);
            }

            .session-tabs .tab:hover {
                color: var(--text-primary);
            }

            .session-tabs .tab.active {
                background: var(--active-item-bg);
                color: var(--accent-color);
                box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
            }

            .session-tabs .tab .count {
                background: rgba(0, 0, 0, 0.05);
                padding: 2px 6px;
                border-radius: 4px;
                font-size: 0.72rem;
                font-weight: 600;
                color: var(--text-secondary);
                transition: all 0.2s;
            }

            .session-tabs .tab.active .count {
                background: rgba(var(--accent-color-rgb), 0.1);
                color: var(--accent-color);
            }

    /* Star (bookmark) button on each session item */
    .star-btn {
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 4px;
        opacity: 0;
        color: var(--text-secondary);
        font-size: 0.95rem;
        line-height: 1;
        transition: all 0.2s;
    }

    .session-item:hover .star-btn {
        opacity: 0.7;
    }

    .star-btn.saved {
        opacity: 1;
        color: #f59e0b;
    }

    .star-btn:hover {
        opacity: 1 !important;
    }

    /* Search loading / empty states */
    .session-loading,
    .session-empty {
        padding: 16px;
        text-align: center;
        font-size: 0.85rem;
        color: var(--text-secondary);
    }

    /* Favorite (reusable) prompts */
    .favorites-section {
        padding: 0px 12px 4px;
    }

    .favorites-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--text-secondary);
        padding: 4px 2px 8px;
        overflow-y: auto;
    }

    .favorites-add-btn {
        background: transparent;
        border: 1px solid var(--border-color);
        color: var(--accent-color);
        width: 22px;
        height: 22px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 1.05rem;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

        .favorites-add-btn:hover {
            background: var(--hover-bg);
            border-color: var(--accent-color);
        }

    .composer-save-btn {
        background: var(--input-bg);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-lg);
        width: 48px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        cursor: pointer;
        transition: all var(--transition-speed);
        flex-shrink: 0;
    }

        .composer-save-btn:hover:not(:disabled) {
            color: var(--accent-color);
            border-color: var(--accent-color);
        }

        .composer-save-btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

    /* Favorite item action buttons (edit / delete) */
    .favorite-actions {
        display: flex;
        align-items: center;
        gap: 2px;
        flex-shrink: 0;
    }

    .fav-action-btn {
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 4px;
        opacity: 0;
        color:var(--text-secondary)  ;
        transition: opacity 0.2s;
    }

    .favorite-item:hover .fav-action-btn {
        opacity: 0.7;
    }

    .fav-action-btn:hover {
        opacity: 1 !important;
    }

    /* ===== Save / edit prompt modal ===== */
    .modal-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10000;
        padding: 20px;
        animation: modal-fade 0.15s ease;
    }

    @keyframes modal-fade {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    .modal-card {
        background: var(--bg-container);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-lg);
        box-shadow: var(--shadow-main);
        width: 100%;
        max-width: 480px;
        display: flex;
        flex-direction: column;
        animation: modal-pop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes modal-pop {
        from {
            opacity: 0;
            transform: translateY(12px) scale(0.98);
        }

        to {
            opacity: 1;
            transform: none;
        }
    }

    .modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px 24px 6px;
    }

        .modal-header h3 {
            margin: 0;
            font-size: 1.15rem;
            font-weight: 600;
            color: var(--text-primary);
        }

    .modal-close {
        background: transparent;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        font-size: 1rem;
        padding: 4px 8px;
        border-radius: var(--border-radius-sm);
    }

        .modal-close:hover {
            background: var(--hover-bg);
            color: var(--text-primary);
        }

    .modal-body {
        padding: 8px 24px 4px;
        display: flex;
        flex-direction: column;
    }

    .modal-label {
        font-size: 0.85rem;
        font-weight: 500;
        color: var(--text-secondary);
        margin: 12px 0 6px;
    }

    .modal-input,
    .modal-textarea {
        width: 100%;
        box-sizing: border-box;
        background: var(--input-bg);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-md);
        padding: 12px 14px;
        color: var(--text-primary);
        font-size: 0.95rem;
        font-family: var(--font-main);
        outline: none;
        transition: all var(--transition-speed);
    }

    .modal-textarea {
        resize: vertical;
        min-height: 110px;
        line-height: 1.5;
    }

        .modal-input:focus,
        .modal-textarea:focus {
            background: var(--input-focus-bg);
            border-color: var(--accent-color);
            box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
        }

    .modal-footer {
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        padding: 16px 24px 22px;
    }

    .modal-btn-secondary {
        padding: 10px 18px;
        background: transparent;
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        border-radius: var(--border-radius-md);
        font-weight: 500;
        cursor: pointer;
        transition: all var(--transition-speed);
    }

        .modal-btn-secondary:hover {
            background: var(--hover-bg);
            color: var(--text-primary);
        }

    .modal-btn-primary {
        padding: 10px 22px;
        background: var(--bubble-user-bg);
        border: none;
        color: #fff;
        border-radius: var(--border-radius-md);
        font-weight: 600;
        cursor: pointer;
        min-width: 92px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all var(--transition-speed);
    }

        .modal-btn-primary:hover:not(:disabled) {
            transform: translateY(-1px);
            box-shadow: 0 8px 20px rgba(14, 165, 233, 0.3);
        }

        .modal-btn-primary:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

    .spinner-sm {
        width: 18px;
        height: 18px;
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-top-color: #fff;
        border-radius: 50%;
        animation: modal-spin 0.8s linear infinite;
    }

    @keyframes modal-spin {
        to {
            transform: rotate(360deg);
        }
    }

    /* Sidebar customer logo */
    .sidebar-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 18px 20px 12px;
    }

    .sidebar-logo-img {
        max-width: 170px;
        object-fit: contain;
    }

    .sidebar-logo-name {
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Sessions header (moved out of the padded sidebar-header) */
    .sessions-header {
        padding: 14px 20px 0;
    }

    .sessions-title {
        margin: 0;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 1px;
    }

    .header-controls {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    /* Collapsible favorites chevron */
    /* 1. الحالة العادية للأيقونة (في الإنجليزي LTR وتكون مقفولة) */
    .chevron-icon {
        transition: transform 0.25s ease-in-out; /* حركة ناعمة جداً أثناء الدوران */
        opacity: 0.7;
        display: inline-block;
        transform: rotate(0deg);
    }

        .chevron-icon.open {
            transform: rotate(90deg);
        }


    [dir="rtl"] .chevron-icon {
        transform: rotate(180deg);
    }

        [dir="rtl"] .chevron-icon.open {
            transform: rotate(90deg);
        }

    /* Auto-title hint inside the add-prompt modal */
    .modal-hint {
        margin-top: 8px;
        font-size: 0.78rem;
        color: var(--text-secondary);
        opacity: 0.85;
    }

    /* Toast notification */
    .toast {
        position: fixed;
        bottom: 28px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--text-primary);
        color: var(--bg-container);
        padding: 12px 22px;
        border-radius: 999px;
        font-size: 0.9rem;
        font-weight: 500;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
        z-index: 11000;
        animation: toast-in 0.2s ease;
    }

    @keyframes toast-in {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(10px);
        }

        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }

    /* Favorited state for the chat-message star action */
    .action-btn.favorited {
        opacity: 1 !important;
        color: #f59e0b !important;
    }

        .action-btn.favorited svg {
            fill: #f59e0b;
            stroke: #f59e0b;
        }

    .favorites-empty {
        padding: 4px 6px 8px;
        font-size: 0.78rem;
        color: var(--text-secondary);
        opacity: 0.8;
        line-height: 1.4;
    }

    .favorite-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        padding: 4px 17px;
        border-radius: var(--border-radius-sm);
        cursor: pointer;
        color: var(--text-secondary);
        font-size: 0.88rem;
        transition: all 0.2s;
    }

        .favorite-item:hover {
            background: var(--hover-bg);
            color: var(--text-primary);
        }

        .favorite-item .favorite-title {
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .favorite-item .delete-btn {
            opacity: 0;
        }

        .favorite-item:hover .delete-btn {
            opacity: 0.7;
        }

    /* Quick-prompt chips shown on the empty welcome screen */
    .quick-prompts {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
        margin-top: 16px;
    }

    .quick-prompt-chip {
        padding: 8px 14px;
        border: 1px solid var(--accent-color);
        background: rgba(14, 165, 233, 0.08);
        color: var(--accent-color);
        border-radius: 999px;
        font-size: 0.85rem;
        cursor: pointer;
        transition: all 0.2s;
    }

        .quick-prompt-chip:hover {
            background: rgba(14, 165, 233, 0.18);
            transform: translateY(-1px);
        }
