/* CSS Variables - Dark Theme */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --bg-hover: #303030;
    --text-primary: #e5e5e5;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --border: #333333;
    --success: #22c55e;
    --error: #ef4444;
    --user-bg: #2563eb;
    --assistant-bg: #1f1f1f;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 280px;
    --header-height: 56px;
    --input-height: 60px;
}

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

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


body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* App Layout */
#app {
    display: flex;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.conversation-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
    transition: background-color 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    touch-action: manipulation;
}

.conversation-item:hover {
    background-color: var(--bg-hover);
}

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

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

.conversation-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
}

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

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

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    object-fit: cover;
    flex-shrink: 0;
}

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

.btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    flex-shrink: 0;
}

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

/* Settings Toggle */
.settings-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.toggle-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: 0.2s;
    border-radius: 22px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: 0.2s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
    background-color: white;
}

/* Streaming Cursor */
.message.streaming .message-content .cursor {
    display: inline-block;
    animation: blink 1s step-end infinite;
    color: var(--accent);
    font-weight: bold;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

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

/* Mobile Header */
.mobile-header {
    display: none;
    min-height: var(--header-height);
    padding: 0 16px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.mobile-header span {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Messages Area */
.messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.message {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 16px;
    flex-shrink: 0;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 8px;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
}

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

.message-content {
    background-color: var(--assistant-bg);
    padding: 12px 16px;
    border-radius: var(--radius);
    min-width: 0;
    flex: 1;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

.message.user .message-content {
    background-color: var(--user-bg);
    flex: 0 1 auto;
    max-width: calc(100% - 48px);
}

/* Markdown content styling */
.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content code {
    background-color: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.875em;
}

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

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

.message-content ul, .message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}

.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.message-content a {
    color: var(--accent);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* Input Area */
.input-area {
    padding: 16px 24px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
    background-color: var(--bg-primary);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.model-selector {
    position: relative;
    margin-bottom: 8px;
}

.model-selector-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.15s;
}

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

.dropdown-arrow {
    font-size: 0.5rem;
    line-height: 1;
    transition: transform 0.15s;
}

.model-selector-btn.open .dropdown-arrow {
    transform: rotate(180deg);
}

.model-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 200px;
    box-shadow: var(--shadow);
    z-index: 50;
}

.model-dropdown.hidden {
    display: none;
}

.model-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s;
}

.model-dropdown-item:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.model-dropdown-item:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.model-dropdown-item:hover {
    background-color: var(--bg-hover);
}

.model-dropdown-item.selected {
    background-color: var(--bg-tertiary);
}

.model-dropdown-item-name {
    font-size: 0.875rem;
    font-weight: 500;
}

.model-dropdown-item-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.input-container {
    display: flex;
    gap: 12px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 16px;
    align-items: center;
}

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

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

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

/* Buttons */
.btn {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
}

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

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

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

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

.btn-send {
    background-color: var(--accent);
    color: white;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-send .send-icon {
    width: 16px;
    height: 16px;
    display: block;
}

.btn-send:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
}

.btn-google {
    background-color: white;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 12px 24px;
}

.btn-google:hover {
    background-color: #f5f5f5;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 400px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 16px;
}

.model-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.model-option {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}

.model-option:hover {
    background-color: var(--bg-hover);
}

.model-option.selected {
    border-color: var(--accent);
    background-color: rgba(99, 102, 241, 0.1);
}

.model-option-name {
    font-weight: 500;
}

.model-option-id {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    inset: 0;
    background-color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.login-overlay.hidden {
    display: none;
}

.login-box {
    text-align: center;
    padding: 48px;
}

.login-box h2 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.login-box p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Loading indicator */
.loading {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.loading span {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.loading span:nth-child(1) { animation-delay: 0s; }
.loading span:nth-child(2) { animation-delay: 0.2s; }
.loading span:nth-child(3) { animation-delay: 0.4s; }

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

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

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

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

::-webkit-scrollbar-thumb:hover {
    background-color: var(--bg-hover);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .messages {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px 16px;
    }

    .message {
        gap: 12px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .message-content {
        max-width: calc(100% - 40px);
        padding: 10px 14px;
    }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

.sidebar-overlay.visible {
    display: block;
}
