/* Customer profile (customers#show). Reuses the Visão Geral frame:
   masthead → joined KPI tiles → cards. Activity on the left, the record on the right. */
@scope (.customer-profile) {
  :scope {
    --_surface: var(--color-surface);
    --_border: var(--color-border-muted);
    --_ink: var(--color-text-heading);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    /* An inline-size container cannot shrink-to-fit: without an explicit width
       the auto-margined .record-page collapses to zero. */
    inline-size: 100%;
    max-inline-size: 80rem;
    container: profile / inline-size;
  }

  :scope > * {
    min-inline-size: 0;
  }

  /* ── Masthead ── */
  .customer-profile__masthead {
    padding-block-end: var(--space-lg);
    border-bottom: 1px solid var(--_border);
  }

  .customer-profile__eyebrow {
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-widest);
    text-transform: uppercase;
  }

  .customer-profile__title {
    margin-top: var(--space-xs);
    color: var(--_ink);
    font-size: clamp(var(--text-heading-2), 3vw, var(--text-heading-1));
    font-weight: var(--font-semibold);
    overflow-wrap: anywhere;
  }

  .customer-profile__thesis {
    margin-top: var(--space-sm);
    color: var(--color-text-secondary);
  }

  .customer-profile__quick {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-md);
  }

  .customer-profile__chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-inline-size: 0;
    padding: var(--space-xs) var(--space-md);
    border: 1px solid var(--_border);
    border-radius: var(--radius-full);
    background: var(--_surface);
    color: var(--color-text);
    font-size: var(--text-sm);
    text-decoration: none;
    overflow-wrap: anywhere;

    &:hover {
      border-color: var(--color-primary);
      color: var(--color-primary);
    }

    .icon {
      flex-shrink: 0;
      inline-size: 1rem;
      block-size: 1rem;
    }
  }

  /* ── KPI tiles: 1px gap over the border color draws the dividers ── */
  .customer-profile__metrics {
    display: grid;
    overflow: hidden;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    border: 1px solid var(--_border);
    border-radius: var(--radius-xl);
    background: var(--_border);
    box-shadow: var(--shadow-xs);
  }

  @container profile (width >= 44rem) {
    .customer-profile__metrics {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  .customer-profile__metric {
    display: grid;
    align-content: start;
    gap: var(--space-xs);
    min-inline-size: 0;
    padding: var(--space-lg);
    background: var(--_surface);
  }

  .customer-profile__metric--lead {
    background: linear-gradient(var(--color-primary-muted), var(--color-primary-muted)), var(--_surface);
  }

  .customer-profile__metric-label {
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-widest);
    text-transform: uppercase;
  }

  .customer-profile__metric-value {
    color: var(--_ink);
    font-family: var(--font-mono);
    font-size: var(--text-heading-3);
    font-variant-numeric: tabular-nums;
    font-weight: var(--font-semibold);
  }

  .customer-profile__metric-note {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  /* ── Layout ── */
  .customer-profile__layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-xl);
    align-items: start;
  }

  @container profile (width >= 60rem) {
    .customer-profile__layout {
      grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
    }

    .customer-profile__aside {
      position: sticky;
      top: var(--space-lg);
    }
  }

  .customer-profile__main,
  .customer-profile__aside {
    display: grid;
    gap: var(--space-lg);
    min-inline-size: 0;
  }

  /* ── Cards ── */
  .customer-profile__card {
    display: grid;
    gap: var(--space-md);
    min-inline-size: 0;
    padding: var(--space-lg);
    border: 1px solid var(--_border);
    border-radius: var(--radius-xl);
    background: var(--_surface);
    box-shadow: var(--shadow-xs);
  }

  .customer-profile__card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    justify-content: space-between;
    gap: var(--space-md);
  }

  .customer-profile__card-title {
    color: var(--_ink);
    font-size: var(--text-heading-5);
    font-weight: var(--font-semibold);
  }

  .customer-profile__card-hint {
    margin-top: var(--space-2xs);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .customer-profile__empty {
    padding-block: var(--space-md);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  /* ── Activity rows (leads, quotes) ── */
  .customer-profile__rows {
    display: grid;
    margin-inline: calc(var(--space-lg) * -1);
    border-top: 1px solid var(--_border);
    list-style: none;

    > li + li {
      border-top: 1px solid var(--_border);
    }
  }

  .customer-profile__row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2xs) var(--space-md);
    padding: var(--space-md) var(--space-lg);
    color: var(--color-text);
    text-decoration: none;

    &:hover {
      background: var(--color-surface-muted);

      .customer-profile__row-chevron {
        color: var(--color-primary);
      }
    }
  }

  @container profile (width >= 36rem) {
    .customer-profile__row {
      grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto auto;
    }
  }

  .customer-profile__row-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    min-inline-size: 0;
  }

  .customer-profile__row-number {
    color: var(--_ink);
    font-family: var(--font-mono);
    font-weight: var(--font-semibold);
  }

  .customer-profile__row-meta {
    min-inline-size: 0;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .customer-profile__row-date {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  .customer-profile__row-chevron {
    inline-size: 1rem;
    block-size: 1rem;
    color: var(--color-text-muted);
  }

  .customer-profile__more {
    justify-self: start;
    color: var(--color-primary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
  }

  /* ── Readouts: uppercase label over value, no boxes ── */
  .customer-profile__readouts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-md);

    > div {
      display: grid;
      gap: var(--space-2xs);
      min-inline-size: 0;
    }

    dt {
      color: var(--color-text-secondary);
      font-size: var(--text-xs);
      font-weight: var(--font-bold);
      letter-spacing: var(--tracking-wide);
      text-transform: uppercase;
    }

    dd {
      color: var(--_ink);
      font-size: var(--text-sm);
      overflow-wrap: anywhere;
    }
  }

  .customer-profile__readout--full {
    grid-column: 1 / -1;
  }

  .customer-profile__mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

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

  .customer-profile__address {
    display: grid;
    gap: var(--space-2xs);
    font-size: var(--text-sm);

    & + & {
      padding-top: var(--space-md);
      border-top: 1px solid var(--_border);
    }

    h3 {
      color: var(--_ink);
      font-size: var(--text-sm);
      font-weight: var(--font-semibold);
    }
  }

  .customer-profile__notes {
    color: var(--color-text);
    font-size: var(--text-sm);
  }

  /* Nudge to fill the sections that are still empty, instead of empty cards. */
  .customer-profile__missing {
    display: grid;
    gap: var(--space-2xs);
    padding: var(--space-md) var(--space-lg);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-xl);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    text-decoration: none;

    &:hover {
      border-color: var(--color-primary);
      color: var(--color-primary);
    }
  }

  .customer-profile__missing-label {
    color: var(--color-primary);
    font-weight: var(--font-semibold);
  }

  .customer-profile__card--notes {
    padding: var(--space-lg);
  }
}

