@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables / Design Tokens ──────────────────────────── */
:root {
    --bg-primary: #0f0f13;
    --bg-secondary: #18181f;
    --bg-tertiary: #1e1e28;
    --bg-hover: #262633;
    --bg-active: #2d2d3d;
    --surface: #22222e;
    --surface-elevated: #2a2a38;

    --text-primary: #e8e8ed;
    --text-secondary: #9e9eb0;
    --text-muted: #6b6b80;
    --text-inverse: #0f0f13;

    --accent: #6c63ff;
    --accent-hover: #7b73ff;
    --accent-glow: rgba(108, 99, 255, 0.25);
    --accent-gradient: linear-gradient(135deg, #6c63ff 0%, #9b59b6 50%, #e74c8e 100%);

    --success: #4ecdc4;
    --warning: #f7b731;
    --danger: #ff6b6b;

    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-width: 280px;
    --header-height: 56px;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
    outline: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #ff5252;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.25);
}

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

/* ── Inputs ────────────────────────────────────────────────── */
.input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: all var(--transition-normal);
    outline: none;
}
.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.input::placeholder { color: var(--text-muted); }

/* ── Login Page ────────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: var(--accent-gradient);
    border-radius: 50%;
    filter: blur(150px);
    opacity: 0.15;
    top: -200px;
    right: -200px;
    animation: float 8s ease-in-out infinite;
}

.login-wrapper::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #e74c8e 0%, #6c63ff 100%);
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.1;
    bottom: -150px;
    left: -150px;
    animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -30px); }
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 48px 40px;
    background: rgba(30, 30, 40, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.6s ease-out;
}

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

.login-branding {
    text-align: center;
    margin-bottom: 36px;
}

.login-branding .logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.login-branding .logo-img {
    height: 60px;
    width: auto;
    object-fit: contain;
    border-radius: var(--radius-md);
    transition: transform var(--transition-normal);
}

.login-branding .logo-img:hover {
    transform: scale(1.05);
}

.login-branding h1 {
    font-size: 22px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.login-branding p {
    color: var(--text-muted);
    font-size: 13px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.login-error {
    padding: 10px 14px;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.2);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 13px;
    display: none;
}

.login-form .btn-primary {
    margin-top: 8px;
    padding: 12px;
    font-size: 15px;
    justify-content: center;
}

/* ── Chat Layout ───────────────────────────────────────────── */
.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
    z-index: 100;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.sidebar-brand .logo-sm {
    width: 90%;
    height: auto;
    object-fit: contain;
}

.sidebar-brand span {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.new-chat-btn {
    width: 100%;
    padding: 10px;
    justify-content: center;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}
.new-chat-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Conversation list ─────────────────────────────────────── */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.convo-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2px;
    position: relative;
}

.convo-item:hover { background: var(--bg-hover); }
.convo-item.active { background: var(--bg-active); }

.convo-item .convo-icon {
    font-size: 16px;
    opacity: 0.5;
    flex-shrink: 0;
}

.convo-item .convo-title {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.convo-item.active .convo-title { color: var(--text-primary); }

.convo-item .convo-delete {
    opacity: 0;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    background: none;
    border: none;
    padding: 4px;
    flex-shrink: 0;
}
.convo-item:hover .convo-delete { opacity: 1; }
.convo-item .convo-delete:hover { color: var(--danger); }

/* ── Sidebar footer ────────────────────────────────────────── */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

/* Token usage bar */
.token-usage {
    margin-bottom: 12px;
}

.token-usage .usage-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.token-usage .usage-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.token-usage .usage-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
    min-width: 2px;
}

.token-usage .usage-fill.warning { background: var(--warning); }
.token-usage .usage-fill.danger { background: var(--danger); }

/* Model selector */
.model-selector {
    margin-bottom: 12px;
}

.model-selector label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.model-selector select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239e9eb0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
.model-selector select:focus {
    border-color: var(--accent);
}

/* User menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    color: white;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-info .user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info .user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    transition: color var(--transition-fast);
    flex-shrink: 0;
}
.logout-btn:hover { color: var(--danger); }

/* ── Main Chat Area ────────────────────────────────────────── */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-primary);
}

