:root {
  --bg: #0a0e13;
  --panel: #121820;
  --panel-2: #0d1218;
  --panel-hover: #161d27;
  --border: #212a35;
  --border-soft: #1a222c;
  --text: #e7edf3;
  --muted: #8b97a6;
  --faint: #5c6774;
  --wa: #25d366;
  --meta: #2078f4;
  --amber: #f2a93b;
  --won: #34d399;
  --lost: #f2545b;
  --radius: 14px;
  --shadow: 0 24px 70px rgba(0, 0, 0, .36);
}

* {
  box-sizing: border-box;
  min-width: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% -8%, rgba(32, 120, 244, .19), transparent 30%),
    radial-gradient(circle at 96% 2%, rgba(37, 211, 102, .13), transparent 28%),
    var(--bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}

button, input, select {
  min-width: 0;
  font: inherit;
}
button { cursor: pointer; border: 0; }
html { scroll-behavior: smooth; }
html, body { overflow-x: hidden; }

.app {
  width: min(1160px, 100%);
  max-width: 100vw;
  margin: 0 auto;
  padding: 22px 16px 44px;
}

.topbar, .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar { margin-bottom: 16px; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.install-btn {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(37, 211, 102, .46);
  border-radius: 999px;
  color: var(--wa);
  background: rgba(37, 211, 102, .08);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.install-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(37, 211, 102, .30);
  border-radius: 12px;
  color: var(--text);
  background: rgba(37, 211, 102, .08);
}

.install-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.install-card button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  font-weight: 700;
}

.install-card.hidden { display: none; }

.api-alert {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  padding: 13px 14px;
  border: 1px solid rgba(242, 169, 59, .34);
  border-radius: 12px;
  background: rgba(242, 169, 59, .10);
}

.api-alert strong,
.api-alert span {
  display: block;
}

.api-alert span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.api-alert-actions {
  display: flex;
  gap: 8px;
}

.api-alert a,
.api-alert button {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.api-alert a {
  color: #061009;
  background: var(--amber);
}

.api-alert.hidden { display: none; }

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(37, 211, 102, .48);
  border-radius: 10px;
  color: var(--wa);
  background: rgba(37, 211, 102, .08);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
}

.brand strong, h1, h2, h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

.brand span, .section-head span, footer {
  color: var(--faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(18, 24, 32, .86);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wa);
  box-shadow: 0 0 0 4px rgba(37, 211, 102, .12);
}

.panel, .hero {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(18, 24, 32, .92);
  box-shadow: var(--shadow);
}

.access-panel {
  display: grid;
  grid-template-columns: .9fr 1.5fr;
  gap: 16px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
}

.access-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.hero {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 20px;
  align-items: center;
  min-height: 230px;
  padding: 26px;
  margin-bottom: 16px;
  background:
    linear-gradient(140deg, rgba(32, 120, 244, .10), transparent 38%),
    linear-gradient(180deg, #101820 0%, #0b1016 100%);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1 {
  max-width: 620px;
  font-size: clamp(32px, 5vw, 62px);
  line-height: .98;
  letter-spacing: 0;
}

.hero p:last-child {
  max-width: 560px;
  color: var(--muted);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.signal-flow {
  display: grid;
  grid-template-columns: 72px 1fr 72px 1fr 72px;
  align-items: center;
  min-height: 112px;
}

.node {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
}

.node.wa { color: var(--wa); border-color: rgba(37, 211, 102, .55); }
.node.sheet { color: var(--amber); border-color: rgba(242, 169, 59, .50); }
.node.meta { color: var(--meta); border-color: rgba(32, 120, 244, .55); }
.line { height: 1px; background: linear-gradient(90deg, var(--border), rgba(37, 211, 102, .56)); }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  min-height: 116px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(18, 24, 32, .90);
}

.kpi span {
  color: var(--faint);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 30px;
}

.grid {
  display: grid;
  grid-template-columns: .92fr 1.08fr;
  gap: 16px;
  margin-bottom: 16px;
}

.admin-panel, .form-panel, .leads-panel, .panel:not(.access-panel) { padding: 16px; }

.accordion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;
  padding: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  font-weight: 700;
}

.accordion small {
  color: var(--muted);
  font-weight: 500;
}

.accordion-body {
  display: none;
  padding-top: 8px;
}

.accordion-body.open { display: grid; gap: 10px; }

.meta-state {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.meta-state div {
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
}

.meta-state small, label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meta-state strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 14px;
}

label { display: grid; gap: 7px; }

input, select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: #0b1016;
}

input:focus, select:focus {
  border-color: rgba(32, 120, 244, .78);
  box-shadow: 0 0 0 3px rgba(32, 120, 244, .12);
}

.lead-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.cs-row { grid-column: 1 / -1; }

.btn {
  min-height: 40px;
  padding: 0 15px;
  border-radius: 10px;
  color: var(--text);
  background: #202832;
  font-weight: 800;
}

.btn.primary {
  color: #061009;
  background: var(--wa);
}

.btn:disabled,
.lead-form.is-saving .btn.primary {
  cursor: wait;
  opacity: .72;
  box-shadow: none;
}

.performance {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.cs-card, .lead-card {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: rgba(13, 18, 24, .88);
}

.cs-card {
  padding: 14px;
}

.cs-card strong, .lead-title strong { font-size: 16px; }
.cs-card .numbers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.numbers div {
  padding: 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .035);
}

.numbers small { display: block; color: var(--faint); }

