:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-input: #ffffff;
    --bg-chat: #fafbfc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-color: #1e40af;
    --accent-hover: #1e3a8a;
    --accent-light: #eff6ff;
    --accent-gradient: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    --danger: #dc2626;
    --success: #059669;
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);

    --font-main: 'Cairo', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Fira Code', 'Consolas', monospace;
    --sidebar-width: 280px;
    --header-height: 60px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: #f8fafc;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    transition: width 0.2s ease, transform 0.3s ease, padding 0.3s ease;
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    max-width: 600px;
    min-width: 220px;
}

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

.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0;
    border: none;
}

.sidebar-header {
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* User Profile */
#user-profile {
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color) !important;
}

#user-profile:hover {
    background-color: #e8edf3 !important;
    border-color: #cbd5e1 !important;
}

.user-avatar {
    font-size: 0.8rem;
}

/* New Chat Button */
.btn-primary-outline {
    width: 100%;
    padding: 0.65rem;
    border: 1.5px solid var(--accent-color);
    background: var(--accent-light);
    color: var(--accent-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    font-weight: 600;
    justify-content: center;
}

.btn-primary-outline:hover {
    background-color: var(--accent-color);
    color: #ffffff;
}

.btn-primary-outline:hover svg {
    color: #ffffff;
}

/* Search Box */
.search-container {
    width: 100%;
    position: relative;
    margin-bottom: 0.5rem;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-primary);
    font-size: 0.85rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

[dir="rtl"] .search-input {
    padding: 0.5rem 2rem 0.5rem 0.5rem;
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 0.5rem;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    width: 14px;
    height: 14px;
}

[dir="rtl"] .search-icon {
    left: auto;
    right: 0.5rem;
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.08);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 1rem;
}

.history-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin: 0.75rem 0 0.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.history-item {
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    color: var(--text-primary);
    transition: all 0.15s ease;
    margin-bottom: 2px;
    position: relative;
    height: 38px;
    font-size: 0.85rem;
}

.history-item-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
    flex: 1;
}

.history-text {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    font-size: 0.85rem;
}

.history-item:hover {
    background-color: #e8edf3;
}

.history-item.active {
    background-color: #dce4f0;
    font-weight: 500;
}

.history-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-item:hover .history-menu-btn,
.history-menu-btn.active {
    opacity: 1;
}

.history-menu-btn:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.05);
}

.rename-input {
    width: 100%;
    background: transparent;
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    padding: 0;
    font-size: 0.85rem;
    color: var(--text-primary);
    outline: none;
    height: auto;
    font-family: inherit;
    box-shadow: none;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}

.nav-item {
    width: 100%;
    padding: 0.65rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transition: all 0.15s;
}

.nav-item:hover {
    background-color: #e8edf3;
    color: var(--text-primary);
}

/* ==================== CHAT AREA ==================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-chat);
    transition: width 0.3s ease;
}

/* Top Brand Bar */
.top-brand-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0a0a0a;
    padding: 0 1.5rem;
    height: 44px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.top-brand-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-brand-name {
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.25em;
    font-family: 'Inter', sans-serif;
}

.top-brand-badge {
    background: rgba(255, 255, 255, 0.12);
    color: #d1d5db;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.08em;
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-family: 'Inter', sans-serif;
}

.top-brand-right {
    display: flex;
    align-items: center;
}

.lang-toggle-btn-dark {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #d1d5db;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-weight: 500;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

.lang-toggle-btn-dark:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.chat-header {
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    position: relative;
    height: 46px;
    background: var(--bg-primary);
}

.mobile-only {
    display: none;
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-weight: 600;
    font-size: 0.8rem;
}

.sidebar-toggle-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.header-branding {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

#current-chat-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-secondary);
}

/* ==================== MENUS & DROPDOWNS ==================== */
.header-actions {
    position: relative;
}

.menu-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.menu-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    display: none;
    z-index: 100;
    flex-direction: column;
    padding: 4px;
}

