:root {
    --bg-main: #0d0e12;
    --bg-sidebar: #13151c;
    --bg-card: #1a1d26;
    --bg-input: #202431;
    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --cyan: #06b6d4;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #2e3444;
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }
body, #react-root { background-color: var(--bg-main); color: var(--text-main); height: 100vh; width: 100vw; overflow: hidden; }

/* Auth Overlay */
.auth-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(13, 14, 18, 0.95); backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.auth-box {
    background-color: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); width: 100%; max-width: 420px; padding: 32px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-icon {
    width: 48px; height: 48px; background: linear-gradient(135deg, var(--accent), var(--cyan));
    border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; color: white; margin: 0 auto 12px;
}
.auth-brand h2 { font-size: 1.3rem; font-weight: 700; }
.auth-brand p { font-size: 0.8rem; color: var(--text-muted); }
.auth-form h3 { font-size: 1rem; margin-bottom: 16px; text-align: center; }
.auth-form .form-group { margin-bottom: 16px; text-align: left; }
.auth-form label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.auth-form input {
    width: 100%; background: var(--bg-input); border: 1px solid var(--border);
    color: var(--text-main); padding: 10px 14px; border-radius: var(--radius-md); outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.btn-auth {
    width: 100%; padding: 12px; background: var(--accent); border: none; color: white;
    border-radius: var(--radius-md); font-weight: 600; cursor: pointer; margin-top: 8px;
    transition: background 0.2s;
}
.btn-auth:hover { background: var(--accent-hover); }
.auth-toggle-text { text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-top: 16px; }
.auth-toggle-text a { color: var(--cyan); text-decoration: none; font-weight: 600; }
.auth-error { background: rgba(239, 68, 68, 0.15); border: 1px solid #ef4444; color: #ef4444; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 0.8rem; margin-bottom: 12px; text-align: center; }

/* Main Layout */
.app-container { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar { width: 280px; background-color: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 10; }
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand-icon { width: 38px; height: 38px; background: linear-gradient(135deg, var(--accent), var(--cyan)); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; color: white; }
.brand-text h2 { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.status-badge { font-size: 0.7rem; color: var(--cyan); display: flex; align-items: center; gap: 4px; }
.btn-new-chat { width: 100%; padding: 10px 16px; background-color: var(--accent); color: white; border: none; border-radius: var(--radius-md); font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all 0.2s; }
.btn-new-chat:hover { background-color: var(--accent-hover); }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.sidebar-section { margin-bottom: 24px; }
.section-title { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); letter-spacing: 0.05em; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.section-title button { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.section-title button:hover { color: var(--text-main); }

.nav-main-list, .project-list { list-style: none; }
.nav-item, .project-item { padding: 10px 12px; border-radius: var(--radius-md); font-size: 0.9rem; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; transition: all 0.2s; }
.nav-item:hover, .project-item:hover { background-color: var(--bg-card); color: var(--text-main); }
.nav-item.active, .project-item.active { background-color: rgba(124, 58, 237, 0.15); color: var(--cyan); border-left: 3px solid var(--cyan); }

.btn-sidebar-action { width: 100%; padding: 10px; background-color: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-main); font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 8px; justify-content: center; }
.btn-sidebar-action:hover { border-color: var(--accent); }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; position: relative; }
.avatar { width: 34px; height: 34px; background: linear-gradient(135deg, #3b82f6, #8b5cf6); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; }
.user-details { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 600; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; }

/* Views Container */
.chat-main { flex: 1; display: flex; flex-direction: column; height: 100vh; background-color: var(--bg-main); position: relative; }
.view-pane { display: none; height: 100%; flex-direction: column; }
.view-pane.active { display: flex; }

/* Chat Header */
.chat-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background-color: rgba(19, 21, 28, 0.8); backdrop-filter: blur(8px); }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h3 { font-size: 1rem; font-weight: 600; color: var(--text-main); }
.btn-icon-small { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; }
.btn-icon-small:hover { color: var(--accent); }

.header-controls { display: flex; align-items: center; gap: 16px; }
.rag-toggle-container { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-muted); }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--bg-input); transition: .3s; border-radius: 22px; border: 1px solid var(--border); }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: var(--text-muted); transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
input:checked + .slider:before { transform: translateX(16px); background-color: white; }

.model-selector select { background-color: var(--bg-card); color: var(--text-main); border: 1px solid var(--border); padding: 6px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; outline: none; }

/* Messages & Welcome */
.messages-container { flex: 1; overflow-y: auto; padding: 24px 15%; display: flex; flex-direction: column; gap: 24px; }
.welcome-screen { margin: auto; text-align: center; max-width: 600px; }
.welcome-icon { font-size: 3rem; color: var(--cyan); margin-bottom: 16px; }
.welcome-screen h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.welcome-screen p { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 32px; }
.suggestion-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.suggestion-card { background-color: var(--bg-card); border: 1px solid var(--border); padding: 16px; border-radius: var(--radius-md); cursor: pointer; text-align: left; transition: all 0.2s; }
.suggestion-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.suggestion-card i { color: var(--accent); margin-bottom: 8px; font-size: 1.2rem; }
.suggestion-card h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; }
.suggestion-card p { font-size: 0.75rem; color: var(--text-muted); margin: 0; }

