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

:root {
    --bg: #f3f3f9;
    --surface: #ffffff;
    --border: #e5e5e5;
    --text: #221c35;
    --text-muted: #514c4b;
    --accent: #0083ca;
    --accent-light: #e4edf8;
    --accent-dark: #2b3c73;
    --user-bg: #0083ca;
    --user-text: #ffffff;
    --assistant-bg: #ffffff;
    --error: #e53e3e;
    --header-bg: #221c35;
    --header-text: #e4edf8;
}

body {
    font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.screen { height: 100vh; }
.hidden { display: none !important; }

/* Login */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 2rem;
}

.logo h1 {
    font-size: 2.5rem;
    font-weight: 300;
    text-align: center;
}

.logo .accent { color: var(--accent); font-weight: 600; }
.tagline { color: var(--text-muted); text-align: center; margin-top: 0.5rem; }

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 300px;
}

#login-form input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#login-form input:focus { border-color: var(--accent); }

#login-form button {
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

#login-form button:hover { opacity: 0.9; }

/* Chat Layout */
#chat-screen {
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--header-bg);
    border-bottom: none;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 300;
    color: var(--header-text);
}

header .accent { color: var(--accent); font-weight: 600; }

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-secondary {
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: 1px solid rgba(228, 237, 248, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--header-text);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    max-width: 75%;
}

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

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
}

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

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

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

.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin: 0.75rem 0 0.35rem 0;
    line-height: 1.3;
}
.message-content h1 { font-size: 1.3em; }
.message-content h2 { font-size: 1.15em; }
.message-content h3 { font-size: 1.05em; }
.message-content h1:first-child, .message-content h2:first-child,
.message-content h3:first-child { margin-top: 0; }

.message-content ul, .message-content ol {
    margin: 0.35rem 0;
    padding-left: 1.5rem;
}
.message-content li { margin-bottom: 0.2rem; }

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

.message-content code {
    background: rgba(0,0,0,0.06);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

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

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.4s ease-in-out 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(-6px); }
}

/* Chat Input */
.chat-input {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

#chat-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    transition: border-color 0.2s;
}

#chat-input:focus { border-color: var(--accent); }

#send-btn {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}

#send-btn:hover { opacity: 0.9; }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-message {
    color: var(--error);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    text-align: center;
}

/* Auth forms */
.form-error {
    color: var(--error);
    font-size: 0.85rem;
    text-align: center;
    padding: 0.5rem;
}

.form-success {
    color: #38a169;
    font-size: 0.85rem;
    text-align: center;
    padding: 0.5rem;
}

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

/* Admin */
.admin-content {
    padding: 1.5rem;
    max-width: 800px;
    margin: 0 auto;
    overflow-y: auto;
    flex: 1;
}

.admin-section {
    margin-bottom: 2rem;
}

.admin-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--accent-dark);
}

.admin-form {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.admin-form input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
}

.admin-form input:focus { border-color: var(--accent); }

.admin-form button {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}

.admin-form button:hover { opacity: 0.9; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}

.admin-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
}
.btn-sm:hover { background: var(--accent-light); }
.btn-sm.btn-danger { color: var(--error); border-color: var(--error); }
.btn-sm.btn-danger:hover { background: #fee; }

.admin-table .empty {
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

header small {
    font-size: 0.7em;
    color: var(--header-text);
    font-weight: 400;
    opacity: 0.7;
}