/* Hover feedback is a background, never an underline. */
@scope (.customer-profile) {
  a:is(.customer-profile__row, .customer-profile__chip, .customer-profile__missing, .customer-profile__more),
  a:is(.customer-profile__row, .customer-profile__chip, .customer-profile__missing, .customer-profile__more):hover {
    text-decoration: none;
  }

  .customer-profile__chip:hover {
    border-color: var(--_border);
    background: var(--color-surface-muted);
    color: var(--color-text);
  }

  .customer-profile__missing:hover {
    border-color: var(--color-border);
    background: var(--color-primary-muted);
    color: var(--color-text-secondary);
  }

  .customer-profile__more {
    padding: var(--space-xs) var(--space-sm);
    margin-inline-start: calc(var(--space-sm) * -1);
    border-radius: var(--radius-md);

    &:hover {
      background: var(--color-primary-muted);
    }
  }

  /* Phone: stage + date on the left, origin above the chevron on the right. */
  @container profile (width < 36rem) {
    .customer-profile__row {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: "main meta" "date chevron";
    }

    .customer-profile__row-main { grid-area: main; }
    .customer-profile__row-meta { grid-area: meta; justify-self: end; }
    .customer-profile__row-date { grid-area: date; }
    .customer-profile__row-chevron { grid-area: chevron; justify-self: end; }
  }
}