.message-item { display: flex; gap: 16px; max-width: 100%; }
.message-item.user { justify-content: flex-end; }
.message-item.user .message-content { background-color: #272c3d; border-radius: var(--radius-lg) var(--radius-lg) 2px var(--radius-lg); }
.message-item.assistant .message-content { background-color: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 2px; width: 100%; }
.message-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; flex-shrink: 0; }
.message-item.user .message-avatar { background: #3b82f6; }
.message-item.assistant .message-avatar { background: linear-gradient(135deg, var(--accent), var(--cyan)); }
.message-content { padding: 16px 20px; font-size: 0.95rem; line-height: 1.6; }

.chat-input-wrapper { padding: 16px 15% 24px; background: linear-gradient(to top, var(--bg-main) 80%, transparent); }
.chat-input-box { background-color: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-input-box textarea { background: none; border: none; outline: none; color: var(--text-main); font-size: 0.95rem; resize: none; max-height: 150px; width: 100%; }
.input-actions { display: flex; justify-content: space-between; align-items: center; }
.btn-send { background-color: var(--accent); color: white; border: none; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* Admin Dashboard View */
.admin-container { padding: 24px; overflow-y: auto; flex: 1; }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { background-color: var(--bg-card); border: 1px solid var(--border); padding: 20px; border-radius: var(--radius-lg); display: flex; align-items: center; gap: 16px; }
.metric-icon { width: 44px; height: 44px; background: rgba(124, 58, 237, 0.15); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; color: var(--cyan); }
.metric-data h4 { font-size: 1.4rem; font-weight: 700; color: var(--text-main); }
.metric-data span { font-size: 0.75rem; color: var(--text-muted); }

.admin-card { background-color: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 24px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.btn-primary-sm { background-color: var(--accent); color: white; border: none; padding: 6px 14px; border-radius: var(--radius-sm); font-size: 0.8rem; cursor: pointer; font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.85rem; }
.data-table th { padding: 10px; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 600; }
.data-table td { padding: 12px 10px; border-bottom: 1px solid rgba(46, 52, 68, 0.5); }
.key-code { font-family: 'JetBrains Mono', monospace; background: var(--bg-input); padding: 4px 8px; border-radius: 4px; color: var(--cyan); }
.status-tag { padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: 600; }
.status-tag.active { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.status-tag.revoked { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

/* Modals */
.modal-backdrop { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background-color: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 90%; max-width: 550px; padding: 24px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group input, .form-group textarea { width: 100%; background-color: var(--bg-input); border: 1px solid var(--border); color: var(--text-main); padding: 10px; border-radius: var(--radius-md); outline: none; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; }
.btn-secondary { background: none; border: 1px solid var(--border); color: var(--text-main); padding: 8px 16px; border-radius: var(--radius-md); cursor: pointer; }
.btn-primary { background: var(--accent); border: none; color: white; padding: 8px 16px; border-radius: var(--radius-md); cursor: pointer; font-weight: 600; }

.hidden { display: none !important; }