[dir="ltr"] .dropdown-menu {
    left: 0;
    right: auto;
}

[dir="rtl"] .dropdown-menu {
    right: 0;
    left: auto;
}

.dropdown-menu.active {
    display: flex;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    width: 100%;
    text-align: inherit;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.dropdown-item:hover {
    background-color: var(--bg-secondary);
}

.dropdown-item.danger {
    color: var(--danger);
}

.dropdown-item.danger:hover {
    background-color: rgba(239, 68, 68, 0.08);
}

/* Context Menu */
.context-menu {
    position: fixed;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    display: none;
    z-index: 9999;
    flex-direction: column;
    padding: 4px;
}

.context-menu.active {
    display: flex;
}

/* ==================== MESSAGES ==================== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    padding: 0;
    display: flex;
    gap: 0.75rem;
    font-size: 0.92rem;
    line-height: 1.65;
    border: none;
    position: relative;
    max-width: 80%;
    animation: messageSlideIn 0.2s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

[dir="ltr"] .message.user-message {
    align-self: flex-start;
    flex-direction: row;
}

.message.ai-message {
    align-self: flex-start;
    background: transparent;
    border: none;
    flex-direction: row;
}

[dir="ltr"] .message.ai-message {
    align-self: flex-start;
    flex-direction: row;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar.user-avatar {
    background: var(--accent-gradient);
    color: #fff;
}

.avatar.user-avatar svg {
    width: 16px;
    height: 16px;
}

.avatar.ai-avatar {
    background: linear-gradient(135deg, #059669 0%, #34d399 100%);
    color: #fff;
}

.avatar.ai-avatar svg {
    width: 16px;
    height: 16px;
}

/* Message Bubbles */
.message-content {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.ai-message .message-content {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-top-right-radius: 4px;
    box-shadow: var(--shadow-sm);
}

[dir="ltr"] .message.ai-message .message-content {
    border-top-right-radius: var(--radius-lg);
    border-top-left-radius: 4px;
}

.message.user-message .message-content {
    background: var(--accent-gradient);
    color: #ffffff;
    border: none;
    border-top-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.15);
}

[dir="ltr"] .message.user-message .message-content {
    border-top-right-radius: var(--radius-lg);
    border-top-left-radius: 4px;
}

.message.user-message .message-content a {
    color: #bfdbfe;
}

/* Message Content Styling */
.message-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
}

.message-content pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: var(--font-mono);
    overflow-x: auto;
    margin: 0.5rem 0;
    border: 1px solid #334155;
    position: relative;
}

.message-content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.message-content p code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    color: #be185d;
    font-size: 0.85em;
}

.message.user-message .message-content p code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.message-content ul, .message-content ol {
    padding-inline-start: 1.25rem;
    margin: 0.25rem 0;
}

.message-content li {
    margin-bottom: 0.15rem;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}

.message-content th, .message-content td {
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    text-align: start;
}

.message-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.message-content blockquote {
    border-inline-start: 3px solid var(--accent-color);
    padding-inline-start: 0.75rem;
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

/* Message Body & Actions */
.message-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-width: 800px;
}

.message-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 4px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
}

.action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.action-btn.copied {
    color: var(--success);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Cursor Blink */
.cursor-blink {
    animation: blink 1s step-end infinite;
    color: var(--accent-color);
    font-size: 0.8em;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ==================== WELCOME SCREEN ==================== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem;
    text-align: center;
    gap: 1.5rem;
}

.welcome-logo {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

.welcome-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.welcome-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.5;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    max-width: 500px;
    width: 100%;
    margin-top: 0.5rem;
}

.suggestion-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: start;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
}

.suggestion-card:hover {
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.08);
    transform: translateY(-1px);
}

.suggestion-card-icon {
    color: var(--accent-color);
    flex-shrink: 0;
    margin-top: 2px;
}

.suggestion-card-text {
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.4;
}