.chat-header .model-badge {
    font-size: 12px;
    padding: 4px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

/* ── Messages ──────────────────────────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.messages-inner {
    max-width: 780px;
    margin: 0 auto;
    padding: 0 24px;
}

.message {
    display: flex;
    gap: 16px;
    padding: 16px 0;
    animation: messageIn 0.3s ease-out;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--surface-elevated);
    color: var(--success);
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-body .sender-name {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.message-content {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }

/* ── Inline code ───────────────────────────────────────────── */
.message-content code {
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

/* ── Code block wrapper (header + pre) ─────────────────────── */
.code-block-wrapper {
    margin: 14px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-secondary);
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 34px;
}

.code-lang {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-family: inherit;
}

.copy-code-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 10px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}
.copy-code-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.code-block-wrapper pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    background: var(--bg-secondary);
    border: none;
    border-radius: 0;
}

.code-block-wrapper pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.6;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

/* Standalone pre (not inside wrapper — fallback) */
.message-content > pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content > pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* ── highlight.js overrides (match dark theme) ─────────────── */
.hljs {
    background: transparent !important;
    color: var(--text-primary);
}

/* ── Lists ─────────────────────────────────────────────────── */
.message-content ul, .message-content ol {
    padding-left: 24px;
    margin: 8px 0;
}

.message-content li { margin-bottom: 4px; }

.message-content li > ul,
.message-content li > ol {
    margin: 4px 0 4px 0;
}

/* ── Headings ──────────────────────────────────────────────── */
.message-content h1, .message-content h2, .message-content h3 {
    margin: 16px 0 8px;
    color: var(--text-primary);
}
.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 17px; }
.message-content h3 { font-size: 15px; }

/* ── Blockquotes ───────────────────────────────────────────── */
.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 4px 16px;
    margin: 8px 0;
    color: var(--text-secondary);
    background: rgba(108, 99, 255, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ── KaTeX overrides (dark theme) ──────────────────────────── */
.katex {
    font-size: 1.05em;
    color: var(--text-primary);
}

.katex-display {
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

.katex-display > .katex {
    text-align: center;
}

.math-error {
    color: var(--danger);
    font-style: italic;
}

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

.message-content th, .message-content td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
    font-size: 13px;
}

.message-content th {
    background: var(--surface);
    font-weight: 600;
}

/* File badges in messages */
.file-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
}

.message-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    object-fit: contain;
    background: var(--surface);
}

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

.welcome-screen .welcome-icon {
    width: 64px;
    height: 64px;
    background: var(--accent-gradient);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 20px;
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: var(--shadow-glow); }
}

.welcome-screen h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.welcome-screen p {
    color: var(--text-muted);
    font-size: 14px;
    max-width: 400px;
}

/* Streaming cursor */
.streaming-cursor {
    display: inline-block;
    width: 7px;
    height: 18px;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    border-radius: 1px;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ── Input Area ────────────────────────────────────────────── */
.input-area {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
}

.input-wrapper {
    max-width: 780px;
    margin: 0 auto;
    position: relative;
}

.input-box {
    display: flex;
    align-items: flex-end;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    transition: all var(--transition-normal);
}

.input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-box textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    min-height: 24px;
}

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

.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.attach-btn, .send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all var(--transition-fast);
}

