:root {
    --bg-primary: #17181a;
    --bg-secondary: #202225;
    --bg-tertiary: #2c2f33;
    --bg-code: #101214;
    --bg-hover: #35383c;
    --text-primary: #f0f2f5;
    --text-secondary: #a8b3cf;
    --text-active: #82aaff;
    --border-color: #3a3d42;
    --error-color: #ff8a80;
    --sidebar-width: 260px;
    --font-family: 'Inter', sans-serif;
    --font-family-code: 'Roboto Mono', monospace;
}

/* --- Base & Reset --- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background-color: var(--bg-primary); color: var(--text-primary); font-family: var(--font-family); font-size: 16px; }
button, a { background: none; border: none; cursor: pointer; color: inherit; text-decoration: none; font-family: inherit; }
.material-symbols-outlined { font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24; font-size: 20px; color: var(--text-secondary); transition: color 0.2s; user-select: none; }

/* --- Accessibility --- */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
*:focus-visible { outline: 2px solid var(--text-active); outline-offset: 2px; border-radius: 4px; }

/* --- Main Layout --- */
.app-container { display: flex; width: 100%; height: 100%; }
.main-wrapper { width: 100%; height: 100%; display: flex; flex-direction: column; }
.main-header { display: flex; align-items: center; padding: 12px 24px; background-color: rgba(23, 24, 26, 0.7); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-color); flex-shrink: 0; position: sticky; top: 0; z-index: 100; }
.header-title { font-size: 1.1rem; font-weight: 600; }
.icon-button { padding: 8px; border-radius: 50%; display: flex; transition: background-color 0.2s; }
.icon-button:hover { background-color: var(--bg-hover); }
.content-area { flex-grow: 1; overflow: hidden; position: relative; }

/* --- Sidebar --- */
#left-sidebar { position: fixed; top: 0; left: 0; height: 100%; width: var(--sidebar-width); max-width: 85%; background-color: var(--bg-secondary); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; z-index: 1001; transform: translateX(-100%); transition: transform 0.3s ease-in-out; }
body.left-sidebar-open #left-sidebar { transform: translateX(0); }
.sidebar-content { padding: 16px; display: flex; flex-direction: column; flex-grow: 1; overflow-y: auto; }
.sidebar-header { font-size: 1.75rem; font-weight: 700; padding: 12px; margin-bottom: 24px; }
.sidebar-nav a, .sidebar-nav button { font-size: 1em; display: flex; align-items: center; gap: 16px; padding: 12px; border-radius: 8px; font-weight: 500; transition: background-color 0.2s, color 0.2s, opacity 0.2s; color: var(--text-secondary); text-align: left; width: 100%; }
.sidebar-nav a:hover, .sidebar-nav button:hover { background-color: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav a.active { background-color: var(--bg-tertiary); color: var(--text-primary); }
.sidebar-nav .material-symbols-outlined { color: var(--text-secondary); }
.sidebar-nav a:hover .material-symbols-outlined, .sidebar-nav a.active .material-symbols-outlined, .sidebar-nav button:hover .material-symbols-outlined { color: var(--text-primary); }
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border-color); }