/* ==================== INLINE EDIT ==================== */
.edit-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    width: 100%;
}

.inline-edit-textarea {
    width: 100%;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    min-height: 2.5rem;
    font-family: inherit;
    outline: none;
}

.inline-edit-textarea:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.08);
}

.edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn-sm {
    padding: 0.45rem 1rem;
    font-size: 0.82rem;
    border-radius: 1.5rem;
    cursor: pointer;
    font-weight: 600;
    border: none;
    transition: all 0.15s;
}

.btn-cancel {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-cancel:hover {
    background-color: #e8edf3;
}

.btn-save {
    background-color: var(--accent-color);
    color: #fff;
}

.btn-save:hover {
    background-color: var(--accent-hover);
}

/* ==================== INPUT AREA ==================== */
.input-area {
    padding: 1rem 2rem 1.25rem;
    background-image: linear-gradient(180deg, rgba(250, 251, 252, 0), var(--bg-chat) 50%);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    background-color: #ffffff;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.06), var(--shadow-md);
}

.file-preview {
    padding: 0.5rem;
    display: none;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.file-preview.active {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.preview-name {
    font-size: 0.8rem;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-file-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    padding: 0.65rem 0.75rem;
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 0.15rem 0.5rem;
    line-height: 1.5;
}

#chat-input::placeholder {
    color: #94a3b8;
}

.file-upload-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-upload-btn:hover {
    color: var(--accent-color);
    background-color: var(--accent-light);
}

.send-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm);
}

.send-btn:not(:disabled):hover {
    color: #fff;
    background: var(--accent-color);
    border-radius: var(--radius-sm);
}

.send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.input-hint kbd {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 3px;
    padding: 0 4px;
    font-size: 0.65rem;
    font-family: inherit;
}

/* ==================== MODALS ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-primary);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.input-group {
    margin-top: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 0.65rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.modal-footer {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.15s;
}

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

/* Recycle Bin */
.recycle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-secondary);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-light);
}

.recycle-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recycle-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-restore,
.btn-delete-forever {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-restore {
    color: var(--accent-color);
}

.btn-delete-forever {
    color: var(--danger);
}

.btn-restore:hover {
    background-color: rgba(30, 64, 175, 0.08);
}

.btn-delete-forever:hover {
    background-color: rgba(239, 68, 68, 0.08);
}

/* ==================== RESIZE HANDLE ==================== */
.resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    z-index: 100;
    transition: background 0.2s;
}

[dir="rtl"] .resize-handle {
    left: 0;
}

[dir="ltr"] .resize-handle {
    right: 0;
}

.resize-handle:hover,
.sidebar.resizing .resize-handle {
    background-color: var(--accent-color);
}

/* ==================== LIGHTBOX ==================== */
.lightbox-modal {
    background-color: rgba(0, 0, 0, 0.9) !important;
    z-index: 2000;
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    border-radius: var(--radius-sm);
    animation: zoomIn 0.25s;
    transition: transform 0.1s ease-out;
    cursor: grab;
}

.lightbox-content:active {
    cursor: grabbing;
}

@keyframes zoomIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.close-lightbox {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 36px;
    font-weight: bold;
    transition: 0.2s;
    cursor: pointer;
    z-index: 2001;
}

.close-lightbox:hover {
    color: #bbb;
}

[dir="rtl"] .close-lightbox {
    right: auto;
    left: 35px;
}

.zoom-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 2002;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 24px;
}

.zoom-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.zoom-btn:hover {
    transform: scale(1.15);
}

/* ==================== LOGIN VIEW ==================== */
.login-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('login_bg_circuit.png') no-repeat center center/cover;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-view::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(12px);
    z-index: -1;
}

.login-card {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    width: 90%;
    max-width: 400px;
    padding: 2.5rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.4);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    z-index: 1;
}

.login-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-logo h1 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

