
/* =========================================================
   01) ROOT / APP SHELL
========================================================= */
:root {
    --bg-main: #1a1a1a;       /* Updated to strictly match your prompt */
    --bg-panel: #222222;      
    --bg-user: #2d2d2d;
    --bg-jad: rgba(255, 255, 255, 0.03);
    --border-soft: rgba(255, 255, 255, 0.08);
    --border-softer: rgba(255, 255, 255, 0.05);
    --text-main: #e3e3e3;
    --text-soft: #94a3b8;
    --text-muted: #666;
    --accent: #fb923c;
    --accent-soft: rgba(251, 146, 60, 0.08);
    --success: #4ade80;
    --danger: #f87171;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.15);
    --radius-lg: 18px;
    --radius-md: 12px;
    --max-content-width: 800px;
    --font-main: 'Cairo', sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: auto;
}

body,
textarea,
input,
button,
.user-msg,
.bubble,
.jad-text {
    font-family: var(--font-main) !important;
}

header {
    backdrop-filter: blur(16px);
    background: rgba(0, 0, 0, 0.4);
}

footer {
    width: 100%;
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: 10px 15px 25px 15px;
    background: var(--bg-main);
}

/* =========================================================
   02) CHAT WINDOW / SCROLL
========================================================= */
.chat-window,
#chat-box {
    width: 100%;
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

/* 🚀 Target BOTH the main chat and the sidebar list */
.chat-window::-webkit-scrollbar,
#chat-box::-webkit-scrollbar,
.sidebar-chat-list-container::-webkit-scrollbar {
    width: 6px;
}

.chat-window::-webkit-scrollbar-track,
#chat-box::-webkit-scrollbar-track,
.sidebar-chat-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-window::-webkit-scrollbar-thumb,
#chat-box::-webkit-scrollbar-thumb,
.sidebar-chat-list-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.chat-window::-webkit-scrollbar-thumb:hover,
#chat-box::-webkit-scrollbar-thumb:hover,
.sidebar-chat-list-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* =========================================================
   03) USER MESSAGE
========================================================= */
.user-msg-row {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    width: 100%;
}

.user-msg-actions {
    display: flex;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    margin-bottom: 0.5rem;
}

.user-msg-row:hover .user-msg-actions {
    opacity: 1;
}

.user-msg {
    align-self: flex-end;
    max-width: 85%;
    margin-bottom: 0;
    padding: 12px 16px;
    position: relative;
    background: var(--bg-user);
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
    border: 1px solid var(--border-softer);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 0.01em;
}

.user-msg-toggle {
    margin-top: 8px;
    align-self: flex-start;
    border: 0;
    background: transparent;
    color: #d1d5db;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    z-index: 10;
}

.user-msg-toggle:hover {
    color: white;
}

.attached-files {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

/* =========================================================
   04) JAD MESSAGE ROW / AVATAR / BUBBLE
========================================================= */
.jad-msg-container {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 15px;
}

.jad-avatar {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    margin-top: 2px;
}

.jad-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.bubble {
    width: fit-content;
    max-width: 100%;
    padding: 14px 16px;
    background: var(--bg-jad);
    color: var(--text-main);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid var(--border-soft);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-soft);
    line-height: 1.7;
    font-size: 15px;
    word-wrap: break-word;
}

.jad-text {
    direction: ltr;
    text-align: left;
    unicode-bidi: plaintext;
    word-break: break-word;
    min-width: 0;
    line-height: 1.7;
}

.jad-text:lang(ar),
.jad-text[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

.jad-footer {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding-inline: 0.25rem;
    margin-top: 0.25rem;
}

/* =========================================================
   05) THINKING / TYPING
========================================================= */
.processing-status {
    font-size: 10px;
    color: rgba(251, 146, 60, 0.8);
    font-weight: 700;
    margin-left: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    animation: pulseSoft 1.4s infinite;
}

.dots span {
    animation: blink 1.4s infinite;
}

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

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

@keyframes blink {
    0%, 80%, 100% {
        opacity: 0;
    }
    40% {
        opacity: 1;
    }
}

@keyframes pulseSoft {
    0%, 100% {
        opacity: 0.55;
    }
    50% {
        opacity: 1;
    }
}

/* =========================================================
   06) INPUT AREA
========================================================= */
.input-wrapper {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-panel);
    border: 1px solid #333;
    border-radius: 2rem;
    transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: rgba(255, 255, 255, 0.4);
}

textarea#input {
    width: 100%;
    min-height: 24px;
    max-height: 120px;
    resize: none;
    overflow: hidden;
    background: transparent;
    border: none;
    outline: none;
    color: white;
    padding-left: 12px;
    line-height: 1.5;
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 0.01em;
}

textarea#input::placeholder {
    color: var(--text-muted);
    font-family: var(--font-main) !important;
}

textarea#input::-webkit-scrollbar {
    width: 4px;
}

textarea#input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

/* =========================================================
   07) FILE PREVIEW CHIPS
========================================================= */
.file-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 12px;
    color: #d1d5db;
}

.file-remove-btn {
    background: transparent;
    border: 0;
    color: #6b7280;
    cursor: pointer;
    margin-left: 0.25rem;
    transition: color 0.2s ease;
}

.file-remove-btn:hover {
    color: #f87171;
}

