:root {
    /* Islamic Premium Theme Palette */
    --bg-color: #051412;        /* Very dark emerald green (night mood) */
    --sidebar-bg: rgba(9, 26, 23, 0.85); /* Semi-transparent dark emerald */
    --chat-header-bg: rgba(5, 20, 18, 0.8);
    --glass-border: rgba(197, 168, 128, 0.15); /* Gold-tinted transparent border */
    --glass-border-focus: rgba(197, 168, 128, 0.45);
    
    --primary-color: #15803d;    /* Emerald green */
    --primary-hover: #166534;
    --accent-gold: #c5a880;      /* Satin Gold */
    --color-gold: #e9c46a;       /* Vivid Gold for highlights */
    --accent-amber: #d97706;
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    
    /* Message bubble styling */
    --user-msg-bg: rgba(21, 128, 61, 0.12); /* Soft emerald Tint */
    --user-msg-border: rgba(21, 128, 61, 0.35);
    --ai-msg-bg: rgba(255, 255, 255, 0.02);  /* Transparent ivory glass */
    --ai-msg-border: rgba(197, 168, 128, 0.12);
    
    --error-color: #ef4444;
    --success-color: #10b981;
    
    /* Font stacks */
    --font-body: 'Tajawal', sans-serif;
    --font-logo: 'Reem Kufi', 'Tajawal', sans-serif;
    --font-title: 'Tajawal', sans-serif;
    --font-quran: 'Amiri', serif;
}

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

button, input, select, textarea {
    font-family: var(--font-body);
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(21, 128, 61, 0.25) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(197, 168, 128, 0.12) 0px, transparent 50%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cpath d='M40 0l3 25 22-12-12 22 25 3-25 3 12 22-22-12-3 25-3-25-22 12 12-22-25-3 25-3-12-22 22 12z' fill='%23c5a880' fill-opacity='0.015'/%3E%3C/svg%3E");
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(197, 168, 128, 0.2);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(197, 168, 128, 0.4);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 1800px;
    margin: 0 auto;
}

/* Sidebar */
.sidebar {
    width: 340px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--glass-border);
    padding: 30px 24px;
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 20px;
}