/* Floating Icons */
.floating-icons {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

.float-icon {
    position: absolute;
    opacity: 0;
    width: 22px;
    height: 22px;
}

.icon-idea { color: #f59e0b; left: 50%; top: 50%; --tx: -40px; animation: floatUpFadeOut 2s ease-out infinite; animation-delay: 0.2s; }
.icon-code { color: #10a37f; left: 50%; top: 50%; --tx: 40px; animation: floatUpFadeOut 2s ease-out infinite; animation-delay: 0.5s; }
.icon-ai { color: #8b5cf6; left: 50%; top: 50%; --tx: 0px; animation: floatUpFadeOut 2s ease-out infinite; animation-delay: 0.8s; }
.icon-sparkle { color: #3b82f6; left: 50%; top: 50%; --tx: 20px; animation: floatUpFadeOut 1.5s ease-out infinite; animation-delay: 1.0s; }

@keyframes floatUpFadeOut {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    20% { opacity: 1; transform: translate(var(--tx), -20px) scale(1); }
    100% { opacity: 0; transform: translate(var(--tx), -100px) scale(0.8); }
}

/* ==================== CUSTOM POPUP ==================== */
.custom-popup-backdrop {
    backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.35);
    z-index: 9999;
}

.popup-content {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 380px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    animation: popupSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popupSlideUp {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.popup-icon-container {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background-color: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.popup-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: #0f172a;
    letter-spacing: -0.01em;
}

.popup-message {
    font-size: 0.9rem;
    color: #64748b;
    line-height: 1.5;
    margin-bottom: 20px;
    max-width: 300px;
}

.popup-input {
    width: 100%;
    padding: 9px 12px;
    background-color: #fff;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
    color: #0f172a;
}

.popup-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.08);
}

.popup-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    margin-top: 6px;
}

.btn-popup {
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 38px;
}

.btn-popup:active {
    transform: scale(0.98);
}

.btn-popup-cancel {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    color: #374151;
}

.btn-popup-cancel:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-popup-confirm {
    background-color: var(--accent-color);
    color: #ffffff;
}

.btn-popup-confirm:hover {
    background-color: var(--accent-hover);
}

.btn-popup-confirm.danger {
    background-color: #ef4444;
    color: #fff;
    border: 1px solid #ef4444;
}

.btn-popup-confirm.danger:hover {
    background-color: #dc2626;
    border-color: #dc2626;
}

/* ==================== BRAND ==================== */
.brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.08);
}

.brand-text {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

[dir="rtl"] .top-brand-logo { right: 24px; left: auto; flex-direction: row; }
[dir="ltr"] .top-brand-logo { left: 24px; right: auto; flex-direction: row; }

@media (max-width: 480px) {
    .brand-text { display: none; }
}

/* ==================== MOBILE SIDEBAR OVERLAY ==================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 49;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ==================== RESPONSIVE - TABLET (768px - 1024px) ==================== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }

    .messages-container {
        padding: 1.25rem 1.5rem;
    }

    .input-area {
        padding: 0.75rem 1.5rem 1rem;
    }

    .message {
        max-width: 88%;
    }

    #current-chat-title {
        max-width: 200px;
        font-size: 0.9rem;
    }

    .welcome-title {
        font-size: 1.2rem;
    }
}

/* ==================== RESPONSIVE - MOBILE (max 768px) ==================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        height: 100dvh;
        width: 280px !important;
        min-width: 0 !important;
        max-width: 80vw !important;
        transform: translateX(-100%);
        z-index: 50;
        background-color: var(--bg-primary);
        box-shadow: none;
        transition: transform 0.3s ease;
        border: none;
    }

    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    [dir="rtl"] .sidebar.mobile-open {
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .sidebar.collapsed {
        transform: translateX(-100%) !important;
    }

    [dir="rtl"] .sidebar.collapsed {
        transform: translateX(100%) !important;
    }

    .resize-handle {
        display: none;
    }

    .mobile-only {
        display: flex !important;
    }

    #sidebar-toggle-btn {
        display: none !important;
    }

    .top-brand-bar {
        padding: 0 0.75rem;
        height: 40px;
    }

    .top-brand-name {
        font-size: 0.75rem;
        letter-spacing: 0.2em;
    }

    .top-brand-badge {
        font-size: 0.5rem;
        padding: 1px 6px;
    }

    .chat-header {
        padding: 0 0.75rem;
        height: 40px;
        gap: 8px;
    }

    .header-branding {
        min-width: 0;
    }

    #current-chat-title {
        max-width: 140px;
        font-size: 0.8rem;
    }

    .messages-container {
        padding: 0.75rem 0.75rem;
    }

    .message {
        max-width: 95%;
        font-size: 0.88rem;
        gap: 0.5rem;
    }

    .avatar {
        width: 26px;
        height: 26px;
    }

    .avatar svg {
        width: 14px !important;
        height: 14px !important;
    }

    .message-content {
        padding: 0.6rem 0.85rem;
    }

    .message-body {
        max-width: calc(100vw - 100px);
    }

    .input-area {
        padding: 0.5rem 0.75rem 0.75rem;
    }

    .input-container {
        border-radius: var(--radius-md);
    }

    .input-wrapper {
        padding: 0.5rem 0.6rem;
    }

    #chat-input {
        font-size: 0.9rem;
    }

    .input-hint {
        font-size: 0.6rem;
        margin-top: 0.35rem;
        gap: 0.35rem;
    }

    .input-hint kbd {
        font-size: 0.58rem;
        padding: 0 3px;
    }

    .welcome-screen {
        padding: 1.25rem;
        gap: 1rem;
    }

    .welcome-logo {
        width: 48px;
        height: 48px;
    }

    .welcome-title {
        font-size: 1.15rem;
    }

    .welcome-subtitle {
        font-size: 0.82rem;
    }

    .suggestion-cards {
        grid-template-columns: 1fr;
        max-width: 100%;
        gap: 0.5rem;
    }

    .suggestion-card {
        padding: 0.7rem 0.85rem;
    }

    .suggestion-card-text {
        font-size: 0.78rem;
    }

    .modal-content {
        width: 94%;
        padding: 1.25rem;
        max-height: 85vh;
        border-radius: var(--radius-md);
    }

    .popup-content {
        width: 92%;
        padding: 20px;
    }

    .login-card {
        width: 92%;
        padding: 2rem 1.5rem;
    }

    .lang-toggle-btn {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .message-actions {
        opacity: 1;
    }

    .dropdown-menu {
        min-width: 140px;
    }

    .message-content pre {
        font-size: 0.75rem;
        padding: 0.65rem 0.75rem;
    }

    .message-content table {
        font-size: 0.78rem;
    }

    .message-content th, .message-content td {
        padding: 0.3rem 0.4rem;
    }
}

/* ==================== RESPONSIVE - SMALL MOBILE (max 400px) ==================== */
@media (max-width: 400px) {
    .chat-header {
        padding: 0 0.5rem;
        height: 48px;
        gap: 6px;
    }

    #current-chat-title {
        max-width: 100px;
        font-size: 0.8rem;
    }

    .brand-icon {
        width: 20px !important;
        height: 20px !important;
    }

    .model-badge {
        display: none;
    }

    .messages-container {
        padding: 0.5rem;
    }

    .message {
        font-size: 0.85rem;
    }

    .message-content {
        padding: 0.5rem 0.75rem;
    }

    .input-area {
        padding: 0.4rem 0.5rem 0.6rem;
    }

    .input-hint {
        display: none;
    }

    .welcome-title {
        font-size: 1rem;
    }

    .suggestion-card {
        padding: 0.6rem 0.75rem;
    }

    .login-card {
        width: 95%;
        padding: 1.5rem 1.25rem;
    }

    .login-card img {
        max-width: 80px !important;
    }
}

/* ==================== TOAST NOTIFICATION ==================== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #0f172a;
    color: #fff;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Spin animation for loader */
.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}
