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

:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --primary: #1a5276;
    --primary-light: #2980b9;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #dce1e3;
    --error: #c0392b;
    --success: #27ae60;
    --radius: 8px;
    --sidebar-w: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Auth pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.auth-card, .admin-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.admin-card { max-width: 640px; }
.auth-card h1, .admin-card h1 {
    color: var(--primary);
    margin-bottom: .25rem;
}
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; font-size: .9rem; }
.field small { color: var(--text-muted); font-size: .8rem; }
.field.inline { display: flex; align-items: center; gap: .5rem; }
.field.inline label { margin-bottom: 0; }

input[type="text"], input[type="password"], input[type="number"], input[type="email"], textarea {
    width: 100%;
    padding: .6rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color .2s;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(41,128,185,.15);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .2s, opacity .2s;
    color: var(--text);
    background: var(--bg);
}
.btn.primary {
    background: var(--primary);
    color: #fff;
}
.btn.primary:hover { background: var(--primary-light); }
.btn.small { padding: .35rem .75rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.error {
    background: #fdecea;
    color: var(--error);
    padding: .6rem .8rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}

/* App layout */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 1rem;
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
}
.app-header h1 { font-size: 1.1rem; font-weight: 600; }
.app-header nav { display: flex; gap: .5rem; }
.app-header .btn { color: #fff; background: rgba(255,255,255,.15); }
.app-header .btn:hover { background: rgba(255,255,255,.25); }

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    padding: .25rem;
    margin-right: .5rem;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar .new-chat {
    margin: .75rem;
    background: var(--primary);
    color: #fff;
}
.sidebar .new-chat:hover { background: var(--primary-light); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
    padding: .6rem .75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background .15s;
}
.chat-item:hover { background: var(--bg); }
.chat-item.active { background: #e8f0fe; border-left: 3px solid var(--primary); }

/* Chat main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.empty-state {
    text-align: center;
    margin: auto;
    color: var(--text-muted);
}
.empty-state h2 { color: var(--primary); margin-bottom: .5rem; }

.message {
    max-width: 80%;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.6;
    word-wrap: break-word;
}
.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
}
.message.assistant {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
}
.message.assistant p { margin-bottom: .5rem; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant pre {
    background: var(--bg);
    padding: .5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: .85rem;
}
.message.assistant code {
    background: var(--bg);
    padding: .1rem .3rem;
    border-radius: 3px;
    font-size: .9em;
}
.message.assistant pre code {
    background: none;
    padding: 0;
}
.message .thinking {
    color: var(--text-muted);
    font-style: italic;
    font-size: .85rem;
    border-left: 2px solid var(--border);
    padding-left: .5rem;
    margin-bottom: .5rem;
}

/* Input bar */
.input-bar {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.input-bar textarea {
    flex: 1;
    resize: none;
    min-height: 2.5rem;
    max-height: 8rem;
}
.send-btn {
    padding: .6rem .8rem;
    font-size: 1.1rem;
}
.upload-btn {
    font-size: 1.3rem;
    cursor: pointer;
    padding: .3rem;
    opacity: .6;
    transition: opacity .2s;
}
.upload-btn:hover { opacity: 1; }

/* Loading indicator */
.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4) infinite;
}
@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* Password modal */
.password-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 380px;
    width: 100%;
}
.modal-card h2 { margin-bottom: .5rem; }
.modal-card p { margin-bottom: 1rem; color: var(--text-muted); }
.modal-card input { margin-bottom: .75rem; }

/* Admin */
.admin-card h2 { margin-top: 1.5rem; margin-bottom: .75rem; color: var(--primary); }
.invite-result {
    background: #e8f5e9;
    padding: .75rem;
    border-radius: var(--radius);
    margin: .75rem 0;
}
.invite-result input { margin-top: .5rem; font-size: .85rem; }
.invite-list { display: flex; flex-direction: column; gap: .5rem; }
.invite-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    padding: .5rem;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: .85rem;
}
.invite-item code {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .8rem;
}
.badge {
    padding: .15rem .5rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
}
.badge.active { background: #e8f5e9; color: var(--success); }
.badge.used { background: #e3f2fd; color: var(--primary-light); }
.badge.expired { background: #fdecea; color: var(--error); }
.muted { color: var(--text-muted); }

/* Mobile */
@media (max-width: 768px) {
    .sidebar-toggle { display: block; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,.15);
        padding-top: 3.5rem;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.3);
        z-index: 49;
    }
    .message { max-width: 95%; }
    .app-header h1 { font-size: 1rem; }
}
