/* ============================================================================
   nest.ai - Clean White Theme (matching NestDaddy)
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #f1f3f5;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --border-color: #dee2e6;
    --message-user-bg: #e7f3ff;
    --message-ai-bg: #f8f9fa;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* ============================================================================
   MOBILE HEADER (Hidden on desktop)
   ============================================================================ */

.mobile-header {
    display: none;
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.mobile-menu-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px 8px;
}

.mobile-header .logo {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-color);
    flex: 1;
}

/* ============================================================================
   SIDEBAR
   ============================================================================ */

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 4px;
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Models Section */
.models-section {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.models-section h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding: 0 12px;
}

.models-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.model-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.model-item:hover {
    background: var(--bg-tertiary);
}

.model-item.active {
    background: var(--bg-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.model-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    flex-shrink: 0;
}

.model-item.active .model-indicator {
    background: #10b981;
}

.model-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.model-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

/* New Chat Button */
.new-chat-btn {
    margin: 16px;
    padding: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--accent-hover);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.sidebar-footer a:hover {
    color: var(--accent-color);
    background: var(--bg-tertiary);
}

/* ============================================================================
   CHAT CONTAINER
   ============================================================================ */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.chat-header {
    padding: 20px 32px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.chat-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.chat-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Messages */
.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-user {
    flex-direction: row-reverse;
}

.message-user .message-content {
    background: var(--message-user-bg);
    border-radius: 18px 18px 4px 18px;
}

.message-ai .message-content {
    background: var(--message-ai-bg);
    border-radius: 18px 18px 18px 4px;
}

.avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
}

.message-content {
    max-width: 65%;
    padding: 12px 16px;
}

.message-model {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.message-text {
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* Chat Input */
.chat-input-container {
    padding: 20px 32px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    display: flex;
    gap: 12px;
}

#chatInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

#chatInput:focus {
    outline: none;
    border-color: var(--accent-color);
}

.send-btn {
    padding: 12px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

/* ============================================================================
   SCROLLBAR
   ============================================================================ */

.chat-messages::-webkit-scrollbar,
.models-section::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.models-section::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.models-section::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.models-section::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================================================
   MOBILE SIDEBAR OVERLAY
   ============================================================================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 98;
}

.sidebar-overlay.show {
    display: block;
}

/* ============================================================================
   RESPONSIVE (Mobile)
   ============================================================================ */

@media (max-width: 768px) {
    body {
        padding-top: 60px;
        /* iOS safe area support */
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-header {
        display: flex;
        /* iOS safe area support */
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 60px;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px - env(safe-area-inset-bottom));
        z-index: 99;
        transition: left 0.3s ease;
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
    }

    .models-section {
        flex: 0 1 auto;
        max-height: 200px;
        overflow-y: auto;
    }

    .sidebar-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .chat-container {
        width: 100%;
        height: calc(100vh - 60px);
        position: relative;
    }

    .chat-header {
        padding: 16px 20px;
    }

    .chat-messages {
        padding: 16px 20px;
        /* Reserve space for fixed input at bottom */
        padding-bottom: 100px;
        /* Limit height so input always visible */
        max-height: calc(100vh - 60px - 120px);
        overflow-y: auto;
    }

    .chat-input-container {
        padding: 16px 20px;
        /* iOS safe area support */
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        /* FIXED at bottom - always visible */
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-primary);
        /* Shadow to separate from messages */
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        /* Below sidebar when open */
        z-index: 1;
    }

    .message-content {
        max-width: 80%;
    }

    /* When input is focused, ensure it's visible */
    #chatInput:focus {
        /* iOS specific: prevent zoom on focus */
        font-size: 16px;
    }
}
