/* Base styles and variables */
:root {
    --bg-color: #131314;
    --surface-color: #1e1f20;
    --surface-hover: #2a2b2c;
    --text-primary: #e3e3e3;
    --text-secondary: #c4c7c5;
    --accent-color: #a8c7fa;
    --accent-hover: #8ab4f8;
    --border-color: #3c4043;
    --glass-bg: rgba(30, 31, 32, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --error-color: #f28b82;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Glassmorphism utility */
.glass-effect {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* --- Login Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    padding: 2.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal-content h2 {
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, #4285f4, #ea4335, #fbbc05, #34a853);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.8rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

#password-input {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#password-input:focus {
    border-color: var(--accent-color);
}

#login-btn {
    width: 100%;
    padding: 0.8rem;
    border-radius: 8px;
    border: none;
    background: var(--accent-color);
    color: #000;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#login-btn:hover {
    background: var(--accent-hover);
}

#login-btn:active {
    transform: scale(0.98);
}

.error-msg {
    color: var(--error-color) !important;
    margin-top: 1rem;
    margin-bottom: 0 !important;
}

/* --- App Container --- */
#app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- Sidebar --- */
#sidebar {
    width: 300px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

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

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--surface-hover);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.history-item {
    padding: 0.8rem 1.2rem;
    margin: 0.2rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: background 0.2s;
}

.history-item:hover, .history-item.active {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.loading-history {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- Main Chat Area --- */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-color);
}

.chat-header {
    height: 60px;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s;
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 80px 2rem 120px 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    scroll-behavior: smooth;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.welcome-screen h2 {
    font-size: 2.5rem;
    font-weight: 500;
    background: linear-gradient(90deg, #4285f4, #ea4335, #fbbc05, #34a853);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-top: 1rem;
}

/* Message Bubbles */
.message {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    gap: 1.5rem;
}

.message.user {
    justify-content: flex-end;
    position: relative;
}

.message-content {
    padding: 1rem 1.5rem;
    border-radius: 24px;
    font-size: 1rem;
    line-height: 1.6;
    max-width: 85%;
}

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

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

/* Szerkesztés gomb user üzenetnél */
.edit-msg-btn {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translate(-10px, -50%);
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s, background 0.2s;
}

.message.user:hover .edit-msg-btn {
    opacity: 1;
}

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


/* Markdown styling inside messages */
.message-content p { margin-bottom: 1rem; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
}
.message-content code {
    font-family: monospace;
    background: rgba(255,255,255,0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}
.message-content pre code {
    background: transparent;
    padding: 0;
}
.message-content ul, .message-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 0.3rem;
    padding: 1rem 0;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* --- Input Area --- */
.input-area-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0 2rem 1.5rem 2rem;
    background: linear-gradient(transparent, var(--bg-color) 40%);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    border-radius: 24px;
    padding: 0.8rem 1.2rem;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
}

#prompt-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    padding: 0.4rem 0;
}

#prompt-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#prompt-input::placeholder {
    color: #6c6f72;
}

.send-btn {
    background: var(--surface-color);
    border: none;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.send-btn:not(:disabled):hover {
    background: var(--accent-color);
    color: #000;
}

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

/* Stop Mode Button */
.send-btn.stop-mode {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.send-btn.stop-mode:hover {
    background: var(--surface-hover);
    color: var(--error-color);
}

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

/* Responsive */
.mobile-only {
    display: none;
}

#sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9;
    display: none;
}
#sidebar-overlay.open {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }
    #sidebar {
        position: absolute;
        transform: translateX(-100%);
        transition: transform 0.3s;
        background: var(--bg-color);
        height: 100%;
        z-index: 10;
        box-shadow: 4px 0 15px rgba(0,0,0,0.5);
    }
    #sidebar.open {
        transform: translateX(0);
    }
}
