/* ============================================================
   DEXTRA LocalRAG - Styles (ChatGPT-like Theme)
   ============================================================ */

:root {
    /* Colors - ChatGPT Dark Theme */
    --bg-primary: #343541;
    --bg-secondary: #202123; /* Sidebar */
    --bg-tertiary: #2A2B32;
    --bg-chat: #343541;
    --bg-message-user: #343541;
    --bg-message-assistant: #444654;
    --bg-code: #000000;
    --bg-input: #40414F;
    
    --text-primary: #ECECF1;
    --text-secondary: #C5C5D2;
    --text-muted: #8E8EA0;
    
    --accent-primary: #10a37f; /* ChatGPT Green */
    --accent-secondary: #1a7f64;
    --accent-success: #10a37f;
    --accent-error: #ef4444;
    --accent-warning: #eab308;
    
    --border-color: #565869; /* Subtle borders */
    --border-light: #4d4d4f;
    
    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 0px; /* Hidden header in main view usually */
    --input-height: auto;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

html, body {
    height: 100%;
    font-family: 'Söhne', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* ============================================================
   Login Screen
   ============================================================ */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-box {
    background: var(--bg-primary); /* Blend with bg */
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header {
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.login-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

.form-group {
    margin-bottom: 1.25rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-group input {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.btn-login {
    width: 100%;
    padding: 0.875rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

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

.error-message {
    color: var(--accent-error);
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* ============================================================
   Main App Container
   ============================================================ */

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 0.5rem;
    margin: 0.5rem;
}

.btn-new-chat {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    text-align: left;
}

.btn-new-chat:hover {
    background: var(--bg-tertiary);
}

.btn-new-chat::before {
    content: "+";
    font-size: 1.2rem;
    line-height: 1;
}

.btn-new-chat svg {
    display: none; /* Hide old icon if present in HTML */
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-item {
    padding: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 0.25rem;
    transition: background var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    position: relative;
}

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

.chat-item.active {
    background: var(--bg-tertiary);
}

.chat-item-icon {
    color: var(--text-secondary);
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    transition: opacity var(--transition-fast);
}

.chat-item:hover .chat-item-delete {
    opacity: 1;
}

.chat-item-delete:hover {
    color: var(--accent-error);
}

.sidebar-footer {
    padding: 0.5rem;
    border-top: 1px solid var(--border-light);
}

.user-info {
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-info:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 2px;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    flex: 1;
}

/* ============================================================
   Chat Main Area
   ============================================================ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    position: relative;
}

.chat-header {
    display: none; /* Hide header for cleaner look */
}

/* ============================================================
   Messages Area
   ============================================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 150px; /* Space for input */
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}

.welcome-message h2 {
    font-size: 2.25rem;
    font-weight: 600;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.search-commands {
    display: none; /* Hide for now or restyle if needed */
}

.example-prompts {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-width: 720px;
    width: 100%;
}

.example-btn {
    background: var(--bg-secondary); /* Slightly lighter than bg */
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.875rem;
    line-height: 1.4;
}

.example-btn:hover {
    background: var(--bg-tertiary);
}

.example-btn strong {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

/* Message Styles - Row Layout */
.message {
    width: 100%;
    padding: 1.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.message.user {
    background: var(--bg-message-user);
}

.message.assistant {
    background: var(--bg-message-assistant);
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.message-content-wrapper {
    max-width: 48rem; /* approx 768px */
    margin: 0 auto;
    display: flex;
    gap: 1.5rem;
    padding: 0 1rem;
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 2px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.message.user .message-avatar {
    background: #5436DA; /* User color */
    color: white;
}

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

.message-body {
    flex: 1;
    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: break-word;
    min-width: 0; /* Fix flex overflow */
}

.message-meta {
    display: none; /* Hide timestamps for cleaner look */
}

/* ============================================================
   Code Blocks
   ============================================================ */

.code-block {
    margin: 1rem 0;
    border-radius: 6px;
    overflow: hidden;
    background: black;
    border: 1px solid var(--border-light);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: #343541;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.code-language {
    font-family: sans-serif;
    text-transform: lowercase;
}

.btn-copy {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem; /* Added padding for better click area */
    line-height: 1; /* Fix vertical alignment */
}

.btn-copy:hover {
    color: var(--text-primary);
}

.btn-copy svg {
    width: 14px; /* Fixed size for icon */
    height: 14px;
    display: block; /* Remove inline spacing */
}

.code-block pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    background: black;
    color: #d4d4d4;
}

.code-block code {
    font-family: 'Söhne Mono', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
}

/* Inline code */
.message-body code:not(.hljs) {
    background: rgba(255,255,255,0.1);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: monospace;
}

/* ============================================================
   Input Area
   ============================================================ */

.chat-input-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(180deg, rgba(53,53,65,0), var(--bg-primary) 20%);
    padding: 2rem 1rem 3rem;
}

.chat-form {
    max-width: 48rem;
    margin: 0 auto;
    position: relative;
}

.input-wrapper {
    background: var(--bg-input);
    border: 1px solid rgba(32,33,35,0.5);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
    display: flex;
    align-items: flex-end;
}

.input-wrapper:focus-within {
    border-color: rgba(0,0,0,0.3);
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
}

.input-wrapper textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    padding: 0;
    margin-right: 0.75rem;
    font-family: inherit;
}

.input-wrapper textarea:focus {
    outline: none;
}

.btn-send {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.btn-send:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn-send svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
    opacity: 0.8;
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================================
   Settings Modal
   ============================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

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

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: var(--transition-fast);
    line-height: 1;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.settings-section {
    margin-bottom: 2rem;
}

.settings-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.setting-item {
    margin-bottom: 1.5rem;
}

.setting-item label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.setting-item input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition-fast);
}

.setting-item input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.setting-description {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

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

.btn-primary,
.btn-secondary {
    padding: 0.625rem 1.25rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    border: none;
}

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

.btn-primary:hover {
    background: #5568d3;
}

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

.btn-secondary:hover {
    background: #164570;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        z-index: 100;
        height: 100%;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .message-content-wrapper {
        padding: 0 1rem;
    }
}