.logo-icon {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--accent-gold), var(--primary-color));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(21, 128, 61, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-icon i {
    font-size: 20px;
    color: #051412;
}

.logo-text h1 {
    font-family: var(--font-logo);
    font-size: 26px;
    font-weight: 700;
    color: var(--color-gold);
    line-height: 1.1;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.logo-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-top: 3px;
}

/* Quick Prompts */
.quick-prompts-container {
    flex: 1;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.quick-prompts-container h3 {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.quick-prompts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quick-prompt-card {
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 13px;
    text-align: right;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.quick-prompt-card i {
    color: var(--accent-gold);
    font-size: 14px;
    opacity: 0.8;
    transition: transform 0.25s;
}

.quick-prompt-card:hover {
    background: rgba(21, 128, 61, 0.1);
    border-color: var(--glass-border-focus);
    transform: translateX(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.quick-prompt-card:hover i {
    transform: scale(1.1) rotate(-5deg);
    color: var(--color-gold);
}

/* Actions */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 20px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    font-size: 13.5px;
    border-radius: 12px;
    transition: all 0.2s ease;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
}

.sidebar-btn.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), #14532d);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 12px rgba(21, 128, 61, 0.15);
}

.sidebar-btn.primary-btn:hover {
    background: linear-gradient(135deg, #15803d, #166534);
    border-color: var(--accent-gold);
}

.sidebar-btn.secondary-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
}

.sidebar-btn.secondary-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Status Panel */
.status-panel {
    padding-top: 10px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error-color);
    box-shadow: 0 0 8px var(--error-color);
    transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.connected {
    background: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: transparent;
}

.chat-header {
    padding: 20px 40px;
    border-bottom: 1px solid var(--glass-border);
    background: var(--chat-header-bg);
    backdrop-filter: blur(12px);
    z-index: 5;
}

.chat-header h2 {
    font-family: var(--font-title);
    font-size: 20px;
    color: var(--color-gold);
    font-weight: 600;
}

.chat-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    max-width: 80%;
    animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.message.user-message {
    align-self: flex-start; /* RTL: aligns right */
}

.message.ai-message {
    align-self: flex-end; /* RTL: aligns left */
    flex-direction: row-reverse;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 17px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.user-message .avatar {
    background: linear-gradient(135deg, var(--primary-color), #14532d);
    color: white;
}

.ai-message .avatar {
    background: linear-gradient(135deg, var(--accent-gold), #856a42);
    color: #051412;
}

.content {
    background: var(--ai-msg-bg);
    border: 1px solid var(--ai-msg-border);
    padding: 16px 20px;
    border-radius: 18px;
    line-height: 1.75;
    font-size: 14.5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    color: #f3f4f6;
}

.user-message .content {
    background: var(--user-msg-bg);
    border: 1px solid var(--user-msg-border);
    border-bottom-right-radius: 4px;
}

.ai-message .content {
    border-bottom-left-radius: 4px;
}

/* Welcome Message Styling */
.welcome-msg {
    max-width: 800px;
    margin: 0 auto;
    align-self: center !important;
}

.welcome-msg .avatar {
    background: linear-gradient(135deg, var(--color-gold), var(--accent-gold));
    color: #051412;
    width: 48px;
    height: 48px;
    font-size: 20px;
}

.welcome-msg .content {
    background: rgba(9, 26, 23, 0.5) !important;
    border: 1px solid var(--glass-border-focus) !important;
    padding: 24px 30px !important;
    border-radius: 20px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.welcome-msg h3 {
    font-family: var(--font-title);
    font-size: 22px;
    color: var(--color-gold);
    margin-bottom: 12px;
}

.welcome-msg p {
    margin-bottom: 14px;
    color: #e2e8f0;
}

.welcome-features {
    list-style: none;
    margin: 18px 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.welcome-features li {
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #cbd5e1;
}

.welcome-features li i {
    color: var(--color-gold);
    font-size: 12px;
}

.welcome-alert {
    background: rgba(197, 168, 128, 0.08);
    border: 1px solid rgba(197, 168, 128, 0.25);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 13.5px;
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
}

.welcome-alert i {
    font-size: 18px;
    color: var(--color-gold);
}

/* Tool execution visual feedback */
.tool-call {
    font-size: 12px;
    color: var(--color-gold);
    background: rgba(197, 168, 128, 0.06);
    padding: 8px 16px;
    border-radius: 24px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    border: 1px solid rgba(197, 168, 128, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: var(--font-body);
}

.tool-call i.fa-spin {
    animation: spin 2.5s linear infinite;
}

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

/* Tool call details styles */
.tool-call-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.tool-call.clickable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, border-color 0.2s;
}

.tool-call.clickable:hover {
    background: rgba(197, 168, 128, 0.15);
    border-color: var(--color-gold);
}

.tool-details-pane {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px;
    margin-top: 6px;
    width: 100%;
    max-width: 650px;
    display: none;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
    animation: detailsSlideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes detailsSlideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.tool-details-section {
    margin-bottom: 12px;
    text-align: right;
    direction: rtl;
}

.tool-details-section:last-child {
    margin-bottom: 0;
}

.tool-details-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-gold);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.tool-details-code {
    direction: ltr;
    text-align: left;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(197, 168, 128, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.tool-details-result {
    direction: rtl;
    text-align: right;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(197, 168, 128, 0.1);
    padding: 10px 14px;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: var(--font-body);
    font-size: 13px;
    line-height: 1.6;
    color: #e2e8f0;
}

/* Input Area */
.input-area {
    padding: 24px 40px;
    background: linear-gradient(to top, var(--bg-color) 60%, transparent);
}

.input-wrapper {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    background: rgba(9, 26, 23, 0.7);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    padding: 10px 16px;
    backdrop-filter: blur(15px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.input-wrapper:focus-within {
    border-color: var(--color-gold);
    box-shadow: 0 10px 35px rgba(21, 128, 61, 0.2), 0 0 0 1px var(--color-gold);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-family: var(--font-body);
    font-size: 15.5px;
    resize: none;
    outline: none;
    padding: 8px 0;
    max-height: 150px;
    line-height: 1.6;
}

#send-btn {
    background: linear-gradient(135deg, var(--color-gold), #b49368);
    color: #051412;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 17px;
    flex-shrink: 0;
    margin-right: 12px;
    box-shadow: 0 4px 10px rgba(197, 168, 128, 0.2);
}

#send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--color-gold), #dfb15b);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(197, 168, 128, 0.4);
}

#send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: var(--text-muted);
    color: var(--bg-color);
    box-shadow: none;
}

/* Settings Modal (Popup) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(3, 11, 10, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #091a17;
    border: 1px solid var(--glass-border-focus);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(197, 168, 128, 0.1);
    padding: 30px;
    position: relative;
    transform: scale(1) translateY(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.9) translateY(20px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 14px;
}

.modal-header h3 {
    font-family: var(--font-title);
    font-size: 20px;
    color: var(--color-gold);
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 28px;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.close-btn:hover {
    color: var(--color-gold);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 13px;
    color: var(--accent-gold);
    font-weight: 500;
}

.api-key-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.api-key-input-wrapper input {
    width: 100%;
}

.input-group .api-key-input-wrapper input {
    padding-left: 45px; /* space for toggle button */
}

#toggle-api-key-btn {
    position: absolute;
    left: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    font-size: 15px;
    transition: color 0.2s;
}

#toggle-api-key-btn:hover {
    color: var(--color-gold);
}

.input-group input, .input-group select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    padding: 12px 14px;
    border-radius: 10px;
    color: white;
    font-family: var(--font-body);
    outline: none;
    transition: all 0.3s;
    font-size: 14px;
}

.input-group input[type="password"] {
    font-family: 'Inter', sans-serif;
    direction: ltr;
    text-align: left;
}

.input-group input[type="text"] {
    font-family: 'Inter', sans-serif;
    direction: ltr;
    text-align: left;
}

.input-group select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23e9c46a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 14px center;
    background-size: 12px;
    padding-left: 40px; /* space for custom gold arrow */
    cursor: pointer;
}

.input-group select option {
    background: #091a17;
    color: #f3f4f6;
    padding: 12px;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--color-gold);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 1px var(--color-gold);
}

.input-group small {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
}

.modal-footer {
    display: flex;
}

.full-width {
    width: 100%;
    padding: 14px;
    font-size: 14.5px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary-color), #14532d);
    color: white;
    font-weight: 600;
    transition: all 0.2s;
}

.full-width:hover {
    background: linear-gradient(135deg, #15803d, #166534);
    box-shadow: 0 4px 12px rgba(21, 128, 61, 0.25);
}

/* Toast Alert */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1100;
    display: flex;
    align-items: center;
    direction: rtl;
}

.success-toast {
    background: rgba(9, 28, 23, 0.95);
    border: 1px solid var(--glass-border-focus);
    color: #f3f4f6;
    box-shadow: 0 10px 30px rgba(21, 128, 61, 0.2), 0 0 0 1px rgba(197, 168, 128, 0.1);
}

.error-toast {
    background: rgba(45, 12, 12, 0.95);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #fee2e2;
    box-shadow: 0 10px 30px rgba(220, 38, 38, 0.15);
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Markdown parsing output layout */
.content h1, .content h2, .content h3, .content h4 {
    margin-top: 18px;
    margin-bottom: 10px;
    color: var(--color-gold);
    font-family: var(--font-title);
}

.content h1 { font-size: 1.6rem; }
.content h2 { font-size: 1.4rem; }
.content h3 { font-size: 1.2rem; }

.content p {
    margin-bottom: 12px;
}

.content blockquote {
    border-right: 3px solid var(--color-gold);
    border-left: none;
    padding: 12px 18px;
    margin: 16px 0;
    background: rgba(197, 168, 128, 0.04);
    font-family: var(--font-quran);
    font-size: 21px;
    color: var(--color-gold);
    text-align: center;
    border-radius: 6px;
    line-height: 1.8;
}

.content ul, .content ol {
    margin-right: 24px;
    margin-bottom: 12px;
}

.content li {
    margin-bottom: 6px;
}

.content strong {
    color: var(--color-gold);
    font-weight: 700;
}

/* Responsive Rules */
@media (max-width: 900px) {
    body {
        flex-direction: column;
    }
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        border-left: none;
        border-bottom: 1px solid var(--glass-border);
        padding: 18px 20px;
    }
    .logo-container {
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
    .quick-prompts-container {
        display: none; /* Hide scroll suggestions on mobile to prevent clutter */
    }
    .sidebar-actions {
        flex-direction: row;
        border-bottom: none;
        padding-bottom: 0;
        margin-bottom: 8px;
        gap: 12px;
    }
    .sidebar-btn {
        padding: 10px;
        font-size: 12.5px;
    }
    .status-panel {
        display: none;
    }
    .chat-header {
        padding: 14px 20px;
    }
    .chat-header h2 {
        font-size: 18px;
    }
    .chat-header p {
        font-size: 12px;
    }
    .chat-container {
        padding: 20px;
        gap: 18px;
    }
    .message {
        max-width: 92%;
    }
    .welcome-features {
        grid-template-columns: 1fr;
    }
    .input-area {
        padding: 12px 20px;
    }
    .input-wrapper {
        padding: 8px 12px;
    }
    #user-input {
        font-size: 14.5px;
    }
    #send-btn {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }
}