.attach-btn {
    background: none;
    color: var(--text-muted);
}
.attach-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.send-btn {
    background: var(--accent);
    color: white;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Multi-file preview */
.files-preview {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    animation: messageIn 0.15s ease-out;
}

.file-chip-icon {
    font-size: 14px;
}

.file-chip-name {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    transition: color var(--transition-fast);
}
.file-chip-remove:hover { color: var(--danger); }

.input-hint {
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Drop zone overlay ────────────────────────────────────── */
.drop-zone-overlay {
    position: absolute;
    inset: 0;
    background: rgba(108, 99, 255, 0.08);
    backdrop-filter: blur(4px);
    border: 3px dashed var(--accent);
    border-radius: var(--radius-md);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: all var(--transition-normal);
    pointer-events: none;
}

.drop-zone-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.drop-zone-content {
    text-align: center;
    padding: 40px;
}

.drop-zone-icon {
    font-size: 48px;
    margin-bottom: 12px;
    animation: float 2s ease-in-out infinite;
}

.drop-zone-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 6px;
}

.drop-zone-hint {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Admin Page ────────────────────────────────────────────── */
.admin-layout {
    min-height: 100vh;
    background: var(--bg-primary);
}

.admin-header {
    padding: 16px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-header h1 {
    font-size: 18px;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.admin-header .admin-actions {
    display: flex;
    gap: 8px;
}

.admin-content {
    max-width: 1000px;
    margin: 32px auto;
    padding: 0 32px;
}

.admin-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
}

.admin-card-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: left;
    padding: 12px 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--surface);
    font-weight: 600;
}

.admin-table td {
    padding: 12px 20px;
    font-size: 14px;
    border-top: 1px solid var(--border);
}

.admin-table tr:hover td {
    background: var(--bg-hover);
}

.admin-table .usage-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-table .mini-bar {
    width: 60px;
    height: 4px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.admin-table .mini-bar .fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-full);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
}
.badge-admin { background: rgba(108, 99, 255, 0.15); color: var(--accent); }
.badge-user { background: rgba(78, 205, 196, 0.15); color: var(--success); }

/* Reasoning level badges (admin table) */
.reasoning-levels-cell {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.reasoning-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
}

/* Reasoning checkboxes in modals */
.reasoning-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.checkbox-label:hover {
    border-color: var(--accent);
}
.checkbox-label input:checked + .checkbox-label,
.checkbox-label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(108, 99, 255, 0.1);
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.active { display: flex; }

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 460px;
    padding: 32px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

.modal .form-group { margin-bottom: 16px; }

.modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* ── Loading ───────────────────────────────────────────────── */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

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

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

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: block; }

    .messages-inner { padding: 0 16px; }
    .input-area { padding: 12px 16px 16px; }

    .admin-content { padding: 0 16px; }
    .admin-header { padding: 12px 16px; }

    .gpts-grid { grid-template-columns: 1fr; }
    .gpt-form-grid { grid-template-columns: 1fr; }
}

/* ── GPT Explorer Page ─────────────────────────────────────── */
.gpts-layout {
    min-height: 100vh;
    background: var(--bg-primary);
}

.gpts-header {
    padding: 16px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gpts-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.gpts-header h1 {
    font-size: 18px;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gpts-content {
    max-width: 1100px;
    margin: 32px auto;
    padding: 0 32px;
}

.gpts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.gpts-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
}

.gpts-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.gpts-empty h3 { font-size: 20px; margin-bottom: 8px; }
.gpts-empty p { color: var(--text-muted); font-size: 14px; }

/* GPT Card */
.gpt-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition-normal);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gpt-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.gpt-card-avatar {
    width: 48px;
    height: 48px;
    background: var(--surface);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.gpt-card-body { flex: 1; }

.gpt-card-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.gpt-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gpt-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gpt-card-creator {
    font-size: 11px;
    color: var(--text-muted);
}

/* GPT Modal (extended) */
.gpt-modal { max-width: 580px; max-height: 90vh; overflow-y: auto; }

.gpt-form-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    margin-bottom: 0;
}

.emoji-input {
    width: 60px;
    text-align: center;
    font-size: 24px;
    padding: 8px;
}

.gpt-textarea {
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
}

.range-input {
    width: 100%;
    margin-top: 8px;
    accent-color: var(--accent);
}

.temp-badge {
    display: inline-block;
    padding: 1px 6px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 11px;
    margin-left: 4px;
}

/* Knowledge files area */
.knowledge-files-area {
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--bg-tertiary);
}

.knowledge-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 8px;
}

.knowledge-upload-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.knowledge-existing-file, .knowledge-pending-file {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.knowledge-existing-file button, .knowledge-pending-file button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
}

.knowledge-existing-file button:hover, .knowledge-pending-file button:hover {
    color: var(--danger);
}