.filters {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

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

.chip {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.chip.active {
  color: #061009;
  background: var(--wa);
  border-color: var(--wa);
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.filter-grid label {
  gap: 6px;
}

.reset-btn {
  min-width: 72px;
  color: var(--text);
}

.leads {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.lead-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 12px;
  padding: 12px;
  transition: background .18s ease, border-color .18s ease;
}

.lead-card:hover {
  border-color: #263443;
  background: rgba(13, 18, 24, .98);
}

.lead-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.badge {
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--wa);
  background: rgba(37, 211, 102, .12);
  font-size: 11px;
  font-weight: 800;
}

.badge.Deal { color: var(--wa); background: rgba(37, 211, 102, .13); }
.badge.Hot { color: var(--amber); background: rgba(242, 169, 59, .12); }
.badge.Lost { color: var(--lost); background: rgba(242, 84, 91, .12); }

.lead-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.lead-sub {
  margin-top: 10px;
  color: var(--faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.lead-actions {
  display: grid;
  gap: 8px;
  align-content: start;
}

.lead-actions a,
.lead-actions .btn {
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.lead-actions a {
  color: #061009;
  background: var(--wa);
}

.lead-actions .btn {
  color: var(--text);
  background: #202832;
}

footer {
  margin-top: 18px;
  padding-bottom: 76px;
  text-align: center;
}

.mobile-nav {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 40;
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(33, 42, 53, .95);
  border-radius: 18px;
  background: rgba(13, 18, 24, .92);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .45);
  backdrop-filter: blur(16px);
}

.mobile-nav a {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .04);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.mobile-nav a:nth-child(2) {
  color: #061009;
  background: var(--wa);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: none;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: #121820;
  box-shadow: var(--shadow);
}

.toast.show { display: block; }

@media (max-width: 860px) {
  .access-panel, .hero, .grid, .lead-card { grid-template-columns: 1fr; }
  .access-grid, .kpis, .performance, .lead-form, .filter-grid { grid-template-columns: 1fr; }
  h1 { font-size: 38px; }
  .signal-flow { grid-template-columns: 58px 1fr 58px 1fr 58px; }
  .node { width: 58px; height: 58px; }
}

@media (max-width: 640px) {
  body {
    background:
      radial-gradient(circle at 0% -10%, rgba(32, 120, 244, .18), transparent 28%),
      var(--bg);
  }

  .app {
    padding: 12px 10px 92px;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: -12px -10px 10px;
    padding: 10px;
    background: rgba(10, 14, 19, .92);
    backdrop-filter: blur(14px);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    max-width: 145px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }

  .brand span {
    display: none;
  }

  .install-btn {
    min-height: 32px;
    padding: 0 10px;
    font-size: 11px;
  }

  .role-pill {
    display: none;
  }

  .top-actions {
    flex: 0 0 auto;
  }

  .install-card {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 11px;
  }

  .api-alert {
    grid-template-columns: 1fr;
    padding: 11px;
  }

  .api-alert-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .install-card span {
    width: 100%;
    font-size: 12px;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .install-card button {
    width: 100%;
  }

  .access-panel,
  .hero,
  .admin-panel,
  .form-panel,
  .panel:not(.access-panel) {
    border-radius: 12px;
    box-shadow: none;
  }

  .access-panel {
    padding: 14px;
  }

  .access-panel h2 {
    font-size: 22px;
  }

  .hero {
    min-height: auto;
    padding: 18px;
    overflow: hidden;
  }

  h1 {
    max-width: 100%;
    font-size: 31px;
    line-height: 1.02;
    overflow-wrap: anywhere;
  }

  .hero p:last-child {
    width: 100%;
    font-size: 14px;
    line-height: 1.6;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .signal-flow {
    min-height: 70px;
    grid-template-columns: 48px minmax(28px, 1fr) 48px minmax(28px, 1fr) 48px;
  }

  .node {
    width: 48px;
    height: 48px;
    font-size: 12px;
  }

  .kpis {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .kpi {
    min-height: 92px;
    padding: 13px;
  }

  .kpi strong {
    font-size: 23px;
    overflow-wrap: anywhere;
  }

  .meta-state {
    grid-template-columns: 1fr;
  }

  input,
  select,
  .btn,
  .lead-actions a,
  .lead-actions .btn {
    min-height: 46px;
    border-radius: 11px;
  }

  .lead-form {
    gap: 10px;
  }

  .chips {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .chips::-webkit-scrollbar {
    display: none;
  }

  .chip {
    min-height: 34px;
  }

  .lead-card {
    gap: 12px;
    padding: 12px;
  }

  .lead-title {
    align-items: flex-start;
    justify-content: space-between;
  }

  .lead-title strong {
    font-size: 17px;
  }

  .lead-actions {
    grid-template-columns: 1fr 1fr;
  }

  .lead-actions select {
    grid-column: 1 / -1;
  }

  .lead-actions a {
    grid-column: 1 / -1;
  }

  .performance {
    grid-template-columns: 1fr;
  }

  .toast {
    right: 10px;
    bottom: 82px;
    left: 10px;
    max-width: none;
  }

  .mobile-nav {
    display: grid;
    left: 8px;
    right: 8px;
  }
}

@media (max-width: 390px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar {
    margin-left: -8px;
    margin-right: -8px;
  }

  .brand strong {
    max-width: 132px;
  }

  h1 {
    font-size: 29px;
  }

  .kpi strong {
    font-size: 20px;
  }

  .kpis {
    gap: 8px;
  }

  .kpi {
    padding: 11px;
  }
}
