/**
 * Trợ lý Kira - Styles
 * Design đẹp, tối ưu mobile
 */

:root {
    /* Light theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --user-bubble: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --assistant-bubble: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --accent-light: #1e1b4b;
    --assistant-bubble: #1e293b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* App Layout */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--user-bubble);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
}

.logo-text {
    font-weight: 600;
    font-size: 1.1rem;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
}

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

.sidebar-section {
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title i {
    font-size: 0.875rem;
}

/* Document Upload */
.document-upload {
    margin-bottom: 0.75rem;
}

.upload-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent-light);
    color: var(--accent-color);
    border: 1px dashed var(--accent-color);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.upload-btn:hover {
    background: var(--accent-color);
    color: white;
    border-style: solid;
}

.document-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.875rem;
}

.document-item i {
    color: var(--accent-color);
}

.document-item .doc-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-item .delete-doc {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.document-item:hover .delete-doc {
    opacity: 1;
}

.document-item .delete-doc:hover {
    color: #ef4444;
}

.settings-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

.settings-btn:hover {
    background: var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header */
.chat-header {
    padding: 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
}

.header-info {
    flex: 1;
}

.header-info h1 {
    font-size: 1.125rem;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
}

.messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.loading-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-muted);
}

.loading-messages.hidden {
    display: none;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 0.75rem;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--user-bubble);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--accent-light);
    color: var(--accent-color);
}

.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.message.user .message-content {
    align-items: flex-end;
}

.message-bubble {
    padding: 0.875rem 1rem;
    border-radius: 16px;
    font-size: 0.9375rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--assistant-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.message-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    padding: 0 0.5rem;
}

/* Generated Image in Message */
.message-image {
    max-width: 300px;
    border-radius: 12px;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Input Area */
.input-area {
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 16px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}

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

.attach-btn {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--bg-secondary);
    color: var(--accent-color);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 0.9375rem;
    color: var(--text-primary);
    resize: none;
    max-height: 150px;
    padding: 0.625rem 0;
    font-family: inherit;
    line-height: 1.5;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--user-bubble);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    max-width: 90%;
    max-height: 90%;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#modalImage {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 12px;
}

/* System Prompt Modal */
.prompt-modal-content {
    width: 100%;
    max-width: 600px;
    padding: 0;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-header .modal-close {
    position: static;
}

.modal-body {
    padding: 1.5rem;
}

#systemPromptInput {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.875rem;
    color: var(--text-primary);
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

#systemPromptInput:focus {
    outline: none;
    border-color: var(--accent-color);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-primary {
    background: var(--accent-color);
    border: none;
    color: white;
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--accent-color);
}

/* Code blocks */
.message-bubble pre {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-bubble code {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
}

.message-bubble p code {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 99;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-close {
        display: block;
    }
    
    .menu-btn {
        display: block;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chat-container {
        padding: 0.75rem;
    }
    
    .input-area {
        padding: 0.75rem;
    }
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.875rem;
}


/* Markdown Styles */
.message-bubble h2.md-h2,
.message-bubble h3.md-h3,
.message-bubble h4.md-h4 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-bubble h2.md-h2 {
    font-size: 1.4em;
    color: var(--accent-color);
}

.message-bubble h3.md-h3 {
    font-size: 1.2em;
    color: var(--accent-color);
}

.message-bubble h4.md-h4 {
    font-size: 1.1em;
    color: var(--text-primary);
}

.message-bubble strong {
    font-weight: 600;
    color: var(--accent-color);
}

.message-bubble em {
    font-style: italic;
}

.message-bubble del {
    text-decoration: line-through;
    opacity: 0.7;
}

.message-bubble code.inline-code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-bubble pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-bubble pre code {
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 0.9em;
    line-height: 1.5;
}

.message-bubble hr.md-hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

/* Markdown Tables */
.message-bubble table.md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9em;
}

.message-bubble table.md-table th,
.message-bubble table.md-table td {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
}

.message-bubble table.md-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    text-align: left;
}

.message-bubble table.md-table tr:nth-child(even) {
    background: var(--bg-tertiary);
}

.message-bubble table.md-table tr:hover {
    background: var(--accent-light);
}

/* Markdown Lists */
.message-bubble ul.md-ul,
.message-bubble ol.md-ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-bubble li.md-li,
.message-bubble li.md-oli {
    margin: 4px 0;
    line-height: 1.6;
}

.message-bubble ul.md-ul li.md-li {
    list-style-type: disc;
}

.message-bubble ol.md-ol li.md-oli {
    list-style-type: decimal;
}

/* User message markdown - lighter colors */
.message.user .message-bubble strong {
    color: #fff;
    font-weight: 700;
}

.message.user .message-bubble h2.md-h2,
.message.user .message-bubble h3.md-h3,
.message.user .message-bubble h4.md-h4 {
    color: #fff;
}

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

.message.user .message-bubble pre {
    background: rgba(255, 255, 255, 0.15);
}

.message.user .message-bubble table.md-table th,
.message.user .message-bubble table.md-table td {
    border-color: rgba(255, 255, 255, 0.3);
}

.message.user .message-bubble table.md-table th {
    background: rgba(255, 255, 255, 0.15);
}

.message.user .message-bubble table.md-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.1);
}