/* GPT Detail Modal */
.gpt-detail-modal { max-width: 500px; }

.gpt-detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.gpt-detail-avatar {
    width: 56px;
    height: 56px;
    background: var(--surface);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

.gpt-detail-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.gpt-detail-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.gpt-meta-tag {
    padding: 3px 10px;
    background: var(--surface);
    border-radius: var(--radius-full);
    font-size: 11px;
    color: var(--text-muted);
}

.starters-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.starter-chip {
    display: inline-block;
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 6px 6px 0;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.starter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.knowledge-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 6px 6px 0;
}

.kf-size { color: var(--text-muted); font-size: 11px; }

.gpt-detail-knowledge, .gpt-detail-starters {
    margin-bottom: 16px;
}

/* Explore GPTs link in sidebar */
.explore-gpts-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    margin-top: 8px;
}

.explore-gpts-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

/* GPT badge in chat header */
.gpt-chat-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.2);
    border-radius: var(--radius-full);
    font-size: 12px;
    color: var(--accent);
}

/* Conversation starters in welcome screen */
.welcome-starters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
    max-width: 500px;
}

.welcome-starters .starter-chip {
    cursor: pointer;
}

/* ── Settings Button ───────────────────────────────────────── */
.settings-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    transition: color var(--transition-fast);
    flex-shrink: 0;
}
.settings-btn:hover { color: var(--accent); }

/* ── Organization Page ─────────────────────────────────────── */
.org-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    padding: 0 8px;
}

.org-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: all var(--transition-normal);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: messageIn 0.3s ease-out;
}

.org-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.org-card-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
}

.org-card-logo {
    max-height: 80px;
    max-width: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.org-card-icon {
    font-size: 48px;
    opacity: 0.5;
}

.org-card-body h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.org-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.org-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.org-status-badge.active {
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
    border: 1px solid rgba(78, 205, 196, 0.3);
}

.org-status-badge.provisioning {
    background: rgba(247, 183, 49, 0.15);
    color: var(--warning);
    border: 1px solid rgba(247, 183, 49, 0.3);
    animation: pulse 2s ease-in-out infinite;
}

.org-status-badge.error {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 107, 107, 0.3);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.org-user-count {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Organization Detail ───────────────────────────────────── */
.org-detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 8px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.org-detail-info {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.org-detail-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.org-detail-info h2 {
    font-size: 20px;
    font-weight: 600;
}

.org-detail-actions {
    display: flex;
    gap: 8px;
}

.org-detail-context {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin: 0 8px 20px;
}

.org-detail-context h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.org-text-preview {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* ── File Upload Area ──────────────────────────────────────── */
.file-upload-area {
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: var(--bg-tertiary);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--accent);
    background: rgba(108, 99, 255, 0.05);
}

.file-upload-placeholder {
    color: var(--text-muted);
}

.file-upload-placeholder span {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}

.file-upload-placeholder p {
    font-size: 14px;
    margin-bottom: 4px;
}

.file-upload-placeholder small {
    font-size: 11px;
    color: var(--text-muted);
}

.logo-preview {
    max-width: 200px;
    max-height: 100px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

/* ── Optional Label ────────────────────────────────────────── */
.optional-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    font-style: italic;
}

/* ── Textarea ──────────────────────────────────────────────── */
.textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

/* ── Import Results ────────────────────────────────────────── */
.import-result {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-top: 12px;
    line-height: 1.6;
}

.import-result.success {
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.2);
    color: var(--success);
}

.import-result.errors {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.2);
    color: var(--danger);
}

/* ── Wide Modal ────────────────────────────────────────────── */
.modal-wide {
    max-width: 600px;
}

.import-instructions {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
}

.import-instructions p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.admin-table.compact {
    font-size: 12px;
}

.admin-table.compact th,
.admin-table.compact td {
    padding: 6px 12px;
}

/* ── User Text Preview ─────────────────────────────────────── */
.user-text-preview {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Explore GPTs button ───────────────────────────────────── */
.explore-gpts-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    margin-top: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    text-decoration: none;
    transition: all var(--transition-fast);
}
.explore-gpts-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-color: var(--accent);
}
