:root {
  --sidebar-width: 250px;
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --bg-body: #f4f6fb;
}

* { box-sizing: border-box; }
body { background: var(--bg-body); font-family: 'Segoe UI', Roboto, -apple-system, sans-serif; }

.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background: #111827;
  color: #e5e7eb;
  flex-shrink: 0;
  min-height: 100vh;
  position: sticky;
  top: 0;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px; font-weight: 700; font-size: 1.05rem;
  color: #fff; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { color: var(--brand); font-size: 1.4rem; }
.sidebar-nav { padding: 10px 0; }
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; color: #cbd5e1; font-size: .92rem;
  border-left: 3px solid transparent;
}
.sidebar-nav .nav-link i { width: 18px; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav .nav-link.active { background: rgba(79,70,229,.15); color: #fff; border-left-color: var(--brand); }

/* Content */
.app-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { background: #fff; padding: 12px 24px; border-bottom: 1px solid #e5e7eb; position: sticky; top: 0; z-index: 20; }
.app-main { padding: 22px; flex: 1; }
.app-footer { padding: 14px 22px; text-align: center; }
.avatar-circle {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem;
}

/* Stat cards */
.stat-card { background: #fff; border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05); height: 100%; }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .78rem; color: #6b7280; }

.card { border: none; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.card-header { background: #fff; border-bottom: 1px solid #eef0f4; font-weight: 600; border-radius: 12px 12px 0 0 !important; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #4f46e5, #111827); }
.login-wrapper { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 36px 30px; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.6rem; }

/* Chat layout */
.chat-layout { display: flex; height: calc(100vh - 160px); background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.chat-list { width: 320px; flex-shrink: 0; border-right: 1px solid #eef0f4; display: flex; flex-direction: column; }
.chat-list-header { padding: 12px; border-bottom: 1px solid #eef0f4; }
.chat-list-body { overflow-y: auto; flex: 1; }
.chat-list-item { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid #f3f4f6; text-decoration: none; color: #111827; }
.chat-list-item:hover, .chat-list-item.active { background: #f5f6ff; }
.chat-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.chat-list-info { flex: 1; min-width: 0; }

.chat-window { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #eef1f8; }
.chat-window-header { padding: 14px 18px; background: #fff; border-bottom: 1px solid #eef0f4; font-weight: 600; }
.chat-window-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-window-footer { padding: 12px 16px; background: #fff; border-top: 1px solid #eef0f4; }

.msg-bubble { max-width: 70%; padding: 10px 14px; border-radius: 14px; font-size: .92rem; line-height: 1.4; position: relative; }
.msg-bubble.user { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; }
.msg-bubble.ai { align-self: flex-end; background: #d1e7ff; border-bottom-right-radius: 4px; }
.msg-bubble.admin { align-self: flex-end; background: #d4f4dd; border-bottom-right-radius: 4px; }
.msg-meta { font-size: .68rem; color: #9ca3af; margin-top: 4px; text-align: right; }
.msg-bubble img { max-width: 100%; border-radius: 8px; margin-bottom: 6px; cursor: pointer; }

@media (max-width: 991px) {
  .app-sidebar { position: fixed; z-index: 1030; transform: translateX(-100%); height: 100vh; }
  .app-sidebar.show { transform: translateX(0); }
  .chat-layout { height: calc(100vh - 200px); flex-direction: column; }
  .chat-list { width: 100%; max-height: 220px; }
}
