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

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2a2a2a;
    --border-color: #333;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --text-muted: #666;
    --accent: #6b8afd;
    --accent-dim: #4a5568;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

html {
    height: -webkit-fill-available;
}

.container {
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-top {
    text-align: left;
}

h1 {
    font-size: 1.5rem;
    font-weight: 500;
    color: #ffffff;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 2px;
}

#userArea {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sign-out-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.sign-out-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* Auth Area */
.auth-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* Chat Area - Main Layout */
.chat-area {
    flex: 1;
    display: flex;
    min-height: 0; /* Critical for flex scroll */
    position: relative;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.new-chat-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.conversation-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.85rem;
}

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

.conversation-item.active {
    background: var(--bg-tertiary);
    border-left: 2px solid var(--accent);
}

.conversation-item .conv-title {
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .conv-date {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.conversation-item .delete-conv-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.conversation-item .delete-conv-btn:hover {
    background: rgba(255, 100, 100, 0.2);
    color: #ff6b6b;
}

.conversation-item {
    position: relative;
    padding-right: 32px;
}

.sidebar-toggle {
    display: none;
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0; /* Critical for flex scroll */
    overflow: hidden;
}

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    height: 0;
    max-height: calc(100vh - 180px); /* Fallback constraint */
}

/* Messages */
.message {
    max-width: 85%;
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
}

.message.sidekick,
.message.boopmachine {
    align-self: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
}

.message.user .message-content {
    background-color: var(--bg-tertiary);
    color: #ffffff;
}

.message.sidekick .message-content,
.message.boopmachine .message-content {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message.user .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 20px;
    display: flex;
    gap: 4px;
    align-items: center;
}

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

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

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

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

/* Input Area */
.input-area {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

textarea {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-tertiary);
    color: #ffffff;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    min-height: 44px;
    max-height: 120px;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-dim);
}

textarea::placeholder {
    color: var(--text-muted);
}

button#sendButton {
    padding: 12px 24px;
    background-color: var(--bg-tertiary);
    color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    white-space: nowrap;
}

button#sendButton:hover {
    background-color: var(--accent-dim);
    border-color: var(--accent);
}

button#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Checkin badge */
.message.checkin .message-content {
    border-color: var(--accent-dim);
    position: relative;
}

.message.checkin .message-content::before {
    content: "check-in";
    position: absolute;
    top: -10px;
    left: 10px;
    font-size: 0.65rem;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: flex;
    }
    
    .chat-main {
        width: 100%;
    }
    
    header {
        padding: 12px 15px;
    }
    
    h1 {
        font-size: 1.3rem;
    }
    
    .chat-window {
        padding: 15px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-area {
        padding: 12px 15px;
    }
    
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    button#sendButton {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .message {
        max-width: 95%;
    }
    
    .message-content {
        padding: 10px 14px;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

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

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-state h2 {
    font-size: 1.2rem;
    font-weight: 400;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.9rem;
}
