:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e6ef;
  --text: #1c2333;
  --text-dim: #667085;
  --primary: #2451f5;
  --primary-dark: #1a3ecb;
  --accent-bg: #eef1ff;
  --danger: #d13438;
  --danger-bg: #fdecec;
  --success: #157a4a;
  --success-bg: #e9f8f0;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
}

.tabs-bar {
  border-top: 1px solid var(--border);
}

.tabs-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 24px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.brand h1 { font-size: 17px; margin: 0; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

.settings-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.settings-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: grid;
  gap: 8px;
  max-width: 520px;
}

.settings-inner label { font-weight: 600; font-size: 13px; }

.settings-inner input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.hint { font-size: 12px; color: var(--text-dim); margin: 0; }

.container {
  max-width: 1400px;
  margin: 24px auto;
  padding: 0 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.directory-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  align-items: start;
  gap: 20px;
}

/* main.js toggles tabs via the [hidden] attribute — since [hidden] and a
   class selector share the same specificity, the class rule above would
   otherwise win the cascade tie and defeat [hidden]. */
.directory-layout[hidden] { display: none; }

.directory-filters { position: sticky; top: 140px; }
.directory-filters .filters-grid { grid-template-columns: 1fr; }

.directory-results {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.name-search-card {
  padding: 14px 18px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.name-search-card .field:first-child { flex: 1 1 240px; }
.name-search-card .field:last-child { flex: 0 1 220px; }

@media (max-width: 860px) {
  .directory-layout { grid-template-columns: 1fr; }
  .directory-filters { position: static; }
}

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

.field input, .field select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.checkbox-field { justify-content: flex-end; }
.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.checkbox-field input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 81, 245, 0.12);
}

.filters-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.filters-note { flex-basis: 100%; margin-top: 4px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f1f3f9; }

.btn-small { padding: 6px 10px; font-size: 12px; }

.status-bar {
  font-size: 13px;
  color: var(--text-dim);
  min-height: 20px;
}

.status-bar .error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 500;
}

.table-card { padding: 0; overflow: hidden; }

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

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }

thead th {
  text-align: left;
  background: #fafbfd;
  color: var(--text-dim);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

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

tbody tr:hover { background: #fafbff; }

.enterprise-name { font-weight: 600; }

.muted { color: var(--text-dim); }

.address-cell { max-width: 260px; }

.empty-state, .loading-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 34, 0.35);
  z-index: 20;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(15, 20, 34, 0.08);
}

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

.side-panel-header h2 { font-size: 15px; margin: 0; }

.side-panel-body { padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }

.side-panel-body input[type="text"],
.side-panel-body input[type="email"],
.side-panel-body input[type="datetime-local"],
.side-panel-body input:not([type]),
.side-panel-body select,
.side-panel-body textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.side-panel-body input:focus,
.side-panel-body select:focus,
.side-panel-body textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 81, 245, 0.12);
}

.checklist { display: flex; flex-direction: column; gap: 8px; }
.checklist-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checklist-item input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }

.timeline { display: flex; flex-direction: column; gap: 10px; max-height: 220px; overflow-y: auto; }
.timeline-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.timeline-meta { color: var(--text-dim); margin-bottom: 2px; }
.timeline-body { color: var(--text); }

.enrich-field { display: flex; flex-direction: column; gap: 3px; }
.enrich-field .label { font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-dim); }
.enrich-field .value { font-size: 14px; }
.enrich-field .value a { word-break: break-all; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-high { background: var(--success-bg); color: var(--success); }
.badge-medium { background: #fff6e0; color: #8a6100; }
.badge-low { background: var(--danger-bg); color: var(--danger); }

.badge-new { background: var(--accent-bg); color: var(--primary); }
.badge-contacted { background: #fff6e0; color: #8a6100; }
.badge-qualified { background: var(--success-bg); color: var(--success); }
.badge-unqualified { background: #f1f3f9; color: var(--text-dim); }
.badge-won { background: var(--success-bg); color: var(--success); }
.badge-lost { background: var(--danger-bg); color: var(--danger); }

.tabs { display: flex; gap: 6px; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}
.tab-btn:hover { background: #f1f3f9; }
.tab-btn.active { background: var(--accent-bg); color: var(--primary); }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 30px auto;
}

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

.enrich-disclaimer {
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.sources { display: flex; flex-direction: column; gap: 4px; }
.sources a { font-size: 12px; }

.overlay[hidden], .side-panel[hidden] { display: none; }
