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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222635;
  --border: #2e3250;
  --primary: #4f7cff;
  --primary-hover: #3a65e8;
  --danger: #e85454;
  --text: #e2e4f0;
  --text-muted: #8b90b4;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; }

/* ── Navbar ───────────────────────────────────── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100;
}
.nav-brand { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-user { font-size: 0.85rem; color: var(--text-muted); }
.btn-logout { background: transparent; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 12px; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* ── Login Page ───────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 420px; padding: 24px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 40px; text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 12px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 6px; }
.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 28px; }
.login-form { text-align: left; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem; outline: none;
}
.form-group input:focus { border-color: var(--primary); }

/* ── Buttons ──────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 11px; background: var(--primary); border: none; border-radius: 8px;
  color: #fff; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.85rem; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; border-radius: 6px; border: none; cursor: pointer; }
.btn-danger { background: #3a1a1a; color: var(--danger); border: 1px solid #5a2222; }
.btn-danger:hover { background: #5a2222; }

/* ── Alert ────────────────────────────────────── */
.alert { padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: #3a1a1a; border: 1px solid #5a2222; color: #f87171; }

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

.chat-sidebar {
  width: 260px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-size: 0.85rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase;
}
.btn-new-chat {
  background: var(--primary); border: none; color: #fff; width: 28px; height: 28px;
  border-radius: 6px; cursor: pointer; font-size: 1.2rem; line-height: 1;
}
.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
  color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.session-item:hover, .session-item.active { background: var(--surface2); color: var(--text); }

.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

.welcome-msg { max-width: 560px; margin: auto; text-align: center; color: var(--text-muted); }
.welcome-msg h2 { color: var(--text); margin-bottom: 8px; }
.welcome-msg ul { text-align: left; padding-left: 20px; margin-top: 12px; line-height: 2; }

.message { display: flex; max-width: 75%; }
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message-content {
  padding: 12px 16px; border-radius: var(--radius); font-size: 0.9rem; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.message.user .message-content { background: var(--primary); color: #fff; }
.message.assistant .message-content { background: var(--surface); border: 1px solid var(--border); }

.chat-input-area {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--border); background: var(--bg);
}
.chat-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; color: var(--text); font-size: 0.9rem; resize: none; outline: none;
  max-height: 140px; font-family: var(--font);
}
.chat-input:focus { border-color: var(--primary); }
.btn-send {
  background: var(--primary); border: none; border-radius: 10px; width: 44px; height: 44px;
  color: #fff; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Typing indicator */
.typing-indicator .message-content { color: var(--text-muted); font-style: italic; }

/* ── Admin Layout ─────────────────────────────── */
.admin-layout { display: flex; min-height: calc(100vh - 56px); }
.admin-sidebar {
  width: 220px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 0; flex-shrink: 0;
}
.admin-sidebar h2 { padding: 0 16px 16px; font-size: 0.85rem; color: var(--text-muted);
  text-transform: uppercase; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.admin-sidebar nav a {
  display: block; padding: 10px 16px; color: var(--text-muted); text-decoration: none;
  font-size: 0.9rem; border-left: 3px solid transparent;
}
.admin-sidebar nav a:hover, .admin-sidebar nav a.active {
  color: var(--text); background: var(--surface2); border-left-color: var(--primary);
}
.admin-content { flex: 1; padding: 28px; overflow-y: auto; }
.admin-content h1 { font-size: 1.4rem; margin-bottom: 20px; }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-header h1, .section-header h2 { margin: 0; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
  padding: 10px 14px; text-align: left; font-size: 0.78rem; color: var(--text-muted);
  text-transform: uppercase; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--surface2); }

/* Filters */
.filters { margin-bottom: 16px; }
.filters form { display: flex; gap: 10px; flex-wrap: wrap; }
.filters input {
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.85rem; outline: none;
}
.filters input:focus { border-color: var(--primary); }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 12px; padding: 16px 0;
  color: var(--text-muted); font-size: 0.85rem; }
.pagination a { color: var(--primary); text-decoration: none; }

/* Badge */
.badge { padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge.admin { background: #2a1a4a; color: #a78bfa; }
.badge.user { background: #1a2a3a; color: #60a5fa; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal.hidden { display: none; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 440px; }
.modal-box h3 { margin-bottom: 20px; }
.modal-box input, .modal-box select {
  display: block; width: 100%; padding: 10px 14px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: 0.9rem; margin-bottom: 12px; outline: none;
}
.modal-box input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .btn-primary { flex: 1; width: auto; }

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