:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --hot: #ea580c;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #f1f5f9;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.75rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.login-brand p {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-mark.sm {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  border-radius: 8px;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

input[type="password"],
input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }

#login-form .btn-primary {
  width: 100%;
  margin-top: 1rem;
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.cell-actions .btn-sm {
  white-space: nowrap;
}

input.readonly {
  background: var(--surface-2, #f1f5f9);
  color: var(--muted, #64748b);
  cursor: not-allowed;
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: var(--danger);
}

.reg-footer {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.reg-section {
  margin-bottom: 2rem;
}

.team-section {
  margin-top: 0.5rem;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface2); }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
  margin-top: auto;
}

.btn-ghost:hover { color: var(--text); background: var(--surface2); }

#login-form { margin-top: 0.5rem; }

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 0.5rem 0.5rem;
  border-bottom: none;
  margin-bottom: 0;
}

.build-tag {
  font-size: 0.68rem;
  color: var(--muted);
  margin: 0 0.5rem 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.table-wrap .col-actions {
  width: 72px;
  white-space: nowrap;
}

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

.nav-item {
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover { background: #fff; color: var(--text); }

.nav-item.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.main {
  padding: 1.5rem 2rem 2.5rem;
  overflow-x: auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.topbar h2 {
  margin: 0;
  font-size: 1.5rem;
}

.muted { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.days-select {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.days-select select { width: auto; min-width: 110px; }

.panel { display: none; }
.panel.active { display: block; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.kpi .value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.kpi .label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }
.kpi.hot .value { color: var(--hot); }

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap::after {
  content: '';
  display: block;
  height: 0;
}

@media (max-width: 768px) {
  .table-wrap {
    margin: 0 -0.25rem;
    padding-bottom: 0.25rem;
  }

  .table-wrap table {
    min-width: 520px;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface2);
}

tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: #f8fafc; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
}

.badge.hot { background: #ffedd5; color: var(--hot); }
.badge.ok { background: #dcfce7; color: var(--success); }
.badge.warn { background: #fef3c7; color: var(--warn); }

.bar-list { padding: 1rem; }

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 48px;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.bar-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.banner-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

.banner-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #047857;
}

.banner-warn {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #b45309;
}

.banner-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  padding: 2rem 0;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar .search-wrap {
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}

.toolbar .search-wrap input { margin: 0; }

.toolbar .count {
  font-size: 0.85rem;
  color: var(--muted);
}

.code-cell {
  font-weight: 700;
  color: var(--accent);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.12);
}

.modal-wide {
  max-width: 560px;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.project-check-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: var(--surface2);
}

.project-check {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  border: 1px solid transparent;
}

.project-check:hover {
  border-color: var(--border);
}

.project-check input {
  width: auto;
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.project-check.is-hidden {
  display: none;
}

.project-check-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.9rem;
}

.project-check-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.field-check {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.35rem;
}

.check-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  margin: 0;
}

.check-inline input {
  width: auto;
  margin: 0;
}

.toolbar .btn-primary.btn-sm {
  padding: 0.45rem 0.9rem;
}

.filters-toolbar {
  align-items: flex-end;
}

.filter-field {
  flex: 1;
  min-width: 140px;
}

.activity-toolbar-inline,
.calls-toolbar-inline,
.leads-toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.activity-toolbar-inline .inline-field,
.calls-toolbar-inline .inline-field,
.leads-toolbar-inline .inline-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.activity-toolbar-inline .inline-field label,
.calls-toolbar-inline .inline-field label,
.leads-toolbar-inline .inline-field label {
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
}

.calls-toolbar-inline #calls-agent-filter,
.leads-toolbar-inline #leads-agent-filter {
  width: min(160px, 28vw);
  margin: 0;
}

.leads-toolbar-inline select,
.calls-toolbar-inline select,
.activity-toolbar-inline select {
  width: min(160px, 28vw);
  margin: 0;
  padding: 0.45rem 0.5rem;
  font-size: 0.875rem;
}

.leads-toolbar-inline .search-wrap {
  flex: 1;
  min-width: min(200px, 36vw);
  max-width: 280px;
}

.leads-toolbar-inline .search-wrap input {
  width: 100%;
  margin: 0;
}

.activity-toolbar-inline .btn,
.calls-toolbar-inline .btn,
.leads-toolbar-inline .btn {
  flex-shrink: 0;
  margin-bottom: 0;
}

.leads-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.leads-pagination-bottom {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.legacy-pool-pagination {
  justify-content: space-between;
}
.legacy-pool-pagination .pagination {
  flex: 1;
}
.leads-page-info {
  font-size: 0.88rem;
  color: var(--muted);
  min-width: 10rem;
}
.leads-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.75rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}

.leads-selected-count {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-right: 0.25rem;
}

.leads-table-wrap .col-check {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}

.leads-table-wrap .col-check input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
}

.leads-table-wrap th.col-check,
.leads-table-wrap td.col-check {
  padding-left: 0.5rem;
  padding-right: 0.35rem;
}

.calls-date-range {
  flex-shrink: 0;
}

.calls-date-range-title {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.calls-date-range-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.35rem 0.4rem;
  padding: 0.35rem 0.5rem 0.35rem 0.55rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.calls-date-lbl {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.calls-date-sep {
  color: var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 0.1rem;
  user-select: none;
}

.calls-toolbar-inline .calls-date-range-row input[type="date"] {
  width: min(132px, 22vw);
  margin: 0;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface2);
  font-size: 0.82rem;
}

.calls-toolbar-inline .calls-date-range-row input[type="date"]:focus {
  border-color: var(--accent);
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.filter-field label {
  margin-bottom: 0.35rem;
}

.label-hint {
  font-weight: 400;
  color: var(--muted);
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  padding: 0.5rem 0;
}

.pagination .page-btn.btn-primary {
  color: #fff;
}

.page-info {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

@media (max-width: 900px) {
  .filters-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
  }

  .calls-toolbar-inline,
  .leads-toolbar-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .calls-toolbar-inline #calls-agent-filter,
  .leads-toolbar-inline #leads-agent-filter,
  .leads-toolbar-inline select,
  .leads-toolbar-inline .search-wrap {
    width: 100%;
    max-width: none;
  }

  .calls-date-range-row {
    flex-wrap: wrap;
  }

  .calls-toolbar-inline .calls-date-range-row input[type="date"] {
    flex: 1;
    min-width: 120px;
    width: auto;
  }

  .calls-toolbar-inline .btn,
  .leads-toolbar-inline .btn {
    width: 100%;
  }

  .pagination {
    justify-content: center;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-row .field { min-width: 0; }

/* ——— Mobile navigation ——— */
.nav-toggle {
  display: none;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: '';
  position: absolute;
  left: 0;
}

.nav-toggle-icon::before { top: -6px; }
.nav-toggle-icon::after { top: 6px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1040;
}

body.nav-open {
  overflow: hidden;
}

.topbar-left {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.topbar-titles {
  min-width: 0;
}

.topbar-titles h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(288px, 88vw);
    z-index: 1050;
    padding: 1rem 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-nav {
    flex: 1;
    overflow-y: auto;
  }

  .nav-item {
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .sidebar-logout {
    width: 100%;
    margin-top: 0.5rem;
    min-height: 44px;
  }

  .main {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    width: 100%;
    min-width: 0;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .topbar h2 {
    font-size: 1.25rem;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .days-select {
    flex: 1;
    min-width: 120px;
  }

  .days-select select {
    width: 100%;
  }

  .topbar-actions .btn-secondary {
    flex: 1;
    min-width: 100px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .kpi {
    padding: 0.85rem;
  }

  .kpi .value {
    font-size: 1.4rem;
  }

  .kpi .label {
    font-size: 0.72rem;
  }

  .section-title {
    font-size: 0.85rem;
    margin-top: 1.25rem;
  }

  .bar-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.35rem 0.5rem;
  }

  .bar-row span:first-child {
    grid-column: 1 / -1;
  }

  .bar-row .bar-track {
    grid-column: 1;
  }

  .bar-row span:last-child {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .search-wrap {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .toolbar .btn-primary.btn-sm {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal,
  .modal-wide {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .modal-header h3 {
    font-size: 1rem;
    padding-right: 0.5rem;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1;
    min-width: 120px;
  }

  .project-check-list {
    max-height: 40vh;
  }

  th, td {
    padding: 0.55rem 0.65rem;
    font-size: 0.82rem;
  }

  .login-card {
    padding: 1.5rem;
  }

  .login-brand h1 {
    font-size: 1.2rem;
  }
}

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

  .topbar-actions {
    flex-direction: column;
  }

  .topbar-actions .btn-secondary,
  .days-select {
    width: 100%;
  }
}

/* ─── Ad Mappings panel ───────────────────────────────────────────────── */
.mono {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  background: var(--surface-2, #f4f5f7);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.badge-green {
  background: #dcfce7;
  color: #166534;
}

.badge-grey {
  background: #f1f5f9;
  color: #64748b;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary, #64748b);
  margin-top: 0.25rem;
  max-width: 60ch;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-secondary, #64748b);
  margin-top: 0.25rem;
}

.field-hint code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.76rem;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
}

.optional {
  font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8);
  font-weight: 400;
  margin-left: 4px;
}

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border: none;
}
.btn-danger:hover {
  background: #fecaca;
}

/* ─── Campaign Mapping panel ──────────────────────────────────────────────── */

.agents-cell {
  max-width: 280px;
}

.agent-badge {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  margin: 2px 3px 2px 0;
  white-space: nowrap;
}

/* Agent picker — available list */
.agent-pick-list {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 6px;
}

.agent-pick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border, #f1f5f9);
  transition: background 0.1s;
}

.agent-pick-item:last-child { border-bottom: none; }
.agent-pick-item:hover { background: #f8fafc; }

.agent-pick-role {
  font-size: 0.72rem;
  flex: 1;
}

/* Agent sortable list (selected) */
.field-sublabel {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  margin: 10px 0 4px;
}

.agent-sortable-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  overflow: hidden;
}

.agent-sortable-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border, #f1f5f9);
  cursor: default;
  user-select: none;
  transition: background 0.1s;
}

.agent-sortable-item:last-child { border-bottom: none; }
.agent-sortable-item:hover { background: #f8fafc; }
.agent-sortable-item[draggable="true"] { cursor: grab; }
.agent-sortable-item[draggable="true"]:active { cursor: grabbing; }

.drag-handle {
  color: #94a3b8;
  font-size: 1rem;
  cursor: grab;
  padding: 0 2px;
}

.agent-order-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #1d4ed8;
  color: #fff;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.agent-name {
  flex: 1;
  font-size: 0.875rem;
}

/* Search within picker */
#amf-agent-search-wrap {
  padding: 6px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background: #fafafa;
}

#amf-agent-search {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Table improvements */
.text-muted { color: #94a3b8; font-size: 0.8rem; }:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --hot: #ea580c;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #f1f5f9;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.75rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.login-brand p {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-mark.sm {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  border-radius: 8px;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

input[type="password"],
input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }

#login-form .btn-primary {
  width: 100%;
  margin-top: 1rem;
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.cell-actions .btn-sm {
  white-space: nowrap;
}

input.readonly {
  background: var(--surface-2, #f1f5f9);
  color: var(--muted, #64748b);
  cursor: not-allowed;
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: var(--danger);
}

.reg-footer {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.reg-section {
  margin-bottom: 2rem;
}

.team-section {
  margin-top: 0.5rem;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface2); }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
  margin-top: auto;
}

.btn-ghost:hover { color: var(--text); background: var(--surface2); }

#login-form { margin-top: 0.5rem; }

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 0.5rem 0.5rem;
  border-bottom: none;
  margin-bottom: 0;
}

.build-tag {
  font-size: 0.68rem;
  color: var(--muted);
  margin: 0 0.5rem 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.table-wrap .col-actions {
  width: 72px;
  white-space: nowrap;
}

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

.nav-item {
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover { background: #fff; color: var(--text); }

.nav-item.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.main {
  padding: 1.5rem 2rem 2.5rem;
  overflow-x: auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.topbar h2 {
  margin: 0;
  font-size: 1.5rem;
}

.muted { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.days-select {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.days-select select { width: auto; min-width: 110px; }

.panel { display: none; }
.panel.active { display: block; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.kpi .value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.kpi .label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }
.kpi.hot .value { color: var(--hot); }

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap::after {
  content: '';
  display: block;
  height: 0;
}

@media (max-width: 768px) {
  .table-wrap {
    margin: 0 -0.25rem;
    padding-bottom: 0.25rem;
  }

  .table-wrap table {
    min-width: 520px;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface2);
}

tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: #f8fafc; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
}

.badge.hot { background: #ffedd5; color: var(--hot); }
.badge.ok { background: #dcfce7; color: var(--success); }
.badge.warn { background: #fef3c7; color: var(--warn); }

.bar-list { padding: 1rem; }

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 48px;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.bar-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.banner-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

.banner-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #047857;
}

.banner-warn {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #b45309;
}

.banner-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  padding: 2rem 0;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar .search-wrap {
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}

.toolbar .search-wrap input { margin: 0; }

.toolbar .count {
  font-size: 0.85rem;
  color: var(--muted);
}

.code-cell {
  font-weight: 700;
  color: var(--accent);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.12);
}

.modal-wide {
  max-width: 560px;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.project-check-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: var(--surface2);
}

.project-check {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  border: 1px solid transparent;
}

.project-check:hover {
  border-color: var(--border);
}

.project-check input {
  width: auto;
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.project-check.is-hidden {
  display: none;
}

.project-check-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.9rem;
}

.project-check-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.field-check {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.35rem;
}

.check-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  margin: 0;
}

.check-inline input {
  width: auto;
  margin: 0;
}

.toolbar .btn-primary.btn-sm {
  padding: 0.45rem 0.9rem;
}

.filters-toolbar {
  align-items: flex-end;
}

.filter-field {
  flex: 1;
  min-width: 140px;
}

.activity-toolbar-inline,
.calls-toolbar-inline,
.leads-toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.activity-toolbar-inline .inline-field,
.calls-toolbar-inline .inline-field,
.leads-toolbar-inline .inline-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.activity-toolbar-inline .inline-field label,
.calls-toolbar-inline .inline-field label,
.leads-toolbar-inline .inline-field label {
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
}

.calls-toolbar-inline #calls-agent-filter,
.leads-toolbar-inline #leads-agent-filter {
  width: min(160px, 28vw);
  margin: 0;
}

.leads-toolbar-inline select,
.calls-toolbar-inline select,
.activity-toolbar-inline select {
  width: min(160px, 28vw);
  margin: 0;
  padding: 0.45rem 0.5rem;
  font-size: 0.875rem;
}

.leads-toolbar-inline .search-wrap {
  flex: 1;
  min-width: min(200px, 36vw);
  max-width: 280px;
}

.leads-toolbar-inline .search-wrap input {
  width: 100%;
  margin: 0;
}

.activity-toolbar-inline .btn,
.calls-toolbar-inline .btn,
.leads-toolbar-inline .btn {
  flex-shrink: 0;
  margin-bottom: 0;
}

.leads-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.leads-pagination-bottom {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.legacy-pool-pagination {
  justify-content: space-between;
}
.legacy-pool-pagination .pagination {
  flex: 1;
}
.leads-page-info {
  font-size: 0.88rem;
  color: var(--muted);
  min-width: 10rem;
}
.leads-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.75rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}

.leads-selected-count {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-right: 0.25rem;
}

.leads-table-wrap .col-check {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}

.leads-table-wrap .col-check input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
}

.leads-table-wrap th.col-check,
.leads-table-wrap td.col-check {
  padding-left: 0.5rem;
  padding-right: 0.35rem;
}

.calls-date-range {
  flex-shrink: 0;
}

.calls-date-range-title {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.calls-date-range-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.35rem 0.4rem;
  padding: 0.35rem 0.5rem 0.35rem 0.55rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.calls-date-lbl {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.calls-date-sep {
  color: var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 0.1rem;
  user-select: none;
}

.calls-toolbar-inline .calls-date-range-row input[type="date"] {
  width: min(132px, 22vw);
  margin: 0;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface2);
  font-size: 0.82rem;
}

.calls-toolbar-inline .calls-date-range-row input[type="date"]:focus {
  border-color: var(--accent);
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.filter-field label {
  margin-bottom: 0.35rem;
}

.label-hint {
  font-weight: 400;
  color: var(--muted);
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  padding: 0.5rem 0;
}

.pagination .page-btn.btn-primary {
  color: #fff;
}

.page-info {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

@media (max-width: 900px) {
  .filters-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
  }

  .calls-toolbar-inline,
  .leads-toolbar-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .calls-toolbar-inline #calls-agent-filter,
  .leads-toolbar-inline #leads-agent-filter,
  .leads-toolbar-inline select,
  .leads-toolbar-inline .search-wrap {
    width: 100%;
    max-width: none;
  }

  .calls-date-range-row {
    flex-wrap: wrap;
  }

  .calls-toolbar-inline .calls-date-range-row input[type="date"] {
    flex: 1;
    min-width: 120px;
    width: auto;
  }

  .calls-toolbar-inline .btn,
  .leads-toolbar-inline .btn {
    width: 100%;
  }

  .pagination {
    justify-content: center;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-row .field { min-width: 0; }

/* ——— Mobile navigation ——— */
.nav-toggle {
  display: none;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: '';
  position: absolute;
  left: 0;
}

.nav-toggle-icon::before { top: -6px; }
.nav-toggle-icon::after { top: 6px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1040;
}

body.nav-open {
  overflow: hidden;
}

.topbar-left {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.topbar-titles {
  min-width: 0;
}

.topbar-titles h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(288px, 88vw);
    z-index: 1050;
    padding: 1rem 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-nav {
    flex: 1;
    overflow-y: auto;
  }

  .nav-item {
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .sidebar-logout {
    width: 100%;
    margin-top: 0.5rem;
    min-height: 44px;
  }

  .main {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    width: 100%;
    min-width: 0;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .topbar h2 {
    font-size: 1.25rem;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .days-select {
    flex: 1;
    min-width: 120px;
  }

  .days-select select {
    width: 100%;
  }

  .topbar-actions .btn-secondary {
    flex: 1;
    min-width: 100px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .kpi {
    padding: 0.85rem;
  }

  .kpi .value {
    font-size: 1.4rem;
  }

  .kpi .label {
    font-size: 0.72rem;
  }

  .section-title {
    font-size: 0.85rem;
    margin-top: 1.25rem;
  }

  .bar-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.35rem 0.5rem;
  }

  .bar-row span:first-child {
    grid-column: 1 / -1;
  }

  .bar-row .bar-track {
    grid-column: 1;
  }

  .bar-row span:last-child {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .search-wrap {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .toolbar .btn-primary.btn-sm {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal,
  .modal-wide {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .modal-header h3 {
    font-size: 1rem;
    padding-right: 0.5rem;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1;
    min-width: 120px;
  }

  .project-check-list {
    max-height: 40vh;
  }

  th, td {
    padding: 0.55rem 0.65rem;
    font-size: 0.82rem;
  }

  .login-card {
    padding: 1.5rem;
  }

  .login-brand h1 {
    font-size: 1.2rem;
  }
}

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

  .topbar-actions {
    flex-direction: column;
  }

  .topbar-actions .btn-secondary,
  .days-select {
    width: 100%;
  }
}

/* ─── Ad Mappings panel ───────────────────────────────────────────────── */
.mono {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  background: var(--surface-2, #f4f5f7);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.badge-green {
  background: #dcfce7;
  color: #166534;
}

.badge-grey {
  background: #f1f5f9;
  color: #64748b;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary, #64748b);
  margin-top: 0.25rem;
  max-width: 60ch;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-secondary, #64748b);
  margin-top: 0.25rem;
}

.field-hint code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.76rem;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
}

.optional {
  font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8);
  font-weight: 400;
  margin-left: 4px;
}

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border: none;
}
.btn-danger:hover {
  background: #fecaca;
}

/* ─── Campaign Mapping panel ──────────────────────────────────────────────── */

.agents-cell {
  max-width: 280px;
}

.agent-badge {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  margin: 2px 3px 2px 0;
  white-space: nowrap;
}

/* Agent picker — available list */
.agent-pick-list {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 6px;
}

.agent-pick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border, #f1f5f9);
  transition: background 0.1s;
}

.agent-pick-item:last-child { border-bottom: none; }
.agent-pick-item:hover { background: #f8fafc; }

.agent-pick-role {
  font-size: 0.72rem;
  flex: 1;
}

/* Agent sortable list (selected) */
.field-sublabel {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  margin: 10px 0 4px;
}

.agent-sortable-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  overflow: hidden;
}

.agent-sortable-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border, #f1f5f9);
  cursor: default;
  user-select: none;
  transition: background 0.1s;
}

.agent-sortable-item:last-child { border-bottom: none; }
.agent-sortable-item:hover { background: #f8fafc; }
.agent-sortable-item[draggable="true"] { cursor: grab; }
.agent-sortable-item[draggable="true"]:active { cursor: grabbing; }

.drag-handle {
  color: #94a3b8;
  font-size: 1rem;
  cursor: grab;
  padding: 0 2px;
}

.agent-order-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #1d4ed8;
  color: #fff;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.agent-name {
  flex: 1;
  font-size: 0.875rem;
}

/* Search within picker */
#amf-agent-search-wrap {
  padding: 6px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background: #fafafa;
}

#amf-agent-search {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Table improvements */
.text-muted { color: #94a3b8; font-size: 0.8rem; }

/* ─── Custom Select Combobox ────────────────────────────────────────────── */
.combo {
  position: relative;
  display: block;
  width: 100%;
  min-width: 190px;
}

.combo-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.combo-trigger:focus,
.combo-trigger.has-value {
  border-color: var(--accent);
  outline: none;
}

.combo-trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combo-chevron {
  color: var(--muted);
  margin-left: 0.5rem;
  font-size: 0.75rem;
}

.combo-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  max-height: 250px;
  overflow: hidden;
}

.combo-menu.hidden {
  display: none !important;
}

.combo-search-wrap {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.combo-search-wrap input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.85rem;
  font-family: var(--font);
  box-sizing: border-box;
}

.combo-search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.combo-options {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.combo-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  font-size: 0.85rem;
  transition: background 0.1s;
}

.combo-option:last-child {
  border-bottom: none;
}

.combo-option:hover,
.combo-option:focus {
  background: var(--surface2);
  outline: none;
}

.combo-option.is-selected {
  background: #eff6ff;
  color: var(--accent);
  font-weight: 600;
}

.combo-option.is-hidden {
  display: none !important;
}

.combo-option-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.agent-checklist-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.agent-checklist-box .combo-search-wrap {
  border-bottom: 1px solid var(--border);
}
.agent-checklist-scroll {
  max-height: 220px;
  overflow: auto;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
}

.is-hidden {
  display: none !important;
}

.unit-editor {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.unit-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.35rem;
}

.unit-editor-scroll {
  overflow-x: auto;
  padding: 0 0.5rem 0.75rem;
}

.unit-editor-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.unit-editor-table th,
.unit-editor-table td {
  padding: 0.35rem 0.3rem;
  vertical-align: middle;
}

.unit-editor-table th {
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.unit-editor-table input,
.unit-editor-table select {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}

.unit-editor-table .unit-col-label input {
  min-width: 9rem;
}

.unit-editor-table .unit-col-num input {
  min-width: 5.5rem;
}

.btn-remove-unit {
  color: var(--danger, #b91c1c);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
}
.unit-editor {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.unit-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.35rem;
}

.unit-editor-scroll {
  overflow-x: auto;
  padding: 0 0.5rem 0.75rem;
}

.unit-editor-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.unit-editor-table th,
.unit-editor-table td {
  padding: 0.35rem 0.3rem;
  vertical-align: middle;
}

.unit-editor-table th {
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.unit-editor-table input,
.unit-editor-table select {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}

.unit-editor-table .unit-col-label input {
  min-width: 9rem;
}

.unit-editor-table .unit-col-num input {
  min-width: 5.5rem;
}

.btn-remove-unit {
  color: var(--danger, #b91c1c);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
}

/* ── Lead Automation panel ─────────────────────────────── */
.la-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.la-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.la-tab.active {
  color: var(--primary, #2563eb);
  border-bottom-color: var(--primary, #2563eb);
}
.la-tabpanel { display: none; }
.la-tabpanel.active { display: block; }

.la-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.la-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.la-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.la-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.la-card-meta span {
  background: var(--bg-chip, rgba(0,0,0,0.05));
  padding: 2px 7px;
  border-radius: 100px;
}
.la-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.la-card-assigned {
  font-size: 0.78rem;
  color: var(--muted);
}
.la-card.is-mapped {
  border-color: var(--success-border, #86efac);
  background: var(--success-bg, #f0fdf4);
}
.la-card.is-mapped .la-card-name::after {
  content: ' ✓';
  color: var(--success, #16a34a);
  font-weight: 700;
}

/* Lead list + detail (Recent leads) */
.leads-table-wrap .col-datetime {
  font-size: 0.82rem;
  color: var(--muted, #64748b);
  white-space: nowrap;
}

.leads-table-wrap .col-actions {
  width: 6.5rem;
  text-align: right;
  white-space: nowrap;
}

.leads-table-wrap .lead-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.leads-table-wrap tr.lead-row.clickable {
  cursor: pointer;
}

.leads-table-wrap tr.lead-row.clickable:hover td {
  background: #f8fafc;
}

.leads-table-wrap tr.lead-row.clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.an-status-table tr.an-status-row.clickable {
  cursor: pointer;
}

.an-status-table tr.an-status-row.clickable:hover td {
  background: #f8fafc;
}

.an-status-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent, #2563eb);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.an-status-link:hover {
  color: #1d4ed8;
}

.lead-cell-name {
  font-weight: 500;
}

.lead-detail-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.65rem 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lead-detail-status-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding-bottom: 0.35rem;
  margin-bottom: 0.15rem;
  border-bottom: 1px solid var(--border);
}

.lead-detail-status-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.lead-status-badge {
  font-size: 0.85rem;
}

.lead-detail-kv {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.lead-detail-k {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.lead-detail-v {
  font-size: 0.92rem;
  color: var(--text);
  word-break: break-word;
}

.lead-detail-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.lead-form-qa {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.lead-form-row {
  display: grid;
  grid-template-columns: minmax(8rem, 34%) 1fr;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lead-form-q {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.lead-form-a {
  font-size: 0.92rem;
  color: var(--text);
  word-break: break-word;
}

.lead-client-messages {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.lead-client-message-item {
  padding: 0.65rem 0.75rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lead-client-message-meta {
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.lead-client-message-body {
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.activity-panel-hint {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
}

.activity-leads-table .lead-row {
  cursor: pointer;
}

/* WhatsApp messages inbox — layout only when this panel is active */
#panel-wamessages.panel.active {
  margin: 0 -0.25rem;
  height: calc(100vh - 150px);
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.wa-inbox {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
}

.wa-inbox-list {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #f8fafc;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.wa-inbox-list-head {
  padding: 0.85rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  background: #075e54;
  color: #fff;
}

.wa-inbox-search-wrap {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #f0f2f5;
}

.wa-inbox-search {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
}

.wa-inbox-search:focus {
  outline: 2px solid #075e54;
  outline-offset: 0;
}

.wa-chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.wa-chat-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.wa-chat-item:hover {
  background: #f0f2f5;
}

.wa-chat-item.active {
  background: #e9edef;
}

.wa-chat-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.wa-chat-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

.wa-chat-time {
  font-size: 0.72rem;
  flex-shrink: 0;
}

.wa-chat-phone {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.wa-chat-preview {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-chat-campaign {
  font-size: 0.72rem;
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-chat-loading,
.wa-chat-empty {
  padding: 1.5rem;
  text-align: center;
}

.wa-inbox-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #e5ddd5;
}

.wa-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: #075e54;
  color: #fff;
}

.wa-thread-header-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.wa-thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.wa-thread-title {
  font-weight: 600;
  font-size: 1rem;
}

.wa-thread-sub {
  font-size: 0.82rem;
  opacity: 0.9;
}

.wa-thread-header .btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  flex-shrink: 0;
}

.wa-thread-header .btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.25);
}

.wa-campaign-banner {
  padding: 0.5rem 1rem;
  background: #dcf8c6;
  border-bottom: 1px solid #c5e1a5;
  font-size: 0.82rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.wa-campaign-banner-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: #33691e;
}

.wa-campaign-banner-value {
  color: #1b5e20;
  font-weight: 500;
}

.wa-campaign-id,
.wa-ad-id {
  font-family: ui-monospace, monospace;
  font-size: 0.85em;
}

.wa-campaign-pending {
  font-size: 0.78rem;
}

.wa-campaign-banner-meta {
  color: var(--muted);
  width: 100%;
  font-size: 0.78rem;
}

.wa-thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #e5ddd5;
}

.wa-bubble {
  max-width: 78%;
  padding: 0.5rem 0.65rem 0.35rem;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.wa-bubble-in {
  align-self: flex-start;
  background: #fff;
  border-top-left-radius: 2px;
}

.wa-bubble-text {
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.wa-bubble-meta {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: right;
  margin-top: 0.25rem;
}

.wa-no-msgs {
  margin: auto;
  text-align: center;
}

.wa-thread-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--muted);
  background: #f0f2f5;
  text-align: center;
}

.wa-thread-empty-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.lead-activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.lead-activity-item {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.lead-activity-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
}

.lead-activity-detail {
  margin-top: 0.35rem;
  font-size: 0.88rem;
  color: var(--text);
  white-space: pre-wrap;
}

.lead-call-screenshot {
  margin-top: 0.5rem;
}

.lead-call-screenshot a {
  display: inline-block;
  line-height: 0;
}

.lead-call-screenshot img {
  display: block;
  max-width: min(100%, 320px);
  max-height: 240px;
  width: auto;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: box-shadow 0.15s ease;
}

.lead-call-screenshot a:hover img {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Agent reports panel */
.reports-toolbar {
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.report-custom-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
}

.report-custom-dates {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.report-print-area {
  margin-top: 1rem;
}

.report-header-block h3 {
  margin: 0 0 0.25rem;
}

.report-period-line {
  margin: 0.5rem 0 0.15rem;
}

.report-generated {
  margin: 0 0 1rem;
  font-size: 0.85rem;
}

.report-kpi-grid {
  margin-bottom: 1.25rem;
}

.report-table-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.report-legend {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  line-height: 1.45;
}

.report-section-title {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
}

.report-kpi .kpi-hint {
  font-size: 0.78rem;
  margin-top: 0.2rem;
}

/* Team daily summary */
.report-team-section {
  margin: 1.25rem 0 1.75rem;
  padding: 1rem 1.1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.report-team-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.team-top-caller-line {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.team-top-row {
  background: #fff7ed;
}

.team-report-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.team-summary-kpis {
  margin-bottom: 0.5rem;
}

.team-kpi-btn {
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.team-kpi-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.team-kpi-btn.team-kpi-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.team-kpi-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.team-kpi-btn:disabled:hover {
  border-color: var(--border);
  box-shadow: none;
}

.team-connected-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.team-connected-btn:hover {
  color: var(--accent-hover, #1d4ed8);
}

.pipeline-total-hint {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.88rem;
}

.team-kpi-static {
  cursor: default;
}

.kpi-tap-hint {
  font-size: 0.72rem;
  margin-top: 0.35rem;
}

.team-drill-panel {
  margin: 0.75rem 0 1rem;
  padding: 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.team-drill-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.team-drill-head h5 {
  margin: 0;
  font-size: 0.95rem;
}

.team-drill-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.team-drill-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.team-drill-close {
  min-width: 36px;
  padding: 0.25rem 0.5rem;
  font-size: 1.1rem;
  line-height: 1;
}

/* Responsive polish — mobile & tablet */
.app {
  min-width: 0;
}

.main {
  min-width: 0;
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.topbar-actions {
  margin-left: auto;
}

.topbar-actions .btn-secondary {
  min-height: 44px;
}

.inline-field {
  min-width: 0;
}

.inline-field select,
.inline-field input[type="date"] {
  max-width: 100%;
}

.reports-toolbar .inline-field,
.reports-toolbar .report-custom-dates,
.reports-toolbar .btn {
  flex: 1 1 auto;
  min-width: 140px;
}

.report-team-head .inline-field {
  flex: 0 1 auto;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .topbar-actions {
    width: auto;
    margin-left: auto;
  }

  .reports-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .reports-toolbar .inline-field,
  .reports-toolbar .report-custom-toggle,
  .reports-toolbar .report-custom-dates,
  .reports-toolbar .btn {
    width: 100%;
    min-width: 0;
  }

  .report-custom-dates {
    flex-direction: column;
    align-items: stretch;
  }

  .report-team-head {
    flex-direction: column;
    align-items: stretch;
  }

  .report-team-head .inline-field input[type="date"] {
    width: 100%;
  }

  .team-summary-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .leads-toolbar-inline,
  .calls-toolbar-inline,
  .activity-toolbar-inline,
  .legacy-pool-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .leads-toolbar-inline > *,
  .calls-toolbar-inline > *,
  .activity-toolbar-inline > * {
    width: 100%;
    min-width: 0;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  #panel-leadauto .panel-header > div:last-child {
    flex-wrap: wrap;
    width: 100%;
  }

  .la-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .data-table th,
  .data-table td,
  .leads-table th,
  .leads-table td {
    white-space: nowrap;
  }

  .wa-inbox {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 40vh) minmax(0, 1fr);
    height: 100%;
  }

  #panel-wamessages.panel.active {
    height: calc(100vh - 180px);
  }
}

@media (max-width: 480px) {
  .kpi-grid,
  .team-summary-kpis,
  .report-kpi-grid {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 0.85rem;
  }

  .topbar h2 {
    font-size: 1.1rem;
  }

  .topbar-actions {
    width: 100%;
    margin-left: 0;
  }

  .topbar-actions .btn-secondary {
    width: 100%;
  }
}

@media print {
  .sidebar,
  .topbar,
  .reports-toolbar,
  .sidebar-backdrop {
    display: none !important;
  }
  .main {
    margin: 0 !important;
    padding: 0 !important;
  }
  .report-print-area {
    break-inside: avoid;
  }
}

/* Legacy pool import — column mapping modal */
.legacy-import-intro {
  margin: 0 0 12px;
}

.legacy-import-dropzone {
  border: 2px dashed var(--border, #d1d5db);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2, #f9fafb);
  transition: border-color 0.15s, background 0.15s;
}

.legacy-import-dropzone:hover,
.legacy-import-dropzone:focus-visible,
.legacy-import-dropzone.drag-over {
  border-color: var(--accent, #2563eb);
  background: #eff6ff;
}

.legacy-import-dropzone-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legacy-import-formats {
  font-size: 0.85rem;
}

.legacy-import-map-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.legacy-import-batch-field {
  flex: 1;
  min-width: 220px;
}

.legacy-import-batch-field input {
  width: 100%;
  margin-top: 4px;
}

.legacy-import-map-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.legacy-import-map-col h4 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.legacy-import-map-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
}

.legacy-import-db-fields,
.legacy-import-excel-cols {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}

.legacy-import-db-field {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.legacy-import-db-field.required .legacy-import-db-label::after {
  content: ' *';
  color: #dc2626;
}

.legacy-import-db-field.mapped {
  border-color: #86efac;
  background: #f0fdf4;
}

.legacy-import-db-field.drop-target {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.legacy-import-db-field.pick-target {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 1px;
}

.legacy-import-db-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.legacy-import-db-hint {
  font-size: 0.78rem;
  margin-top: 2px;
}

.legacy-import-db-mapped {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.legacy-import-mapped-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #dbeafe;
  font-size: 0.82rem;
}

.legacy-import-mapped-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #64748b;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

.legacy-import-excel-col {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  cursor: grab;
  user-select: none;
}

.legacy-import-excel-col:active {
  cursor: grabbing;
}

.legacy-import-excel-col.mapped-away {
  opacity: 0.45;
}

.legacy-import-excel-col.pick-target {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 1px;
}

.legacy-import-excel-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.legacy-import-excel-samples {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 4px;
  word-break: break-word;
}

.legacy-import-preview-wrap h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.legacy-import-preview {
  max-height: 180px;
  overflow: auto;
}

.campaign-import-assign-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border, #e5e7eb);
}

.campaign-import-assign-wrap h4 {
  margin: 0 0 6px;
}

.campaign-import-assign-row {
  margin: 10px 0;
}

.campaign-folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.campaign-folder-card {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.campaign-folder-card:hover {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.campaign-folder-card h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.campaign-folder-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.85rem;
}

.campaign-folder-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.campaign-folder-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 4px;
}

.campaign-folder-kpi {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-2, #f9fafb);
  border: 1px solid var(--border, #e5e7eb);
  min-width: 100px;
}

.campaign-folder-kpi-btn {
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.campaign-folder-kpi-btn:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.campaign-folder-kpi-btn.campaign-folder-kpi-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.campaign-folder-kpi-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.campaign-folder-kpi strong {
  display: block;
  font-size: 1.25rem;
}

.leads-table-wrap .notes-cell {
  max-width: 240px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  color: var(--text);
}

.campaign-folder-leads-table .notes-cell {
  max-width: 220px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
}

@media (max-width: 768px) {
  .legacy-import-map-grid {
    grid-template-columns: 1fr;
  }
}

.mt-agent-list {
  max-height: 280px;
  overflow: auto;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
}

.mt-agent-list .project-check {
  padding: 0.35rem 0.25rem;
}

#manager-team-section .data-table td {
  vertical-align: top;
}

#manager-team-section .mt-members {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: 420px;
}

#manager-team-section .mt-chip {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
  background: var(--surface2, #f3f4f6);
  border-radius: 999px;
  color: var(--text);
}

/* Any card hosting a searchable agent combo must not clip its popup menu, which
   is positioned absolutely and extends below the card's own box (.card sets
   overflow:hidden, which otherwise clips the "Revert mistaken assignments" and
   similar agent-picker dropdowns to almost nothing). */
.card:has(.combo-menu),
.legacy-pool-revert-bar.card {
  overflow: visible;
}
