/* Logleads — local CRM UI (system fonts only, no CDN) */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #d5dbe5;
  --text: #1a2332;
  --text-muted: #5c6778;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --warning: #b45309;
  --focus: #2563eb;
  --shadow: 0 1px 3px rgba(26, 35, 50, 0.08), 0 4px 12px rgba(26, 35, 50, 0.06);
  --radius: 8px;
  --nav-width: 220px;
  --panel-width: min(420px, 100vw);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10000;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* Scan progress bar */
.scan-bar {
  position: sticky;
  top: 0;
  z-index: 900;
  background: #1e293b;
  color: #e2e8f0;
  border-bottom: 1px solid #334155;
  font-size: 0.875rem;
}

.scan-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.5rem 1.25rem;
  max-width: 1600px;
  margin: 0 auto;
}

.scan-bar-state {
  font-weight: 600;
  text-transform: capitalize;
}

.scan-activity {
  flex: 1 1 16rem;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.5rem 0 1rem;
}

.category-picks label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.csv-upload {
  position: relative;
  overflow: hidden;
}

.csv-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.scan-bar-counters {
  flex: 1;
  min-width: 12rem;
  color: #94a3b8;
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.scan-bar-actions {
  display: flex;
  gap: 0.5rem;
}

.scan-bar .btn-secondary {
  background: #334155;
  color: #f1f5f9;
  border-color: #475569;
}

.scan-bar .btn-secondary:hover {
  background: #475569;
}

/* App shell */
.app-shell {
  display: flex;
  min-height: calc(100vh - var(--scan-bar-offset, 0px));
}

.side-nav {
  width: var(--nav-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.brand-name {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-link {
  display: block;
  padding: 0.625rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-link[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.75rem 2rem;
  max-width: 1400px;
}

.view {
  animation: fade-in 0.15s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #fecaca;
}

.btn-secondary {
  background: var(--surface-2);
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Forms */
.field {
  margin-bottom: 1rem;
}

.field label,
.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

input[type="text"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.625rem;
  font: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input {
  width: auto;
}

/* Search & filters */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.search-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.search-field {
  flex: 1;
  min-width: 14rem;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}

.chips-row:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem 0.25rem 0.625rem;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.chip-remove {
  border: none;
  background: transparent;
  padding: 0 0.125rem;
  cursor: pointer;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  border-radius: 4px;
}

.chip-remove:hover {
  background: rgba(37, 99, 235, 0.15);
}

.result-count {
  margin-left: auto;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.filter-selects {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
}

.data-table th.sortable:hover {
  background: #e2e8f0;
}

.data-table th .sort-indicator {
  opacity: 0.35;
  margin-left: 0.25rem;
}

.data-table th[aria-sort="ascending"] .sort-indicator,
.data-table th[aria-sort="descending"] .sort-indicator {
  opacity: 1;
  color: var(--accent);
}

.data-table tbody tr.lead-row {
  cursor: pointer;
}

.data-table tbody tr.lead-row:hover {
  background: #f8fafc;
}

.data-table tbody tr.lead-row:focus-within {
  background: var(--accent-soft);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.col-check {
  width: 2.5rem;
  text-align: center;
}

.cell-muted {
  color: var(--text-muted);
}

.status-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
}

.status-badge[data-status="Valid"],
.status-badge[data-status="Reviewed"] {
  background: #dcfce7;
  color: var(--success);
}

.status-badge[data-status="Invalid"],
.status-badge[data-status="Do Not Contact"],
.status-badge[data-status="Suppressed"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-badge[data-status="Manual Review"],
.status-badge[data-status="New"] {
  background: #fef3c7;
  color: var(--warning);
}

.phone-badge[data-state="valid_mobile"],
.phone-badge[data-state="valid_fixed_line"] {
  color: var(--success);
}

.phone-badge[data-state="invalid"],
.phone-badge[data-state="country_mismatch"] {
  color: var(--danger);
}

/* Empty states */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state h3 {
  margin: 0 0 0.5rem;
  color: var(--text);
  font-size: 1.125rem;
}

.empty-state p {
  margin: 0 0 1rem;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
}

/* Pagination */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}

.pagination-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Lead panel */
.lead-panel {
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
}

.lead-panel:not([hidden]) {
  pointer-events: auto;
}

.lead-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.lead-panel:not([hidden]) .lead-panel-backdrop {
  opacity: 1;
}

.lead-panel-sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-width);
  max-width: 100%;
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.lead-panel:not([hidden]) .lead-panel-sheet {
  transform: translateX(0);
}

.lead-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.lead-panel-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 0.5rem;
}

.lead-panel-body {
  flex: 1;
  overflow: auto;
  padding: 1.25rem;
}

.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.detail-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.375rem 1rem;
  margin: 0;
  font-size: 0.9375rem;
}

.detail-dl dt {
  color: var(--text-muted);
  font-weight: 500;
}

.detail-dl dd {
  margin: 0;
  word-break: break-word;
}

.source-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  background: var(--surface-2);
}

.source-card:last-child {
  margin-bottom: 0;
}

/* Scan view */
.scan-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.scan-section h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 700;
}

.scan-section .section-desc {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.token-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 2.5rem;
  align-items: center;
}

.token-input-wrap:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 0;
}

.token-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 0.8125rem;
}

.token-chip button {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  color: var(--text-muted);
}

.token-inline-input {
  flex: 1;
  min-width: 8rem;
  border: none;
  outline: none;
  padding: 0.25rem;
  font: inherit;
  font-size: 0.875rem;
  background: transparent;
}

.category-block {
  margin-bottom: 1rem;
}

.category-block:last-child {
  margin-bottom: 0;
}

.category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.category-head h3 {
  margin: 0;
  font-size: 0.9375rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.stat-card .stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
}

.settings-details {
  margin-top: 1rem;
}

.settings-details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem 0;
}

