:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-w: 255px;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

/* Màn hình Đăng nhập */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 20px;
}

.login-card {
  background: #ffffff;
  width: 100%;
  max-width: 420px;
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 21px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
}

.login-sub {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 22px;
}

.quick-accounts {
  margin-top: 18px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 12px;
  font-size: 12.5px;
  color: #475569;
}

.quick-acc-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.quick-acc-btns button {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  color: #1e293b;
}
.quick-acc-btns button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand h2 {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-brand span {
  font-size: 12px;
  color: #94a3b8;
  display: block;
  margin-top: 2px;
}

.nav-menu {
  padding: 14px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 13px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-btn.active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-pill {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

.nav-pill.online {
  background: #22c55e;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
}

.user-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info strong {
  display: block;
  font-size: 13.5px;
  color: #fff;
}
.user-info small {
  color: #94a3b8;
  font-size: 11.5px;
}

.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  display: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.content-wrap {
  padding: 22px 24px 40px;
}

/* Common UI Elements */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.92; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-zalo { background: #0068ff; color: #fff; }
.btn-outline { background: #fff; border-color: #cbd5e1; color: #334155; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.03);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin: 6px 0 2px;
  color: var(--text);
}

.kpi-sub {
  font-size: 12px;
  color: #64748b;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 18px;
}

/* Filters & Tables */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.input, .select, .textarea {
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group {
  margin-bottom: 13px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}
.form-group .input, .form-group .select, .form-group .textarea {
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 13px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #64748b;
  background: #f8fafc;
  font-weight: 700;
}

tr.clickable-row {
  cursor: pointer;
  transition: background 0.12s;
}
tr.clickable-row:hover {
  background: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.st-new { background: #dbeafe; color: #1d4ed8; }
.st-calling { background: #fef3c7; color: #b45309; }
.st-interested { background: #ede9fe; color: #6d28d9; }
.st-callback { background: #ffedd5; color: #c2410c; }
.st-won { background: #dcfce7; color: #15803d; }
.st-lost { background: #f1f5f9; color: #64748b; }

.dot-online {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}
.dot-offline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}

/* Slide-over Lead Detail Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  z-index: 200;
  display: none;
  justify-content: flex-end;
}
.drawer-backdrop.open { display: flex; }

.drawer {
  width: 540px;
  max-width: 100vw;
  background: #fff;
  height: 100%;
  overflow-y: auto;
  padding: 22px 24px 36px;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
  animation: slideLeft 0.22s ease;
}

@keyframes slideLeft {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.timeline-item {
  border-left: 2px solid #cbd5e1;
  padding-left: 12px;
  margin-left: 6px;
  margin-bottom: 12px;
  position: relative;
}
.timeline-item::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  position: absolute;
  left: -5px;
  top: 6px;
}

/* Code snippet box */
.code-box {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 10px;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid #334155;
}

/* Live Chat Split Layout */
.chat-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  height: calc(100vh - 150px);
  min-height: 480px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.chat-thread-list {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.chat-thread-item {
  padding: 13px 15px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}
.chat-thread-item:hover, .chat-thread-item.active {
  background: #eff6ff;
}

.chat-room {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.chat-room-msgs {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crm-msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 13px;
  font-size: 13.5px;
}
.crm-msg.visitor {
  background: #fff;
  border: 1px solid #e2e8f0;
  align-self: flex-start;
}
.crm-msg.staff {
  background: var(--primary);
  color: #fff;
  align-self: flex-end;
}

.chat-room-form {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 370px;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 14px 16px;
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  border-left: 4px solid #22c55e;
  font-size: 13.5px;
  animation: slideLeft 0.25s ease;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 22px 24px;
  width: 100%;
  max-width: 460px;
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-area {
    margin-left: 0;
  }
  .mobile-menu-btn {
    display: inline-block;
  }
  .chat-layout {
    grid-template-columns: 1fr;
  }
}
