:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e6e8f0;
  --text: #1a1d29;
  --text-dim: #6b7086;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --success: #059669;
  --success-soft: #e7f8f1;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title { font-size: 16px; font-weight: 700; }

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c73ff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface-2); text-decoration: none; }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7c73ff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-meta { min-width: 0; }

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11.5px;
  color: var(--text-dim);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 9px 12px;
}

.logout-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.logout-btn:hover { background: #fde8e8; color: var(--danger); border-color: #f6c6c6; }

.main-area {
  flex: 1;
  min-width: 0;
}

.topbar {
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-title { font-size: 17px; font-weight: 700; line-height: 1.2; }
.subtitle { color: var(--text-dim); font-size: 13px; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* ---------- Login page ---------- */

.login-body { margin: 0; }

.login-shell {
  min-height: 100vh;
  display: flex;
}

.login-panel {
  position: relative;
  flex: 1.1;
  overflow: hidden;
  background: linear-gradient(155deg, #3730a3 0%, #4f46e5 50%, #6d5ef0 100%);
  color: #fff;
  padding: 64px 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-panel-pattern {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.9), rgba(0,0,0,0.15) 75%);
  pointer-events: none;
}

.login-panel-glow {
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 70%);
  top: -180px;
  right: -180px;
  pointer-events: none;
}

.login-panel-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 56px;
  position: relative;
  z-index: 1;
}

.logo-mark-lg {
  width: 44px;
  height: 44px;
  font-size: 19px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
}

.login-panel-title { font-size: 19px; font-weight: 700; }

.login-panel-heading {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.28;
  max-width: 420px;
  margin: 0 0 16px;
  position: relative;
  z-index: 1;
  letter-spacing: -0.01em;
}

.login-panel-text {
  font-size: 15px;
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.78);
  max-width: 400px;
  margin: 0 0 40px;
  position: relative;
  z-index: 1;
}

.login-panel-features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
  z-index: 1;
}

.login-panel-features li {
  display: flex;
  align-items: center;
  gap: 14px;
}

.feature-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  color: #fff;
}

.feature-icon svg { width: 15px; height: 15px; }

.feature-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
}

.feature-desc {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 1px;
}

.login-form-side {
  flex: 1;
  min-width: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.07), 0 2px 8px rgba(16, 24, 40, 0.05);
  padding: 44px 40px 36px;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #7c73ff);
}

.login-brand-mobile { display: none; align-items: center; gap: 10px; margin-bottom: 20px; }

.login-title {
  font-size: 23px;
  font-weight: 700;
  margin: 0 0 26px;
  letter-spacing: -0.01em;
}

.login-secured-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.login-secured-by svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.input-icon-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--text-dim);
  pointer-events: none;
}

.field .input-icon-group input {
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px 10px 38px;
}

.login-error-box { margin-top: 0; }
.login-error-box:not(:empty) { margin-top: 14px; }

.login-submit {
  width: 100%;
  margin-top: 24px;
  background: var(--accent);
  color: #fff;
  padding: 12px;
  font-size: 14.5px;
  box-shadow: var(--shadow);
}

.login-submit:hover { background: var(--accent-hover); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

@media (max-width: 860px) {
  .login-panel { display: none; }
  .login-form-side { min-width: 0; }
  .login-brand-mobile { display: flex; }
}

.search-card, .results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr) 140px;
  gap: 16px;
}

@media (max-width: 900px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 600; }

.field input, .field select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input::placeholder { color: #a4a9bd; }

.field select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7086' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}

.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}

#search-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

#search-btn:hover { background: var(--accent-hover); }
#search-btn:active { transform: translateY(1px); }
#search-btn:disabled { opacity: 0.6; cursor: not-allowed; }

#export-btn {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #bfe8d6;
}

#export-btn:hover { background: #d9f3e8; }
#export-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.results-actions { display: flex; gap: 10px; }

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #d6d9fb;
}

.btn-secondary:hover { background: #e2e4ff; }
.btn-secondary:disabled { opacity: 0.6; cursor: not-allowed; }

.status-text { color: var(--text-dim); font-size: 13px; }
.status-text.error { color: var(--danger); }

.results-card[hidden], .empty-state[hidden] { display: none; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.results-title { font-size: 16px; font-weight: 700; }
.results-meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.pagination:empty { margin-top: 0; }

.page-info {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.page-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 8px 14px;
}

.page-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Toast notifications ---------- */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12), 0 2px 8px rgba(16, 24, 40, 0.06);
  padding: 14px 14px 14px 16px;
  border-left: 4px solid var(--success);
  animation: toast-in 0.2s ease-out;
}

.toast-error { border-left-color: var(--danger); }

.toast-icon {
  display: flex;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--success);
}

.toast-error .toast-icon { color: var(--danger); }

.toast-icon svg { width: 18px; height: 18px; }

.toast-message {
  flex: 1;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
}

.toast-close {
  background: none;
  border: none;
  padding: 2px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.toast-close svg { width: 14px; height: 14px; }
.toast-close:hover { color: var(--text); }

.toast-out { animation: toast-out 0.2s ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(24px); }
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 820px; }

thead th {
  text-align: left;
  padding: 11px 14px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td.name { font-weight: 600; }
td.muted { color: var(--text-dim); }

a { color: var(--accent); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.rating-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: #b45309;
}

.rating-pill::before {
  content: "★";
  color: #f59e0b;
}

.link-btn {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 12.5px;
}

.link-btn:hover { background: var(--accent-soft); border-color: var(--accent); text-decoration: none; }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 70px 20px;
  font-size: 14px;
}

/* ---------- Facet chips (My Leads) ---------- */

.facet-group + .facet-group { margin-top: 18px; }

.facet-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.facet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.facet-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.facet-chip:hover { border-color: var(--accent); color: var(--accent); }

.facet-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.no-data-state {
  text-align: center;
  padding: 48px 20px;
}

.no-data-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 16px;
}

.no-data-icon svg { width: 24px; height: 24px; }

.no-data-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.no-data-text {
  font-size: 13.5px;
  color: var(--text-dim);
  margin: 0;
}

.facet-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.facet-tile:hover { border-color: var(--accent); background: var(--accent-soft); }

.facet-tile.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.facet-tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.facet-tile.active .facet-tile-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.facet-tile-icon svg { width: 17px; height: 17px; }

.facet-tile-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.facet-tile.active .facet-tile-name { color: #fff; }

.facet-tile-count {
  font-size: 12px;
  color: var(--text-dim);
}

.facet-tile.active .facet-tile-count { color: rgba(255, 255, 255, 0.85); }

.muted { color: var(--text-dim); font-size: 13px; }