/* =========================================================
   08) BUTTONS / ICON BUTTONS / COST CHIP
========================================================= */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    color: white;
}

.footer-btn {
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    margin-right: 0.25rem;
}

.footer-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.cost-tracker {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 0.375rem;
    cursor: help;
    position: relative;
}

.cost-tooltip {
    display: none;
    position: absolute;
    top: -2rem;
    right: 0;
    background: black;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #9ca3af;
    font-size: 9px;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    z-index: 50;
}

.cost-tracker:hover .cost-tooltip {
    display: block;
}

/* =========================================================
   09) TABLES / LINKS / INLINE CODE
========================================================= */
.jad-text table,
#chat-box table {
    width: 100%;
    border-collapse: collapse !important;
    border-spacing: 0 !important;
    table-layout: auto;
    margin: 15px 0 !important;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    overflow: hidden;
}

.jad-text th,
#chat-box th {
    white-space: nowrap;
    text-align: left;
    padding: 10px;
    font-weight: 600;
    color: var(--text-soft);
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin: 0 !important;
}

.jad-text td,
#chat-box td {
    vertical-align: middle;
    line-height: 1.5;
    padding: 10px;
    color: #e2e8f0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin: 0 !important;
}

.jad-text tr:last-child td,
#chat-box tr:last-child td {
    border-bottom: none !important;
}

.jad-link {
    color: white;
    font-weight: 700;
    text-decoration: none;
}

.jad-link:hover {
    text-decoration: underline;
}

.inline-code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.125rem 0.375rem;
    border-radius: 0.375rem;
    color: #fdba74;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
}

.trend-up {
    color: var(--success);
    font-weight: 700;
    margin-left: 0.25rem;
}

.trend-down {
    color: var(--danger);
    font-weight: 700;
    margin-left: 0.25rem;
}

/* =========================================================
   10) CODE BLOCKS
========================================================= */
.code-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1a1a1a;
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem 0.5rem 0 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 0;
}

.code-lang {
    font-size: 10px;
    text-transform: uppercase;
    color: #6b7280;
    font-weight: 700;
}

.code-copy-btn {
    background: transparent;
    border: 0;
    color: #9ca3af;
    font-size: 12px;
    cursor: pointer;
}

.code-copy-btn:hover {
    color: white;
}

.code-block {
    background: rgba(0, 0, 0, 0.4);
    padding: 0.75rem;
    margin: 0;
    overflow-x: auto;
    color: #fdba74;
    font-size: 14px;
    line-height: 1.6;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* =========================================================
   11) SECTION TITLES / NOTE STYLE
========================================================= */
.section-title {
    display: block;
    margin: 1.25rem 0 0.75rem;
}

.jad-text p b:first-child,
.section-title {
    color: var(--accent);
}

.jad-text p b:first-child {
    display: block;
    padding-left: 10px;
    font-size: 0.95rem;
    letter-spacing: 0.025em;
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 0 4px 4px 0;
}

/* =========================================================
   12) MIC / EFFECTS / MISC
========================================================= */
.mic-active {
    background: #ef4444 !important;
    color: white !important;
    transform: scale(1.1);
}

@keyframes pulseMic {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    70%  { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.mic-pulse {
    animation: pulseMic 1.5s infinite;
}

@keyframes blinkOnce {
    0%   { opacity: 1; }
    50%  { opacity: 0; }
    100% { opacity: 1; }
}

.blink-once {
    animation: blinkOnce 0.6s ease-in-out 1;
}

.overflow-x-auto::-webkit-scrollbar {
    height: 4px;
}

.overflow-x-auto::-webkit-scrollbar-track {
    background: transparent;
}

.overflow-x-auto::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}


/* =========================================================
   SIDEBAR COLLAPSE LOGIC (GEMINI STYLE)
========================================================= */
#sidebar {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 768px) {
    /* When collapsed, shrink to 72px */
    body.sidebar-collapsed #sidebar { width: 72px; }
    
    /* When expanded, grow to 280px */
    body:not(.sidebar-collapsed) #sidebar { width: 280px; }
    
    /* Hide text & labels when collapsed */
    body.sidebar-collapsed .hide-on-collapse { 
        opacity: 0; 
        display: none !important; 
    }
    
    /* Center the icons perfectly when collapsed */
    body.sidebar-collapsed .justify-center-on-collapse { 
        justify-content: center !important; 
        width: 44px !important; 
        margin: 0 auto !important;
        padding-left: 0 !important; 
        padding-right: 0 !important; 
    }
    
    /* Hide the entire chat list when collapsed */
    body.sidebar-collapsed .sidebar-chat-list-container {
        display: none; 
    }
}

/* =========================================================
   PROFILE MENU BEHAVIOR
========================================================= */
/* Default State: Sidebar is Open */
#profile-menu {
    width: calc(100% - 16px);
}

/* Collapsed State: Sidebar is closed (Fly-out behavior) */
@media (min-width: 768px) {
    body.sidebar-collapsed #profile-menu {
        width: max-content;        /* Let it be as wide as the text needs */
        min-width: 180px;          /* Give it a nice minimum width */
        left: 72px;                /* Push it perfectly outside the 72px collapsed sidebar */
        bottom: 0px;               /* Align it nicely with the bottom button */
        margin-bottom: 12px;
    }
}