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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #232736;
    --border: #2d3148;
    --text: #e4e4e7;
    --text-muted: #8b8fa3;
    --primary: #6c8cff;
    --success: #4caf50;
    --danger: #ef5350;
    --sidebar-width: 260px;
}

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

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
header {
    display: flex;
    align-items: center;
    padding: 0 16px;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

/* Hamburger */
#sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#sidebar-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 1px;
    transition: background 0.2s;
}

#sidebar-toggle:hover span {
    background: var(--text);
}

/* New chat button */
#new-chat-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#new-chat-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

/* Sidebar */
#sidebar-overlay {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
}

#sidebar-overlay.open {
    transform: translateX(0);
}

#chat-dimmer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#chat-dimmer.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-header {
    padding: 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.15s;
}

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

.conv-item.active {
    background: var(--surface-hover);
    border-left: 2px solid var(--primary);
}

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

.conv-item .conv-preview {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conv-item .conv-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}

.conv-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Chat container */
#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#messages::-webkit-scrollbar {
    display: none;
}

.message {
    margin-bottom: 16px;
}

.message-content {
    line-height: 1.6;
    font-size: 15px;
}

.message.user .message-content {
    background: #1e3a5f;
    padding: 10px 14px;
    border-radius: 12px 12px 2px 12px;
    display: inline-block;
    max-width: 85%;
    float: right;
}

.message.user::after {
    content: "";
    display: table;
    clear: both;
}

.message.assistant .message-content {
    max-width: 100%;
}

.message-content p { margin: 8px 0; }
.message-content p:first-child { margin-top: 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 8px 0; padding-left: 20px; }
.message-content li { margin: 4px 0; }
.message-content strong { color: var(--text); }
.message-content a { color: var(--primary); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }

.message-content h2 {
    font-size: 18px;
    margin: 16px 0 8px;
    color: var(--text);
}

.message-content h3 {
    font-size: 16px;
    margin: 12px 0 6px;
    color: var(--text);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.message-content th {
    text-align: left;
    padding: 8px;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}

.message-content td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.message-content code {
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 14px;
}

.message-content pre {
    background: var(--surface);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

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

.message-content img {
    max-width: 100%;
    border-radius: 6px;
    margin: 8px 0;
}

.message.error .message-content {
    color: var(--danger);
    font-size: 13px;
}

/* Tool indicators */
.tool-indicator {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 12px;
    background: var(--surface);
    border-radius: 6px;
    margin-bottom: 8px;
    display: inline-block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Typing indicator */
#typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

#typing-indicator.hidden { display: none; }

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.typing-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* Welcome screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 0 20px;
}

.welcome-header {
    text-align: center;
    margin-bottom: 32px;
    max-width: 480px;
}

.welcome-header h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.welcome-header p {
    font-size: 15px;
    color: var(--text-muted);
    line-height: 1.5;
}

.welcome-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 640px;
}

@media (max-width: 600px) {
    .welcome-grid {
        grid-template-columns: 1fr;
    }
}

.welcome-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.2s;
}

.welcome-card:hover {
    border-color: var(--text-muted);
}

.welcome-card-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

/* Suggestion links */
.suggestion {
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    line-height: 1.4;
    display: block;
}

.suggestion:hover { text-decoration: underline; }

/* Input area */
#input-area {
    padding: 12px 20px 16px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    gap: 8px;
}

#user-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

#user-input:focus { border-color: var(--primary); }

#user-input:disabled { opacity: 0.5; }

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
    transition: opacity 0.2s;
}

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

/* Login page */
#login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.login-error {
    background: rgba(239, 83, 80, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

.login-error.hidden { display: none; }

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-form input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

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

#login-form button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 4px;
}

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

/* Admin page */
#admin-page {
    background: var(--bg);
    min-height: 100vh;
}

#admin-page header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

#admin-page header h1 { font-size: 18px; }

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
}

.back-link:hover { text-decoration: underline; }

.admin-content {
    max-width: 700px;
    margin: 24px auto;
    padding: 0 20px;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 24px;
    align-items: start;
}

@media (max-width: 800px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }
}

.admin-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.admin-section h2 {
    font-size: 15px;
    margin-bottom: 16px;
    color: var(--text);
}

#create-demo-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#create-demo-form button {
    align-self: flex-start;
}

#create-demo-form input {
    flex: 1;
    min-width: 140px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}

#create-demo-form input:focus { border-color: var(--primary); }

#create-demo-form button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.demo-item {
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
}

.demo-item:last-child { border-bottom: none; }

.demo-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.demo-info strong { font-size: 14px; }
.demo-email { font-size: 12px; color: var(--text-muted); }
.demo-time { font-size: 11px; color: var(--text-muted); }

.demo-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.demo-actions .magic-link-box {
    width: 100%;
}

.magic-link-box {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 200px;
}

.magic-link-box input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 11px;
    outline: none;
}

.magic-link-box button {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.btn-danger {
    background: none;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.btn-danger:hover { background: rgba(239, 83, 80, 0.1); }

.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 16px;
}

#new-link-result {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 6px;
}

#new-link-result.hidden { display: none; }
#new-link-result p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

/* Changelog */
.changelog-content {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}

.changelog-content h1 { display: none; }
.changelog-content h2 { font-size: 15px; margin: 0 0 8px; color: var(--primary); }
.changelog-content h3 { font-size: 13px; margin: 12px 0 6px; color: var(--text-muted); }
.changelog-content ul { padding-left: 20px; margin: 4px 0; }
.changelog-content li { margin: 3px 0; }
.changelog-content strong { color: var(--text); }
.changelog-content hr { display: none; }
.changelog-content code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }

.changelog-version {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 12px;
}

.changelog-older-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
    transition: all 0.2s;
}

#changelog {
    margin-bottom: 8px;
}

.changelog-older-toggle:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* User menu in header */
.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.user-menu a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px;
}

.user-menu a:hover { color: var(--text); }

/* Explore panel */
#explore-btn {
    background: rgba(108, 140, 255, 0.12);
    color: var(--primary);
    border: 1px solid rgba(108, 140, 255, 0.25);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

#explore-btn:hover {
    background: rgba(108, 140, 255, 0.2);
    border-color: rgba(108, 140, 255, 0.4);
}

#explore-dimmer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#explore-dimmer.active {
    opacity: 1;
    pointer-events: auto;
}

#explore-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 400px;
    max-width: 90vw;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
}

#explore-panel.open {
    transform: translateX(0);
}

.explore-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 600;
    flex-shrink: 0;
}

.explore-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.explore-header button:hover {
    color: var(--text);
}

.explore-body {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.explore-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.explore-section:last-child {
    border-bottom: none;
}

.explore-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.explore-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.explore-stat {
    background: var(--bg);
    border-radius: 6px;
    padding: 10px;
}

.explore-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.explore-stat-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.explore-capability {
    margin-bottom: 14px;
}

.explore-capability:last-child {
    margin-bottom: 0;
}

.explore-cap-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
}

.explore-badge {
    background: rgba(76, 175, 80, 0.15);
    color: var(--success);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 500;
    margin-left: 4px;
}

.explore-cap-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.explore-try {
    display: inline-block;
    margin-top: 6px;
    background: rgba(108, 140, 255, 0.1);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    text-decoration: none;
    transition: background 0.15s;
}

.explore-try:hover {
    background: rgba(108, 140, 255, 0.2);
}

.explore-sources {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.explore-source {
    margin-bottom: 4px;
}

.explore-source span {
    color: var(--text);
}

.explore-source-note {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
    margin-top: 8px;
}
