:root {
    --bg: #0f172a;
    --card: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --error: #ef4444;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    height: 100vh; /* পুরোনো ব্রাউজারের জন্য ফলব্যাক */
    height: 100dvh; /* মোবাইল ব্রাউজারের জন্য পারফেক্ট ফিক্স */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    height: 100vh; /* পুরোনো ব্রাউজারের জন্য ফলব্যাক */
    height: 100dvh; /* মোবাইল ব্রাউজারের জন্য পারফেক্ট ফিক্স */
    background: var(--card);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    position: relative; /* Required for sidebar */
}


@media (min-width: 768px) {
    .chat-container {
        height: 95vh;
        max-height: 800px;
        border-radius: 20px;
        margin: 0 15px;
        overflow: hidden; /* Prevent sidebar spilling out */
    }
}

/* Sidebar Styles */
.btn-menu {
    background: transparent; border: none; color: var(--text);
    cursor: pointer; display: flex; align-items: center; padding: 4px;
    transition: 0.2s;
}
.btn-menu:hover { color: var(--accent); }

.sidebar-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 90; display: none;
    border-radius: inherit;
}
.sidebar-overlay.open { display: block; }

.sidebar {
    position: absolute; top: 0; left: -260px; width: 250px; height: 100%;
    background: var(--card); border-right: 1px solid var(--border);
    z-index: 100; transition: left 0.3s ease; display: flex;
    flex-direction: column; padding: 16px; border-radius: inherit;
    border-top-right-radius: 0; border-bottom-right-radius: 0;
}
.sidebar.open { left: 0; }

.btn-new-chat {
    background: var(--accent); color: white; border: none;
    padding: 12px; border-radius: 10px; cursor: pointer;
    font-weight: 600; font-size: 14px; display: flex; align-items: center;
    justify-content: center; gap: 8px; margin-bottom: 16px; transition: 0.2s;
}
.btn-new-chat:hover { background: var(--accent-hover); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.chat-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; background: var(--bg); border-radius: 8px;
    cursor: pointer; transition: 0.2s; border: 1px solid transparent; gap: 10px;
}
.chat-item:hover { background: #243045; }
.chat-item.active { border-color: var(--accent); background: rgba(59, 130, 246, 0.1); }
.chat-item span {
    flex: 1; font-size: 13px; color: var(--text); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.btn-delete-chat {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    padding: 4px; border-radius: 4px; transition: 0.2s;
}
.btn-delete-chat:hover { background: rgba(239, 68, 68, 0.2); color: var(--error); }

/* Header */
.chat-header {
    background: var(--card); color: var(--text); padding: 12px 16px;
    font-size: 18px; font-weight: 700; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}

.btn-settings {
    width: 36px; height: 36px; border-radius: 50%; background: transparent;
    border: 1px solid var(--border); color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; flex-shrink: 0;
}
.btn-settings:hover { background: rgba(59, 130, 246, 0.1); border-color: var(--accent); color: var(--accent); transform: rotate(90deg); }
.btn-settings.active { background: var(--accent); border-color: var(--accent); color: white; transform: rotate(90deg); }

/* Settings Panel */
.settings-panel {
    background: #1a2332; border-bottom: 1px solid var(--border); padding: 0 16px;
    display: flex; flex-direction: column; gap: 10px; max-height: 0; overflow: hidden;
    transition: all 0.3s ease; opacity: 0;
}
.settings-panel.open { max-height: 300px; padding: 12px 16px; opacity: 1; }

.api-row { display: flex; gap: 8px; align-items: center; }
.api-row input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--bg); color: var(--text); outline: none; transition: border 0.2s; }
.api-row input:focus { border-color: var(--accent); }
.api-row input::placeholder { color: #64748b; font-size: 12px; }

.btn-connect { padding: 10px 16px; background: var(--accent); color: white; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; transition: all 0.2s; flex-shrink: 0; }
.btn-connect:hover { background: var(--accent-hover); }
.btn-connect:active { transform: scale(0.96); }

.model-select { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--bg); color: var(--text); cursor: pointer; outline: none; width: 100%; }
.model-select:focus { border-color: var(--accent); }
.model-select option { background: var(--card); color: var(--text); padding: 8px; }

optgroup { font-weight: 700; font-size: 12px; color: var(--text-secondary); letter-spacing: 0.5px; }

.status-badge { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
.status-offline { color: var(--error); background: rgba(239, 68, 68, 0.15); }
.status-online { color: var(--success); background: rgba(34, 197, 94, 0.15); }

/* Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; background: var(--bg); display: flex; flex-direction: column; gap: 12px; touch-action: manipulation; }
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.message { display: flex; align-items: flex-start; animation: slideIn 0.25s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message.user { justify-content: flex-end; }

.message-content { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.6; word-wrap: break-word; white-space: pre-wrap; }
@media (min-width: 768px) { .message-content { max-width: 75%; font-size: 15px; padding: 12px 18px; } }

.message.ai .message-content { background: var(--card); color: var(--text); border: 1px solid var(--border); border-top-left-radius: 4px; }
.message.user .message-content { background: var(--accent); color: white; border-top-right-radius: 4px; }

/* Typing Indicator */
.typing-indicator { display: none; padding: 8px 16px; color: var(--text-secondary); font-size: 13px; background: var(--bg); flex-shrink: 0; }
.typing-indicator.active { display: flex; align-items: center; gap: 6px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); animation: dotBounce 1.4s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* Input Area */
/* Input Area Updated for Textarea */
.chat-input-container {
    padding: 10px 12px;
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .chat-input-container {
        padding: 14px 16px;
    }
}

.chat-input-container textarea {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 25px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border 0.2s;
    resize: none; /* ইউজার যেন টেনে বড় করতে না পারে */
    height: 44px; /* ইনপুট বক্সের মতো সাইজ রাখার জন্য */
    line-height: 20px;
    font-family: inherit;
    overflow: hidden;
}

.chat-input-container textarea:focus {
    border-color: var(--accent);
}

.chat-input-container textarea::placeholder {
    color: #64748b;
    line-height: 20px;
}

.chat-input-container textarea:disabled {
    opacity: 0.4;
}


.btn-send { width: 42px; height: 42px; min-width: 42px; border-radius: 50%; background: var(--accent); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; padding: 0; }
.btn-send:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.05); }
.btn-send:active:not(:disabled) { transform: scale(0.92); }
.btn-send:disabled { background: #475569; cursor: not-allowed; opacity: 0.5; }
.send-icon { width: 20px; height: 20px; fill: none; stroke: white; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Markdown and Code Box Styling */
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.code-wrapper { background: #1a1b26; border-radius: 8px; margin: 10px 0; overflow: hidden; border: 1px solid var(--border); }
.code-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #24283b; color: #a9b1d6; font-size: 12px; font-family: monospace; border-bottom: 1px solid #1f2335; }
.code-header .lang-name { text-transform: uppercase; font-weight: bold; }
.btn-copy, .btn-preview { background: transparent; border: none; color: #a9b1d6; cursor: pointer; font-size: 12px; display: flex; align-items: center; gap: 5px; transition: color 0.2s; }
.btn-copy:hover, .btn-preview:hover { color: #7aa2f7; }
.code-wrapper pre { margin: 0; padding: 12px; overflow-x: auto; }
.code-wrapper code { font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 1.5; }
:not(pre) > code { background: rgba(0,0,0,0.3); padding: 2px 5px; border-radius: 4px; font-family: monospace; font-size: 0.9em; color: #ff9e64; }