/* Duplicates */
.dup-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.dup-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.dup-group-header {
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.dup-group-body {
  padding: 0.5rem;
}

.dup-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.dup-option:hover {
  background: var(--surface-2);
}

.dup-option input {
  margin-top: 0.25rem;
}

.dup-option-main {
  flex: 1;
  min-width: 0;
}

.dup-merge-actions {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Modal */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 28rem;
  width: 100%;
  padding: 1.25rem;
}

.modal-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.125rem;
}

.modal-card p {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Toast */
.toast-region {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 22rem;
}

.toast {
  padding: 0.75rem 1rem;
  background: #1e293b;
  color: #f1f5f9;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast-error {
  background: var(--danger);
  color: #fff;
}

@keyframes toast-in {
  from {
    transform: translateY(0.5rem);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.loading-inline {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 2rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Responsive */
@media (max-width: 800px) {
  .app-shell {
    flex-direction: column;
  }

  .side-nav {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    padding: 0;
    border: none;
    margin: 0;
    margin-right: 1rem;
  }

  .nav-list {
    display: flex;
    gap: 0.25rem;
  }

  .nav-link {
    padding: 0.5rem 0.75rem;
    border-left: none;
    border-radius: var(--radius);
  }

  .nav-link[aria-current="page"] {
    border-left: none;
  }

  .main-content {
    padding: 1rem;
  }

  .lead-panel-sheet {
    width: 100%;
  }

  .result-count {
    margin-left: 0;
    width: 100%;
  }

  .scan-bar-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .scan-bar-actions {
    justify-content: flex-end;
  }
}

@media (min-width: 1280px) {
  .main-content {
    padding: 1.75rem 2rem 2.5rem;
  }
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: #0f1419;
}

.login-screen.hidden { display: none; }

.login-card {
  width: min(22rem, calc(100% - 2rem));
  display: grid;
  gap: 0.6rem;
  padding: 1.5rem;
  background: #1a222b;
  color: #f4f7fb;
  border-radius: 12px;
}

.login-card input {
  width: 100%;
  padding: 0.55rem 0.7rem;
}

.login-error { min-height: 1.2rem; color: #ffb4a8; }

body[data-role="reviewer"] #start-scan-btn,
body[data-role="reviewer"] #extract-phones-btn,
body[data-role="reviewer"] #sort-country-btn,
body[data-role="reviewer"] #sort-cancel-btn,
body[data-role="reviewer"] #pick-paths-btn,
body[data-role="reviewer"] [data-save-config-only],
body[data-role="reviewer"] #scan-pause-btn,
body[data-role="reviewer"] #scan-resume-btn,
body[data-role="reviewer"] #scan-cancel-btn,
body[data-role="reviewer"] #user-admin {
  display: none !important;
}

.side-nav #logout-btn { margin: 1rem; }
