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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f9;
  color: #1a1a2e;
  font-size: 14px;
  line-height: 1.5;
}

/* Navbar */
.navbar {
  background: #1a1a2e;
  color: #fff;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.nav-brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.5px; }
.nav-links a { color: #c9d1e0; text-decoration: none; margin-left: 1.5rem; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; }

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* Flash messages */
.flash-container { margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.flash-error { background: #fee2e2; color: #991b1b; border-left: 4px solid #ef4444; }
.flash-success { background: #dcfce7; color: #166534; border-left: 4px solid #22c55e; }

.flash-collapsible .flash-summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.flash-collapsible .flash-chevron { font-size: 1rem; transition: transform 0.2s; }
.flash-collapsible.open .flash-chevron { transform: rotate(180deg); }
.flash-detail-list { display: none; margin: 0.6rem 0 0 1rem; padding: 0; list-style: disc; font-size: 0.85rem; line-height: 1.8; }
.flash-collapsible.open .flash-detail-list { display: block; }

/* Cards */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 1.25rem;
}

/* Summary cards */
.summary-cards {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.summary-card {
  flex: 1;
  min-width: 160px;
  text-align: center;
  padding: 1rem;
  overflow: hidden;
}
.card-value { font-size: 1.4rem; font-weight: 700; color: #1a1a2e; word-break: break-word; }
.card-label { font-size: 0.75rem; color: #6b7280; margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.5px; }
.highlight-green .card-value { color: #166534; }
.highlight-amber .card-value { color: #92400e; }
.highlight-red .card-value { color: #991b1b; }
.highlight-purple .card-value { color: #6b21a8; }

/* Units-to-next-tier motivation states */
.tier-warm { background: linear-gradient(135deg, #fffbeb, #fff); border: 2px solid #fcd34d; }
.tier-warm .card-value { color: #92400e; }
.tier-hot {
  background: linear-gradient(135deg, #fff7e6, #fff);
  border: 2px solid #f5b942;
  animation: tier-pulse 1.6s ease-in-out infinite;
}
.tier-hot .card-value { color: #b45309; }
.tier-maxed { background: linear-gradient(135deg, #ecfdf5, #fff); border: 2px solid #34d399; }
.tier-maxed .card-value { color: #065f46; }
.tier-gain { font-size: 0.7rem; font-weight: 700; color: #b45309; margin-top: 0.35rem; }
@keyframes tier-pulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 185, 66, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(245, 185, 66, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 185, 66, 0); }
}

/* Upload grid */
.upload-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
@media (max-width: 720px) { .upload-grid { grid-template-columns: 1fr; } }
.upload-card h2 { font-size: 1rem; margin-bottom: 0.5rem; }

/* Page header */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { margin-bottom: 0.25rem; }

/* Headings */
h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; margin-bottom: 0.75rem; margin-top: 1.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
.form-group input[type="file"] { display: block; }
.form-group input[type="text"], .form-group input[type="email"], .form-group input[type="password"] {
  display: block; width: 100%; padding: 0.5rem 0.65rem; border: 1px solid #d1d5db;
  border-radius: 6px; font-size: 0.9rem;
}
.form-group input[type="checkbox"] { margin-right: 0.4rem; }
.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group input[type="password"]:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.form-hint { font-size: 0.82rem; color: #6b7280; margin-bottom: 1rem; line-height: 1.6; }
.form-hint code { background: #f1f5f9; padding: 1px 4px; border-radius: 3px; font-size: 0.8rem; }

/* Agent list (admin Manage Agents) — one elevated card per agent, a clear
   header (identity + destructive action) separated from a two-column body
   (CRM mapping / password), instead of one continuous bordered list. */
.user-list { display: flex; flex-direction: column; gap: 1rem; }
.agent-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 1.25rem 1.5rem;
}
.agent-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.1rem;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid #f1f5f9;
}
.agent-identity { display: flex; align-items: flex-start; gap: 0.85rem; min-width: 0; }
.agent-name-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.2rem; }
.agent-card-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}
.agent-section {
  background: #f8fafc;
  border: 1px solid #eef2f7;
  border-radius: 10px;
  padding: 0.9rem 1rem;
}
.user-avatar { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; background: #1a1a2e;
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 0.85rem; letter-spacing: 0.5px; }
.user-avatar.is-admin { background: #6d28d9; }
.user-name { font-weight: 700; font-size: 0.95rem; color: #1a1a2e; }
.user-email { font-size: 0.82rem; color: #6b7280; }
.user-section-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: #9ca3af; margin-bottom: 0.6rem; }
.user-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.user-actions input[type="text"], .user-actions input[type="password"] {
  flex: 1; padding: 0.4rem 0.6rem; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.82rem;
  min-width: 140px; background: #fff; }
.alias-chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.7rem; }
.chip { display: inline-flex; align-items: center; gap: 0.4rem; background: #eef2ff; color: #3730a3;
  border-radius: 9999px; padding: 0.25rem 0.4rem 0.25rem 0.75rem; font-size: 0.78rem; font-weight: 600; }
.chip button { background: rgba(55,48,163,0.12); border: none; color: #3730a3; cursor: pointer;
  font-weight: 700; width: 16px; height: 16px; border-radius: 50%; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem; }
.chip button:hover { background: rgba(55,48,163,0.25); }
.chip-empty { font-size: 0.8rem; color: #9ca3af; font-style: italic; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; margin-right: 0.25rem; }
.btn-block { display: block; width: 100%; text-align: center; padding: 0.7rem 1rem; font-size: 0.92rem; }

/* Table */
.table-wrapper { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-size: 0.82rem;
}
.data-table th {
  background: #1a1a2e;
  color: #e2e8f0;
  padding: 0.65rem 0.75rem;
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.data-table th[data-col] { cursor: pointer; user-select: none; }
.data-table th[data-col]:hover { background: #2d2d4e; }
.data-table th.sort-asc::after { content: " ▲"; }
.data-table th.sort-desc::after { content: " ▼"; }
.data-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }

/* Row highlights */
.row-green td { background: #f0fdf4; }
.row-amber td { background: #fffbeb; }
.row-red td { background: #fff1f1; }
.row-orange td { background: #fff7ed; }
.row-purple td { background: #faf5ff; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f1f5f9; color: #6b7280; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-red { background: #fee2e2; color: #991b1b; }

/* Tier badge */
.tier-badge {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  font-weight: 700;
  font-size: 0.78rem;
}
.tier-penalty { background: #fee2e2; color: #991b1b; }

/* Legend */
.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; font-size: 0.78rem; }
.legend-item { display: flex; align-items: center; gap: 0.35rem; }
.legend-item::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend-green::before { background: #bbf7d0; }
.legend-amber::before { background: #fde68a; }
.legend-red::before { background: #fecaca; }
.legend-orange::before { background: #fed7aa; }
.legend-purple::before { background: #e9d5ff; }

/* Table actions */
.table-actions { margin-bottom: 0.75rem; display: flex; gap: 0.5rem; align-items: center; }

/* Notes button */
.notes-btn {
  background: #e0e7ff;
  color: #3730a3;
  border: none;
  border-radius: 9999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.notes-btn:hover { background: #c7d2fe; }

/* Notes modal */
.notes-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.notes-modal-overlay.open { display: flex; }
.notes-modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: 400px;
  max-width: 90vw;
  padding: 1.25rem 1.5rem;
}
.notes-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.notes-modal-title { font-weight: 700; font-size: 1rem; }
.notes-modal-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #6b7280;
}
.notes-modal-close:hover { color: #1a1a2e; }
.notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.notes-list li {
  background: #f8fafc;
  border-left: 3px solid #6366f1;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: #1a1a2e;
  line-height: 1.5;
}

/* Agent drill-down link */
.agent-link { font-weight: 600; color: #2563eb; text-decoration: none; }
.agent-link:hover { text-decoration: underline; }

/* Back link */
.back-link { display: inline-block; color: #6b7280; font-size: 0.85rem; margin-bottom: 0.5rem; text-decoration: none; }
.back-link:hover { color: #1a1a2e; }

/* Misc */
.muted { color: #6b7280; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Loading UI (uploads / deletes) ---------- */

/* Top progress bar, Vercel-style */
#loading-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #6366f1, #22c55e);
  background-size: 200% 100%;
  z-index: 2100;
  opacity: 0;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.6);
  transition: width 3.5s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.25s ease;
  pointer-events: none;
}
#loading-bar.active {
  opacity: 1;
  animation: loading-bar-shimmer 1.1s linear infinite;
}
@keyframes loading-bar-shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: 200% 0; }
}

/* Full-screen overlay for heavier actions (uploads, deletes/resets) */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.loading-overlay.active { display: flex; opacity: 1; }
.loading-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.28);
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  max-width: 320px;
  text-align: center;
  animation: loading-card-in 0.25s ease;
}
@keyframes loading-card-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.loading-spinner {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  border-right-color: #6366f1;
  animation: loading-spin 0.7s linear infinite;
}
@keyframes loading-spin { to { transform: rotate(360deg); } }
.loading-card-text { font-weight: 700; color: #1a1a2e; font-size: 0.95rem; }
.loading-card-hint { font-size: 0.8rem; color: #6b7280; line-height: 1.5; }
.loading-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  margin: 0 2px;
  border-radius: 50%;
  background: #9ca3af;
  animation: loading-dot-bounce 1.1s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.24s; }
.loading-dots span:nth-child(2) { animation-delay: -0.12s; }
@keyframes loading-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Button loading state */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  opacity: 0.85;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  animation: loading-spin 0.6s linear infinite;
}
.btn-secondary.is-loading::after { border-color: rgba(55,65,81,0.35); border-top-color: #374151; }

/* ---------- Login page ---------- */
body.login-page { background: #f4f6f9; }
body.login-page .container { max-width: none; margin: 0; padding: 0; }
body.login-page .flash-container { padding: 1.25rem 1.5rem 0; }

.login-shell {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: calc(100vh - 56px);
}

.login-visual {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 3rem;
  background: linear-gradient(135deg, #1a1a2e 0%, #26214f 45%, #3730a3 100%);
  color: #fff;
}
.login-visual-inner { position: relative; z-index: 2; max-width: 420px; }
.login-visual h2 { font-size: 1.75rem; line-height: 1.3; margin-bottom: 0.75rem; }
.login-visual > .login-visual-inner > p { color: rgba(255,255,255,0.75); line-height: 1.6; margin-bottom: 1.85rem; font-size: 0.95rem; }
.login-highlights { list-style: none; display: flex; flex-direction: column; gap: 0.85rem; padding: 0; margin: 0; }
.login-highlights li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  color: rgba(255,255,255,0.92);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  animation: login-highlight-in 0.5s ease both;
}
.login-highlights li:nth-child(1) { animation-delay: 0.05s; }
.login-highlights li:nth-child(2) { animation-delay: 0.15s; }
.login-highlights li:nth-child(3) { animation-delay: 0.25s; }
@keyframes login-highlight-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.login-highlight-icon { font-size: 1rem; }

.login-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.35;
  z-index: 1;
  animation: login-blob-float 11s ease-in-out infinite;
}
.login-blob-1 { width: 280px; height: 280px; background: #6366f1; top: -70px; right: -70px; }
.login-blob-2 { width: 220px; height: 220px; background: #22c55e; bottom: -50px; left: -50px; animation-delay: -5s; }
@keyframes login-blob-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18px, -14px) scale(1.08); }
}

.login-form-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-form-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 15, 40, 0.08);
  padding: 2.25rem 2.25rem 2rem;
  animation: login-card-in 0.35s ease;
}
@keyframes login-card-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-form-card h1 { font-size: 1.4rem; margin-bottom: 0.35rem; }
.login-form-card > p.muted { margin-bottom: 1.5rem; font-size: 0.88rem; }
.login-footnote { margin-top: 1.25rem; font-size: 0.8rem; color: #6b7280; text-align: center; }

.google-signin-wrap { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: #9ca3af;
  font-size: 0.78rem;
  margin-bottom: 1.25rem;
}
.login-divider::before, .login-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid #e5e7eb;
}
.login-divider span { padding: 0 0.75rem; }

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-visual { display: none; }
}
