/**
 * LUNA 2.0 Styles
 */

/* CSS Variables */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --border-color: #2a2a35;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --message-user-bg: #1e3a5f;
    --message-assistant-bg: #1a1a25;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* App Container */
#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    width: 100%;
}

.screen.active {
    display: flex;
}

/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.loading-container {
    text-align: center;
}

.logo {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Auth Screens (Setup & Login) */
#setup-screen,
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--bg-secondary);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.auth-container .logo {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.auth-container h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.auth-container p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

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

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-primary {
    width: 100%;
    padding: 1rem;
    color: white;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-icon {
    font-size: 1.25rem;
}

/* Messages */
.error-message {
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 1rem;
}

.status-message {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Chat Screen */
#chat-screen {
    flex-direction: column;
    background: var(--bg-primary);
}

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

.header-left, .header-center, .header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-small {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#session-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

#user-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Chat Main */
.chat-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 1rem;
    margin-bottom: 1rem;
}

.luna-avatar {
    font-size: 2.5rem;
}

.welcome-text h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.welcome-text p {
    color: var(--text-secondary);
}

/* Messages */
.message {
    max-width: 80%;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

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

.message-user {
    margin-left: auto;
}

.message-assistant,
.message-error {
    margin-right: auto;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
}

.message-user .message-content {
    background: var(--message-user-bg);
    border-bottom-right-radius: 0.25rem;
}

.message-assistant .message-content {
    background: var(--message-assistant-bg);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 0.25rem;
}

.message-error .message-content {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
}

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

.message-user .message-time {
    text-align: right;
}

/* Code in messages */
.message-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-primary);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

.message-content pre {
    margin: 0.5rem 0;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: 0.5rem;
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    padding: 0;
}

/* Typing Indicator */
.typing-indicator .message-content {
    display: flex;
    gap: 0.25rem;
    padding: 1rem;
}

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

.typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }

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

/* Chat Footer */
.chat-footer {
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.chat-input-form {
    max-width: 900px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#chat-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    padding: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: transparent;
    border: none;
    resize: none;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
}

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

.btn-send {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    color: white;
    flex-shrink: 0;
}

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

.btn-send svg {
    width: 20px;
    height: 20px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* Responsive */
@media (max-width: 768px) {
    .auth-container {
        margin: 1rem;
        max-width: none;
    }

    .message {
        max-width: 90%;
    }

    .chat-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ========================================
   File Explorer
   ======================================== */

.btn-icon-only {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-only:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
}

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

/* File Explorer Panel */
.files-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: right 0.3s ease;
}

.files-panel.active {
    right: 0;
}

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

.files-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    overflow: hidden;
}

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

/* Breadcrumb */
#files-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    overflow-x: auto;
    white-space: nowrap;
}

.breadcrumb-item {
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.breadcrumb-item:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.breadcrumb-sep {
    color: var(--text-muted);
}

/* File List */
.files-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.files-loading,
.files-empty,
.files-error {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
}

.files-error {
    color: var(--error);
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.file-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* File Preview */
.files-preview {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.files-preview.active {
    opacity: 1;
    visibility: visible;
}

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

#preview-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

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

.code-preview,
.text-preview {
    margin: 0;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    color: var(--text-secondary);
}

.code-preview code {
    background: none;
    padding: 0;
}

/* Responsive File Explorer */
@media (max-width: 768px) {
    .files-panel {
        width: 100%;
        right: -100%;
    }
}
