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

body {
    font-family: 'Vazirmatn', sans-serif;
    background: radial-gradient(circle at 20% 30%, #0a0a1a, #02020c);
    min-height: 100vh;
}

:root {
    --bg-color: #fff;
    --chat-bg: #fff;
    --header-bg: #fff;
    --text-color: #000;
    --border-color: #ccc;
    --input-bg: #f5f5f5;
    --msg-ai-bg: #f0f0f0;
    --msg-ai-text: #000;
    --btn-bg: #e0e0e0;
    --sidebar-width: 300px;
    --action-bg: #fff;
    --action-color: #333;
    --code-bg: #1e1e2f;
    --code-color: #f8f8f2;
    --send-btn-bg: #245FFC;
}

body.dark {
    --bg-color: #000;
    --chat-bg: #000;
    --header-bg: #000;
    --text-color: #fff;
    --border-color: #333;
    --input-bg: #1a1a1a;
    --msg-ai-bg: #1a1a1a;
    --msg-ai-text: #fff;
    --btn-bg: #2a2a2a;
    --action-bg: #2a2a2a;
    --action-color: #ddd;
    --code-bg: #0d0d1a;
    --code-color: #e0e0e0;
}

body {
    background: var(--bg-color);
}

.chat-container {
    width: 100%;
    height: 100vh;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: nowrap;
    min-height: 54px;
}

.brand-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-color);
    flex-shrink: 0;
}

.brand-name img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #245FFC;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.model-dialog-btn,
.system-prompt-btn {
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 16px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 0.75rem;
    white-space: nowrap;
    font-family: inherit;
}

.hamburger-btn,
.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}

.sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--chat-bg);
    border-left: 1px solid var(--border-color);
    transition: right .3s;
    z-index: 20;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.sidebar-header span {
    color: var(--text-color);
    font-weight: 600;
    font-size: 1.1rem;
}

.sidebar-close {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
}

.new-chat-btn {
    background: var(--btn-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 20px;
    font-family: inherit;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.logout-sidebar-btn {
    background: #C62828;
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    margin-top: auto;
    font-family: inherit;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 15px;
}

.chat-history-item {
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
    color: var(--text-color);
    align-items: center;
}

.chat-history-item:hover {
    background: var(--btn-bg);
}

.chat-history-item i {
    color: #245FFC;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
}

.welcome-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-color);
}

.welcome-message h1 {
    font-size: 1.8rem;
    opacity: 0.7;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: .95rem;
    line-height: 1.5;
    animation: fadeIn .2s;
    word-wrap: break-word;
}

.message.ai {
    align-self: flex-start;
    background: var(--msg-ai-bg);
    color: var(--msg-ai-text);
    border-bottom-right-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background: #000;
    color: #fff;
    border-bottom-left-radius: 4px;
}

body.dark .message.user {
    background: #fff;
    color: #000;
}

.message.error {
    background: transparent;
    padding: 0;
    max-width: 100%;
}

.message-footer {
    margin-top: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.message-time {
    font-size: .65rem;
    opacity: .7;
}

.action-btn {
    background: var(--action-bg);
    border: 1px solid var(--border-color);
    color: var(--action-color);
    padding: 3px 6px;
    border-radius: 6px;
    font-size: .7rem;
    cursor: pointer;
    margin-left: 4px;
    font-family: inherit;
}

.message-actions {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
}

.error-message {
    color: #ff4444;
    background: rgba(255, 68, 68, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin: 4px 0;
}

pre {
    background: var(--code-bg);
    color: var(--code-color);
    padding: 12px;
    border-radius: 12px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 13px;
    margin: 8px 0;
    position: relative;
}

.copy-code-btn {
    position: absolute;
    top: 5px;
    left: 5px;
    background: #245FFC;
    border: none;
    color: #fff;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}

.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--msg-ai-bg);
    border-radius: 18px;
    align-self: flex-start;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%,
    100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.chat-input-area {
    padding: 15px 20px;
    background: var(--chat-bg);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 40px;
    padding: 4px 12px;
}

.input-wrapper input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: .95rem;
    outline: none;
    color: var(--text-color);
    font-family: inherit;
}

.send-btn,
.upload-img-btn {
    background: var(--send-btn-bg);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: 0.2s;
    font-size: 1rem;
}

.send-btn:hover,
.upload-img-btn:hover {
    opacity: 0.85;
    transform: scale(0.96);
}

.model-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .8);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: .2s;
}

.model-modal.show {
    visibility: visible;
    opacity: 1;
}

.model-modal-content {
    background: var(--chat-bg);
    border-radius: 20px;
    padding: 24px;
    width: 320px;
    text-align: center;
    color: var(--text-color);
    max-height: 90vh;
    overflow-y: auto;
}

.model-option {
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    padding: 12px;
    margin: 10px 0;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.95rem;
    width: 100%;
    text-align: center;
}

.model-option .model-desc {
    display: block;
    font-size: 0.8rem;
    color: #999;
    margin-top: 4px;
}

.close-modal {
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    margin-top: 10px;
}

.system-prompt-modal textarea {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    margin: 10px 0;
    resize: vertical;
}

.system-prompt-modal .modal-desc {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 10px;
}

#fileUploadModal .model-modal-content {
    max-width: 500px;
    width: 90%;
}

#fileInput {
    display: block;
    margin: 12px auto;
    color: var(--text-color);
    font-family: inherit;
}

#filePreview {
    margin: 10px 0;
    text-align: center;
    min-height: 40px;
}

#filePreview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
}

#fileStatus {
    font-size: 12px;
    min-height: 20px;
    color: var(--text-color);
}

#pdfExtractArea {
    display: none;
    margin-top: 10px;
}

#pdfExtractArea textarea {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
}

#ocrArea {
    display: none;
    margin-top: 10px;
}

#ocrStatus {
    font-size: 12px;
    margin-top: 5px;
    min-height: 20px;
    color: var(--text-color);
}

@media (max-width: 640px) {
    .chat-header {
        padding: 6px 10px;
        gap: 4px;
    }
    .brand-name {
        font-size: 0.95rem;
    }
    .brand-name img {
        width: 24px;
        height: 24px;
    }
    .model-dialog-btn,
    .system-prompt-btn {
        padding: 3px 8px;
        font-size: 0.65rem;
        border-radius: 12px;
    }
    .hamburger-btn,
    .theme-toggle {
        font-size: 1rem;
        padding: 3px 5px;
    }
}

@media (max-width: 560px) {
    .send-btn,
    .upload-img-btn {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }
    .input-wrapper {
        gap: 5px;
        padding: 4px 8px;
    }
    .input-wrapper input {
        padding: 8px 0;
        font-size: .9rem;
    }
}

@media (max-width: 450px) {
    .send-btn,
    .upload-img-btn {
        width: 36px;
        height: 36px;
        font-size: 0.8rem;
    }
}

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