:root {
  --fb: #1877f2;
  --fb-dark: #166fe5;
  --fb-soft: #e7f0fe;
  --bg: #eef1f6;
  --bg-2: #f6f8fb;
  --card: #ffffff;
  --text: #0f1419;
  --muted: #5b6470;
  --border: #e3e7ee;
  --border-strong: #d4dae3;
  --danger: #d93025;
  --ok: #137333;
  --ok-bg: #e6f4ea;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 240px);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Top bar ------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--fb), #0b5fd0);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  box-shadow: 0 2px 8px rgba(24, 119, 242, 0.35);
}

.brand-mark-sm {
  width: 24px;
  height: 24px;
  font-size: 13px;
  border-radius: 7px;
}

.brand-name {
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-tag {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* ---- Layout -------------------------------------------------------- */
.app {
  width: 100%;
  margin: 0 auto;
  padding: 40px 20px 64px;
  flex: 1;
}

.app-header {
  margin-bottom: 24px;
}

.app-header h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.app-main {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

/* ---- Connect screen ------------------------------------------------ */
.connect-screen {
  text-align: center;
  padding: 24px 0 8px;
}

.connect-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--fb), #0b5fd0);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 15px 26px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(24, 119, 242, 0.32);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

.connect-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(24, 119, 242, 0.4);
}

.fb-mark {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  background: #fff;
  color: var(--fb);
  border-radius: 50%;
  font-weight: 800;
  font-family: Georgia, serif;
}

.hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

/* ---- Error --------------------------------------------------------- */
.error-card {
  text-align: center;
  border: 1px solid #f5c2c0;
  background: #fdecea;
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin-bottom: 24px;
}

.error-card h3 {
  margin: 0 0 8px;
  color: var(--danger);
}

.error-card p {
  margin: 0;
  color: #7a1c16;
}

.retry-btn,
.logout-btn {
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  color: var(--text);
  display: inline-block;
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
}

.retry-btn:hover,
.logout-btn:hover {
  background: var(--bg-2);
  border-color: var(--fb);
}

.logout-form {
  margin: 0;
}

/* ---- Dashboard ----------------------------------------------------- */
.user-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.user-id {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--fb), #0b5fd0);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-meta strong {
  font-size: 16px;
}

.user-meta span {
  color: var(--muted);
  font-size: 14px;
}

.dashboard h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.count {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85em;
}

.business-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.business-card {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  transition:
    transform 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}

.business-card:hover {
  transform: translateY(-2px);
  border-color: var(--fb);
  box-shadow: 0 8px 22px rgba(24, 119, 242, 0.14);
}

.business-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--fb), #0b5fd0);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}

.business-info {
  min-width: 0;
  flex: 1;
}

.business-info h4 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.business-info code {
  color: var(--muted);
  font-size: 12px;
}

.business-chevron {
  margin-left: auto;
  font-size: 26px;
  color: var(--border-strong);
  transition:
    color 0.12s ease,
    transform 0.12s ease;
}

.business-card:hover .business-chevron {
  color: var(--fb);
  transform: translateX(2px);
}

.business-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 2px;
}

.business-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.01em;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge-muted {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.empty {
  color: var(--muted);
  background: var(--bg-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 4px;
  font-size: 14px;
}

/* ---- Business detail page ----------------------------------------- */
.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--fb);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.back-link:hover {
  text-decoration: underline;
}

.detail-section {
  margin-bottom: 32px;
}

.detail-section:last-child {
  margin-bottom: 0;
}

.detail-section h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.field-list {
  margin: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.field-row:last-child {
  border-bottom: none;
}

.field-row dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.field-row dd {
  margin: 0;
  word-break: break-word;
}

.profile-pic {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
}

.thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
  vertical-align: middle;
}

.json {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
}

/* ---- Tables -------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.edge-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.edge-table th,
.edge-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

.edge-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--bg-2);
  position: sticky;
  top: 0;
}

.edge-table tbody tr:hover {
  background: var(--fb-soft);
}

/* ---- Tabs ---------------------------------------------------------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 28px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: var(--fb);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.tab-badge {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.tab.is-active .tab-badge {
  background: var(--fb);
  color: #fff;
}

.tab-panel {
  display: none;
  animation: fade-in 0.18s ease;
}

.tab-panel.is-active {
  display: block;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.edge-block {
  margin-bottom: 28px;
}

.edge-block h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ---- Nested ads / leads cards ------------------------------------- */
.subcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  margin-bottom: 16px;
  background: var(--bg-2);
}

.subcard h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.subcard h3 code,
.field-row code {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.subcard h4 {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 4px 0 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  min-width: 96px;
}

.stat-val {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Collapsible lead-gen form (keeps the Leads tab short) */
.lead-form {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  margin-bottom: 10px;
  overflow: hidden;
}

.lead-form > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
  user-select: none;
}

.lead-form > summary::-webkit-details-marker {
  display: none;
}

.lead-form > summary::before {
  content: "\25B8"; /* ▸ */
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}

.lead-form[open] > summary::before {
  transform: rotate(90deg);
}

.lead-form > summary:hover {
  background: var(--bg-2);
}

.lead-form > summary .count {
  margin-left: auto;
  background: var(--bg);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}

.lead-form-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-form-body {
  padding: 0 14px 14px;
}

.lead {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--card);
}

.lead-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.lead-head code {
  font-size: 12px;
  color: var(--muted);
}

.lead-time {
  font-size: 12px;
  color: var(--muted);
}

.lead .field-row {
  grid-template-columns: 160px 1fr;
  padding: 6px 0;
}

/* ---- Legal / content pages ---------------------------------------- */
.page {
  width: 100%;
  max-width: 760px;
  margin: 40px auto 0;
  padding: 40px;
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.page h2 {
  font-size: 1.15rem;
  margin-top: 2rem;
}

.page ol,
.page ul {
  padding-left: 1.2rem;
}

.updated {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0;
}

/* ---- Site footer --------------------------------------------------- */
.site-footer {
  margin-top: auto;
  background: var(--card);
  border-top: 1px solid var(--border);
}

.site-footer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
}

.site-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.site-footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.site-footer-links a:hover {
  color: var(--fb);
}

.site-footer-copy {
  margin: 0;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Responsive ---------------------------------------------------- */
@media (max-width: 640px) {
  .app-main,
  .page {
    padding: 22px;
  }

  .app-header h1 {
    font-size: 24px;
  }

  .field-row,
  .lead .field-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .brand-tag {
    display: none;
  }

  .site-footer-copy {
    margin-left: 0;
    width: 100%;
  }
}
