html {
  scroll-padding-top: 96px;
}

.referral-page {
  background:
    linear-gradient(180deg, rgba(240, 246, 242, 0.92), rgba(248, 245, 238, 0.98)),
    var(--paper);
  overflow-x: hidden;
}

.referral-shell {
  padding-top: 86px;
  overflow-x: hidden;
}

.referral-hero {
  background:
    linear-gradient(135deg, rgba(32, 61, 52, 0.99), rgba(62, 109, 129, 0.68)),
    var(--forest);
}

.referral-workspace {
  display: grid;
  gap: 20px;
  min-width: 0;
  scroll-margin-top: 92px;
  padding: clamp(28px, 5vw, 72px);
}

.referral-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.56fr);
  gap: clamp(18px, 4vw, 42px);
  align-items: end;
}

.referral-header h2,
.referral-workspace h2 {
  max-width: 1040px;
  margin: 0;
  color: var(--forest);
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.08;
}

.referral-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.referral-metrics article,
.origin-strip,
.origin-panel,
.referral-queue-panel,
.referral-detail-panel,
.origin-card,
.referral-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(23, 33, 31, 0.05);
}

.referral-metrics article {
  display: grid;
  gap: 7px;
  align-items: center;
  justify-items: center;
  min-width: 0;
  padding: 16px 8px;
  text-align: center;
}

.referral-metrics span {
  display: block;
  color: var(--forest);
  font-size: clamp(1.18rem, 2.45vw, 2rem);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.referral-metrics p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  line-height: 1.1;
}

.origin-strip {
  display: flex;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.82);
}

.origin-strip::-webkit-scrollbar {
  display: none;
}

.origin-strip button {
  display: inline-flex;
  min-height: 38px;
  flex: 0 0 auto;
  align-items: center;
  border: 1px solid rgba(32, 61, 52, 0.14);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--forest);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 900;
}

.origin-strip button.is-active {
  border-color: var(--gold);
  color: #1e1707;
  background: var(--gold);
}

.referral-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.78fr) minmax(320px, 0.94fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.origin-panel,
.referral-queue-panel,
.referral-detail-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 18px;
}

.referral-detail-panel {
  position: sticky;
  top: 106px;
}

.panel-heading h3 {
  margin: 0;
  color: var(--forest);
  font-size: 1.28rem;
  line-height: 1.18;
}

.origin-list,
.referral-list {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.origin-card,
.referral-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 15px;
  text-align: left;
}

.origin-card {
  background: rgba(255, 255, 255, 0.72);
}

.referral-card {
  cursor: pointer;
  font: inherit;
}

.referral-card:hover,
.referral-card:focus-visible {
  border-color: rgba(32, 61, 52, 0.32);
  background: #fff;
  outline: none;
}

.referral-card.is-selected {
  border-color: rgba(214, 168, 79, 0.86);
  background:
    linear-gradient(135deg, rgba(255, 247, 231, 0.76), rgba(255, 255, 255, 0.96)),
    #fff;
}

.origin-card h4,
.referral-card h4,
.referral-detail-panel h3,
.detail-section h4 {
  margin: 0;
  color: var(--forest);
  line-height: 1.24;
}

.origin-card p,
.referral-card p,
.referral-detail-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.card-topline,
.referral-meta,
.detail-topline,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.origin-pill,
.status-pill,
.value-pill,
.consent-pill,
.channel-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
}

.origin-pill,
.channel-pill {
  color: var(--forest);
  background: rgba(111, 137, 119, 0.14);
}

.status-pill {
  color: #33423d;
  background: rgba(32, 61, 52, 0.08);
}

.value-pill {
  color: #755113;
  background: #fff7dc;
}

.consent-pill {
  color: #8f2f1e;
  background: #fff0e8;
}

.consent-pill.is-ready {
  color: #17423a;
  background: #e8f4ee;
}

.detail-section {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding-top: 14px;
  border-top: 1px solid rgba(32, 61, 52, 0.11);
}

.detail-section h4 {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.draft-box {
  display: grid;
  gap: 7px;
  border: 1px solid rgba(32, 61, 52, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}

.draft-box strong {
  color: var(--forest);
  font-size: 0.86rem;
}

.detail-actions button {
  min-height: 40px;
  border: 1px solid rgba(32, 61, 52, 0.2);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--forest);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 900;
}

.detail-actions button:first-child {
  border-color: var(--gold);
  color: #1e1707;
  background: var(--gold);
}

.detail-empty {
  display: grid;
  min-height: 280px;
  place-items: center;
  text-align: center;
}

.referral-phone .phone-review-list {
  padding-bottom: 4px;
}

.referral-phone .phone-review-card p {
  font-size: 0.76rem;
}

.referral-phone .phone-detail-draft {
  font-size: 0.78rem;
  line-height: 1.4;
}

@media (max-width: 1160px) {
  .referral-page .action-center-shell {
    grid-template-columns: 224px minmax(0, 1fr);
  }

  .referral-page .signal-sidebar nav {
    grid-template-columns: 1fr;
  }

  .referral-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .referral-detail-panel {
    position: static;
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .referral-header,
  .referral-layout {
    grid-template-columns: 1fr;
  }

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

  .referral-metrics article {
    min-height: 76px;
    padding: 12px 6px;
  }

  .referral-metrics span {
    font-size: clamp(1.05rem, 5.4vw, 1.5rem);
  }

  .referral-metrics p {
    font-size: clamp(0.64rem, 2.7vw, 0.74rem);
  }

  .origin-panel,
  .referral-queue-panel {
    overflow: hidden;
  }

  .origin-list,
  .referral-list {
    display: flex;
    gap: 12px;
    margin-inline: -18px;
    padding: 0 18px 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 18px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .origin-list::-webkit-scrollbar,
  .referral-list::-webkit-scrollbar {
    display: none;
  }

  .origin-card,
  .referral-card {
    flex: 0 0 min(78vw, 340px);
    scroll-snap-align: center;
    scroll-snap-stop: always;
  }
}
