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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #242834;
  --border: #2e3345;
  --text: #e4e4e7;
  --text2: #9ca3af;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --user-msg: #1e293b;
  --bot-msg: #1a1d27;
}

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

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

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

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 360px;
}

.login-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.login-box p {
  color: var(--text2);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

input, textarea, select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

button, .btn {
  padding: 0.625rem 1.25rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  cursor: pointer;
  font-weight: 500;
}

button:hover, .btn:hover {
  background: var(--accent-hover);
}

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg3); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }

.error-msg {
  color: var(--danger);
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.sidebar-nav {
  padding: 0.5rem;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text2);
  font-size: 0.875rem;
  transition: background 0.15s;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: white; }

.nav-item .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  flex-shrink: 0;
}

.nav-item.active .avatar { background: rgba(255,255,255,0.2); }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text2);
}

/* Main content area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat */
.chat-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
}

.chat-header h3 { font-size: 1rem; }
.chat-header .status { font-size: 0.75rem; color: var(--text2); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg3);
  border-bottom-left-radius: 4px;
}

.message .msg-time {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.25rem;
}

.typing-indicator {
  align-self: flex-start;
  padding: 0.75rem 1rem;
  background: var(--bg3);
  border-radius: 12px;
  font-size: 0.85rem;
  color: var(--text2);
  display: none;
}

.typing-indicator.visible { display: block; }

.chat-input-area {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  margin-bottom: 0;
  min-height: 42px;
  max-height: 150px;
}

.chat-input-row button {
  height: 42px;
  padding: 0 1.25rem;
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 1rem;
}

/* Admin */
.admin-page {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
}

.admin-page h2 { margin-bottom: 1rem; }

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.admin-tab {
  padding: 0.5rem 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text2);
  font-size: 0.85rem;
}

.admin-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.admin-section { margin-bottom: 2rem; }
.admin-section h3 { margin-bottom: 0.75rem; font-size: 0.95rem; }

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

th, td {
  text-align: left;
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text2);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: flex-start;
}

.form-row input, .form-row select, .form-row textarea {
  margin-bottom: 0;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 0.25rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 { margin-bottom: 1rem; }

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }
