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

:root {
    --background: #FBF9F6;
    --surface: #FFFFFF;
    --text: #2D1B19;
    --text-secondary: #5A575B;
    --brand: #9E6C46;
    --brand-dark: #684736;
    --brand-hover: #895B3B;
    --border: #DEDBD8;
    --muted: #A3A0A0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    background: var(--background);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.welcome-content h1 {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
}

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

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

.api-keys-info {
    padding: 12px;
    margin-bottom: 12px;
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.api-keys-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
}

.api-keys-status .status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
    animation: pulse 2s ease-in-out infinite;
}

.api-keys-status .status-text {
    font-weight: 500;
}

.api-keys-status #apiKeyCount {
    font-weight: 600;
    color: var(--brand);
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--background);
    border-color: var(--brand);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

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

.chat-item.active {
    background: var(--background);
    border: 1px solid var(--border);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

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

.chat-item-delete {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.chat-item-delete:hover {
    background: rgba(158, 108, 70, 0.1);
    color: var(--brand);
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sign-out-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sign-out-btn:hover {
    background: rgba(158, 108, 70, 0.1);
    color: var(--brand);
}

.google-signin-btn {
    width: 100%;
    padding: 12px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.google-signin-btn:hover {
    background: #f8f8f8;
    border-color: var(--muted);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.google-signin-btn svg {
    flex-shrink: 0;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
    animation: pulse 2s ease-in-out infinite;
}

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

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

.chat-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.welcome-content {
    max-width: 800px;
    text-align: center;
}

.welcome-logo {
    height: 80px;
    width: auto;
    margin-bottom: 24px;
    object-fit: contain;
}

.welcome-content h1 {
    font-size: 48px;
    margin-bottom: 16px;
    color: #2D1B19;
    font-weight: 800;
}

@media (min-width: 768px) {
    .welcome-content h1 {
        font-size: 60px;
    }
}

.welcome-content p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
}

.messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 20px;
}

.message {
    margin-bottom: 32px;
    animation: fadeIn 0.3s ease-in;
    display: flex;
    gap: 12px;
}

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

.message.assistant {
    flex-direction: row;
}

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

.message-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
}

.message-avatar img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.message.user .message-avatar {
    background: var(--brand);
    color: white;
    border: none;
}

.message.assistant .message-avatar {
    background: var(--surface);
    border: 1px solid var(--border);
}

.message-author {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.message-content {
    line-height: 1.6;
    color: var(--text);
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

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

.message.assistant .message-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text);
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.message.user .message-content pre {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message-content code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.message-content :not(pre) > code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message.user .message-content :not(pre) > code {
    background: rgba(0, 0, 0, 0.3);
}

.message.typing .message-content {
    display: flex;
    align-items: center;
    min-height: 40px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    border-top: 1px solid var(--border);
    padding: 20px;
    background: var(--background);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--brand);
}

/* Model Selector */
.model-selector {
    position: relative;
    flex-shrink: 0;
}

.model-selector-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
}

.model-selector-trigger:hover {
    background: var(--background);
}

.model-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
    flex-shrink: 0;
}

.model-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}

.dropdown-icon {
    color: var(--text-secondary);
    transition: transform 0.2s;
    flex-shrink: 0;
}

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

.model-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    max-height: 400px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.model-selector.open .model-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.provider-group {
    border-bottom: 1px solid var(--border);
}

.provider-group:last-child {
    border-bottom: none;
}

.provider-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
}

.provider-header:hover {
    background: var(--background);
}

.provider-header .chevron {
    margin-left: auto;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.provider-group.open .provider-header .chevron {
    transform: rotate(90deg);
}

.provider-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
}

.model-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: var(--background);
}

.provider-group.open .model-list {
    max-height: 200px;
}

.provider-group.locked .provider-header {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f5f5f5;
}

.provider-lock-badge {
    font-size: 14px;
    margin-left: auto;
    margin-right: 4px;
    opacity: 0.8;
}

.provider-group.locked .provider-name::after {
    content: "";
}

.model-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px 10px 44px;
    cursor: pointer;
    transition: background 0.2s;
}

.model-item:hover {
    background: rgba(158, 108, 70, 0.05);
}

.model-item.locked {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background: #f5f5f5;
}

.model-item .lock-icon {
    font-size: 12px;
    opacity: 0.7;
    margin-left: auto;
}

.model-item-name {
    font-size: 13px;
    color: var(--text-secondary);
}

.model-item .check-icon {
    color: var(--brand);
    opacity: 0;
    transition: opacity 0.2s;
}

.model-item.equipped .check-icon {
    opacity: 1;
}

.model-item.equipped .model-item-name {
    color: var(--brand);
    font-weight: 500;
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    resize: none;
    max-height: 200px;
    outline: none;
    font-family: inherit;
    padding: 10px 8px;
    line-height: 1.5;
}

#messageInput::placeholder {
    color: var(--muted);
}

.send-btn {
    width: 36px;
    height: 36px;
    background: var(--brand);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--brand-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--muted);
}

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

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

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

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -260px;
        height: 100%;
        z-index: 100;
        transition: left 0.3s;
    }

    .sidebar.open {
        left: 0;
    }

    .welcome-content h1 {
        font-size: 36px;
    }

    .message-content {
        max-width: 85%;
    }
}