/* --- Screen Layout --- */
.screen { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.screen.active { display: block; }
#home-screen, #history-screen, #profile-screen { overflow-y: auto; padding: 16px 8px; }
.content-wrapper { max-width: 820px; width: 100%; margin: 0 auto; padding: 16px 0; }
.page-header { margin-bottom: 24px; padding: 0 16px;}
.page-header h2 { font-size: 1.75rem; }

/* --- Home Screen --- */
.home-header { text-align: center; margin-bottom: 40px; padding: 0 16px; }
.home-header h1 { font-size: 2.5rem; margin-bottom: 8px; }
.home-header p { font-size: 1.1rem; color: var(--text-secondary); }
.suggestion-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; padding: 0 16px; }
.suggestion-card { display: block; background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; padding: 20px; transition: background-color 0.2s, border-color 0.2s; }
body:not(.touch-device) .suggestion-card:hover { background-color: var(--bg-tertiary); border-color: #4f5257; }
.suggestion-card .material-symbols-outlined { margin-bottom: 12px; color: var(--text-secondary); }
.suggestion-card h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.suggestion-card p { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.6; }

/* --- History Screen --- */
#history-list-container { padding: 0 16px; }
.history-item { display: block; background-color: var(--bg-secondary); border-radius: 8px; padding: 16px; border: 1px solid var(--border-color); margin-bottom: 12px; transition: background-color 0.2s, border-color 0.2s; }
body:not(.touch-device) .history-item:hover { background-color: var(--bg-tertiary); border-color: #4f5257; }
.history-item p { font-size: 1rem; font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Chat Screen --- */
#chat-screen.active { display: flex; flex-direction: column; position: relative; }
.chat-container { flex-grow: 1; overflow-y: auto; padding: 16px 8px; scroll-behavior: smooth; }
.chat-content-wrapper { display: flex; flex-direction: column; gap: 32px; max-width: 820px; width: 100%; margin: 0 auto; padding: 16px; }
.chat-message { position: relative; background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; display: flex; flex-direction: column; }
.message-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px 0; }
.message-role { font-weight: 700; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.5px; }
.user-message { border-left: 3px solid var(--user-accent-color, #82aaff); }
.user-message .message-role { color: var(--user-accent-color, #82aaff); }
.ai-message { border-left: 3px solid var(--model-accent-color, #c792ea); }
.ai-message .message-role { color: var(--model-accent-color, #c792ea); }
.message-body { padding: 16px 20px; line-height: 1.7; font-size: 1rem; color: var(--text-primary); word-wrap: break-word; }
.message-body p:not(:last-child) { margin-bottom: 1em; }

/* --- Code Box --- */
.code-box { background-color: var(--bg-code); border-radius: 8px; border: 1px solid var(--border-color); overflow: hidden; margin: 1em 0; }
.code-box-header { display: flex; align-items: center; justify-content: flex-end; gap: 8px; background-color: var(--bg-tertiary); padding: 8px 12px; border-bottom: 1px solid var(--border-color); }
.code-box-header .lang-name { margin-right: auto; font-family: var(--font-family-code); font-size: 0.85em; color: var(--text-secondary); text-transform: uppercase; }
.code-box-btn { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background-color: transparent; border: 1px solid var(--border-color); border-radius: 6px; font-size: 0.8em; color: var(--text-secondary); transition: background-color 0.2s, color 0.2s; }
.code-box-btn:hover { background-color: var(--bg-hover); color: var(--text-primary); }
.code-box-btn .material-symbols-outlined { font-size: 16px; }
.code-box pre { margin: 0; }
.code-box code { display: block; padding: 16px; font-family: var(--font-family-code); color: var(--text-primary); white-space: pre-wrap; word-wrap: break-word; overflow-x: auto; background-color: transparent; }

.chat-footer { flex-shrink: 0; padding: 16px 24px; border-top: 1px solid var(--border-color); background: var(--bg-primary); }
.prompt-input-wrapper { position: relative; width: 100%; max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 12px; background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; padding: 8px 12px; transition: border-color 0.2s; }
.prompt-input-wrapper:focus-within { border-color: var(--text-active); }
.prompt-input { width: 100%; background: transparent; border: none; color: var(--text-primary); outline: none; font-size: 1rem; line-height: 1.6; resize: none; max-height: 200px; }
.send-button { background-color: var(--bg-tertiary); width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; align-self: flex-end; transition: all 0.2s ease; transform: scale(0.9); opacity: 0.6; }
.send-button.active { background-color: var(--text-active); transform: scale(1); opacity: 1; }
.send-button.active .material-symbols-outlined { color: var(--bg-primary); }
.send-button:disabled { background-color: var(--bg-tertiary); cursor: not-allowed; opacity: 0.5; }

.typing-indicator { display: flex; align-items: center; gap: 8px; background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; padding: 16px 20px; color: var(--text-secondary); font-style: italic; font-size: 0.9rem; }
.typing-indicator .dot { width: 8px; height: 8px; background-color: var(--text-secondary); border-radius: 50%; animation: typing-bounce 1.2s infinite ease-in-out; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }

.scroll-to-bottom-btn { position: absolute; bottom: 110px; left: 50%; transform: translateX(-50%) translateY(20px); background-color: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 20px; padding: 8px 16px; font-size: 0.9rem; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 10; opacity: 0; visibility: hidden; transition: opacity 0.3s, transform 0.3s, visibility 0.3s; }
.scroll-to-bottom-btn.visible { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

/* --- Profile Screen & Form Group --- */
.profile-card { background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; padding: 24px; margin-bottom: 24px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }
.form-group input { width: 100%; background-color: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 6px; padding: 12px; font-size: 1rem; color: var(--text-primary); outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--text-active); }
.profile-actions { display: flex; justify-content: flex-end; gap: 12px; }
.btn { padding: 10px 20px; font-weight: 600; border-radius: 8px; transition: background-color 0.2s, color 0.2s, opacity 0.2s; }
.btn-primary { background-color: var(--text-active); color: var(--bg-primary); }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-secondary { background: none; border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background-color: var(--bg-hover); }
.btn:disabled { opacity: 0.6; cursor: wait; }

/* --- Modal Component --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; z-index: 2000; }
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal-content { background-color: var(--bg-secondary); padding: 24px; border-radius: 12px; border: 1px solid var(--border-color); width: 90%; max-width: 500px; transform: scale(0.95); transition: transform 0.3s; }
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h2 { font-size: 1.25rem; font-weight: 600; }
.modal-body p { color: var(--text-secondary); margin-bottom: 16px; line-height: 1.6; }

/* --- Auth Modal --- */
.auth-view { display: none; }
.auth-view.active { display: block; }
.auth-footer-text { margin-top: 24px; text-align: center; font-size: 0.9rem; color: var(--text-secondary); }
.auth-footer-text a { color: var(--text-active); font-weight: 500; }
.auth-footer-text a:hover { text-decoration: underline; }
.form-group-inline { display: flex; justify-content: flex-end; margin-bottom: 24px; }
.form-group-inline a { font-size: 0.9rem; color: var(--text-active); }
.form-group-inline a:hover { text-decoration: underline; }
.auth-divider { display: flex; align-items: center; text-align: center; color: var(--text-secondary); font-size: 0.8rem; margin: 24px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border-color); }
.auth-divider:not(:empty)::before { margin-right: .5em; }
.auth-divider:not(:empty)::after { margin-left: .5em; }
.btn-google { width: 100%; display: flex; justify-content: center; align-items: center; gap: 12px; }
.btn-google svg { width: 18px; height: 18px; flex-shrink: 0; }
.auth-error-message { color: var(--error-color); background-color: rgba(255, 138, 128, 0.1); border: 1px solid rgba(255, 138, 128, 0.3); padding: 12px; border-radius: 6px; margin-bottom: 16px; font-size: 0.9rem; text-align: center; display: none; }
.auth-error-message.visible { display: block; }

/* --- Responsive & Overlay --- */
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; z-index: 1000; }
body.left-sidebar-open .overlay { opacity: 1; visibility: visible; }
@media (min-width: 1024px) {
    #left-sidebar { position: static; transform: none; }
    .icon-button#menu-toggle { display: none; }
}