@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;1,9..40,300&display=swap');

:root {
  --bg-base:     #08080e;
  --bg-surface:  #0f0f18;
  --bg-elevated: #16161f;
  --bg-hover:    #1e1e2a;
  --bg-active:   #252535;

  --border:      rgba(255,255,255,0.07);
  --border-focus: rgba(99,102,241,0.6);

  --text-primary:   #f0f0f5;
  --text-secondary: #9898ae;
  --text-muted:     #5a5a72;

  --accent:       #6366f1;
  --accent-light: #818cf8;
  --accent-glow:  rgba(99,102,241,0.15);

  --success: #22c55e;
  --danger:  #ef4444;
  --warning: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --sidebar-width: 260px;
  --header-height: 60px;

  --font-display: 'Syne', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --glow:      0 0 24px rgba(99,102,241,0.2);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; border: none; background: none; font-family: inherit; }

input, textarea, select {
  font-family: var(--font-body);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-logo .logo-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--glow);
}
.sidebar-logo .logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.sidebar-section {
  padding: 0.75rem;
  flex: 1;
  overflow-y: auto;
}

.sidebar-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 0.5rem 0.25rem;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  border: 1px solid rgba(99,102,241,0.25);
  color: var(--accent-light);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  margin-bottom: 0.75rem;
}
.new-chat-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.chat-history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.chat-history-item:hover, .chat-history-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-history-item.active {
  background: var(--bg-active);
  border-left: 2px solid var(--accent);
}
.chat-history-item svg { flex-shrink: 0; opacity: 0.5; }

.sidebar-nav {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-active); color: var(--text-primary); }
.nav-item svg { opacity: 0.6; }

.sidebar-user {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.625rem;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 0.825rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 0.7rem; color: var(--text-muted); }

/* ─── Main Content ─── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Chat Area ─── */
.chat-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: rgba(8,8,14,0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.chat-header h2 { font-family: var(--font-display); font-size: 1rem; font-weight: 600; }

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

.message-group {
  padding: 0.875rem 1.5rem;
  display: flex;
  gap: 1rem;
  transition: background 0.15s;
}
.message-group:hover { background: rgba(255,255,255,0.01); }
.message-group.user { background: rgba(99,102,241,0.03); }

.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-avatar.ai {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  box-shadow: var(--glow);
}
.msg-avatar.user-av {
  background: var(--bg-active);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.msg-body { flex: 1; min-width: 0; }
.msg-sender { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.375rem; color: var(--text-secondary); }
.msg-content { font-size: 0.9rem; line-height: 1.7; color: var(--text-primary); }
.msg-content p { margin-bottom: 0.75rem; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.75rem 0;
}
.msg-content code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.84em;
}
.msg-content pre code { background: none; border: none; padding: 0; font-size: inherit; }

.msg-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ─── Chat Input ─── */
.chat-input-area {
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--border);
  background: rgba(8,8,14,0.9);
  backdrop-filter: blur(12px);
}
.input-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.625rem 0.625rem 0.625rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input-box textarea {
  flex: 1;
  background: none;
  border: none;
  resize: none;
  padding: 0;
  min-height: 24px;
  max-height: 180px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
  box-shadow: none;
}
.input-box textarea:focus { box-shadow: none; }
.input-box textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-light);
  box-shadow: var(--glow);
  transform: scale(1.05);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint { font-size: 0.72rem; color: var(--text-muted); text-align: center; margin-top: 0.5rem; }

/* ─── Welcome Screen ─── */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.welcome-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 1.5rem;
  box-shadow: var(--glow), 0 20px 60px rgba(99,102,241,0.2);
}
.welcome-screen h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-screen p { color: var(--text-secondary); max-width: 420px; font-size: 0.925rem; margin-bottom: 2rem; }

.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  max-width: 520px;
  width: 100%;
}
.suggestion-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.83rem;
  color: var(--text-secondary);
  line-height: 1.4;
}
.suggestion-card:hover {
  border-color: rgba(99,102,241,0.4);
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.suggestion-card strong { display: block; color: var(--text-primary); font-size: 0.875rem; margin-bottom: 0.25rem; }

/* ─── Typing indicator ─── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.875rem 1.5rem;
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: var(--font-body);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); box-shadow: var(--glow); }
.btn-secondary { background: var(--bg-elevated); border-color: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-icon { padding: 0.5rem; border-radius: var(--radius-sm); }

/* ─── Auth Pages ─── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  padding: 2rem;
  position: relative;
  overflow: hidden;
}
.auth-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,0.08) 0%, transparent 70%);
  top: -200px; right: -200px;
  pointer-events: none;
}
.auth-page::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139,92,246,0.06) 0%, transparent 70%);
  bottom: -100px; left: -100px;
  pointer-events: none;
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}
.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}
.auth-logo .mark {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  box-shadow: var(--glow);
}
.auth-logo .text {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; margin-bottom: 0.375rem; }
.auth-subtitle { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 1.75rem; }

.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.82rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.375rem; }

.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.85rem; color: var(--text-secondary); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.alert-error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.1); border-color: rgba(34,197,94,0.3); color: #86efac; }
.alert-info { background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.3); color: var(--accent-light); }

/* ─── Admin ─── */
.admin-layout {
  display: flex;
  min-height: 100vh;
}
.admin-sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  top: 0; left: 0;
}
.admin-main {
  margin-left: 240px;
  flex: 1;
  padding: 1.5rem;
  min-height: 100vh;
}
.admin-header {
  margin-bottom: 1.5rem;
}
.admin-header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
}
.admin-header p { color: var(--text-secondary); font-size: 0.875rem; }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-family: var(--font-display); font-size: 1rem; font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 0.75rem; }

/* ─── Table ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary);
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-active { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-suspended { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-admin { background: rgba(99,102,241,0.15); color: var(--accent-light); }
.badge-token { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ─── Global Chat ─── */
.global-chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
}
.global-msg {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 1.5rem;
}
.global-msg .meta { font-size: 0.8rem; }
.global-msg .meta .sender { font-weight: 600; color: var(--text-primary); }
.global-msg .meta .time { color: var(--text-muted); font-size: 0.72rem; margin-left: 0.5rem; }
.global-msg .text { font-size: 0.875rem; color: var(--text-secondary); margin-top: 0.1rem; }
.global-msg.own { flex-direction: row-reverse; }
.global-msg.own .text { text-align: right; color: var(--text-primary); }

/* ─── Mobile Toggle ─── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  width: 38px; height: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-toggle { display: flex; }
  .main-content { margin-left: 0; }
  .admin-sidebar { transform: translateX(-100%); }
  .admin-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .admin-main { margin-left: 0; padding-top: 4rem; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 1.75rem; }
}

/* ─── Utilities ─── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ─── Overlay ─── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  backdrop-filter: blur(4px);
}
.overlay.active { display: block; }

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.message-group { animation: fadeIn 0.25s ease; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ─── Profile ─── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
}
.profile-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
