:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161b26;
    --bg-tertiary: #1e2533;
    --bg-hover: #252d3d;
    --border: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f2f5;
    --text-secondary: #9aa3b5;
    --text-muted: #6b7589;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --user-bubble: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --bot-bubble: #1e2533;
    --success: #22c55e;
    --danger: #ef4444;
    --sidebar-width: 300px;
    --header-height: 64px;
    --input-height: 88px;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100dvh;
    overflow: hidden;
    direction: rtl;
}

.app {
    display: flex;
    height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    background: var(--user-bubble);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.brand p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}

.btn-new-chat:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-new-chat svg {
    width: 18px;
    height: 18px;
}

.sidebar-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
}

.sidebar-section h2 {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 8px 10px;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    border: 1px solid transparent;
}

.chat-history-item:hover {
    background: var(--bg-hover);
}

.chat-history-item.active {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

.chat-history-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chat-history-item span {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-history-item .btn-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: opacity var(--transition), color var(--transition);
}

.chat-history-item:hover .btn-delete {
    opacity: 1;
}

.chat-history-item .btn-delete:hover {
    color: var(--danger);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.copyright {
    font-size: 0.625rem;
    line-height: 1.6;
    color: var(--text-muted);
    text-align: center;
    opacity: 0.75;
}

.copyright a {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dotted rgba(255, 255, 255, 0.2);
    transition: color 0.2s, opacity 0.2s;
}

.copyright a:hover {
    color: var(--accent-hover);
    opacity: 1;
}

.maintenance-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    position: relative;
    z-index: 1;
}

.maintenance-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    opacity: 0.8;
}

.maintenance-screen h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.maintenance-screen p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    max-width: 400px;
    line-height: 1.7;
}

/* Main chat area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
    position: relative;
}

.chat-main::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

.chat-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 23, 0.8);
    backdrop-filter: blur(12px);
    position: relative;
    z-index: 10;
}

.btn-menu,
.btn-clear {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}

.btn-menu {
    display: none;
}

.btn-menu:hover,
.btn-clear:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-menu svg,
.btn-clear svg {
    width: 20px;
    height: 20px;
}

.header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-info h2 {
    font-size: 0.9375rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 24px;
    text-align: center;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.welcome-icon svg {
    width: 36px;
    height: 36px;
    color: var(--accent);
}

.welcome-screen h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-screen > p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    max-width: 400px;
    margin-bottom: 32px;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
}

.suggestion-chip {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition);
}

.suggestion-chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.messages {
    padding: 24px 20px;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    width: 100%;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* RTL: flex-start = راست، flex-end = چپ */
.message.user {
    justify-content: flex-start;
    flex-direction: row;
}

.message.assistant {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
}

.message.user .message-avatar {
    background: var(--user-bubble);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--accent);
}

.message-content {
    max-width: 95%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.7;
    word-break: break-word;
}

.message.user .message-content {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bot-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.typing-indicator {
    display: flex;
    width: 100%;
    gap: 12px;
    padding: 0 20px;
    max-width: 800px;
    margin: 0 auto 20px;
    animation: fadeIn 0.3s ease;
    justify-content: flex-end;
    flex-direction: row-reverse;
}

.typing-indicator.hidden {
    display: none;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--bot-bubble);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-bottom-right-radius: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.error-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--danger);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

.error-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Input area */
.input-area {
    padding: 16px 20px 20px;
    background: rgba(15, 17, 23, 0.9);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

.input-form {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    padding: 8px 4px;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 42px;
    height: 42px;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), opacity var(--transition);
    flex-shrink: 0;
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-send:not(:disabled):hover {
    background: var(--accent-hover);
}

.btn-send svg {
    width: 20px;
    height: 20px;
}

.btn-send .icon-loading {
    display: none;
    animation: spin 1s linear infinite;
}

.btn-send.loading .icon-send {
    display: none;
}

.btn-send.loading .icon-loading {
    display: block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.input-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100dvh;
        transform: translateX(100%);
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .btn-menu {
        display: flex;
    }

    .message-content {
        max-width: 88%;
    }

    .suggestions {
        flex-direction: column;
    }

    .suggestion-chip {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .input-area {
        padding: 12px;
    }

    .messages {
        padding: 16px 12px;
    }
}
