/* Customer page — the same spot for every customer. Roomier than the app's default rhythm:
   the spacing tokens are overridden on the page's root so the shared section
   pattern picks them up unchanged; the side padding is the app's. */

@layer components {
  .customer-page {
    --section-gap: 26px;
    --section-label-gap: 12px;
    --row-padding: 12px;
    --customer-ring: 88px;
    --customer-cell-gap: 5px;
  }

  /* Header: the name big and centred, the three fixed actions spaced evenly under it. */
  .customer-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 4px var(--content-padding) 24px;
    overflow: hidden;
  }

  .customer-name {
    width: 100%;
    margin: 0;
    font-size: var(--text-3xl);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -.02em;
    line-height: var(--line-height-base);
    color: var(--color-text);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-actions {
    display: flex;
    justify-content: space-evenly;
    width: 100%;

    .circle-action-label {
      white-space: nowrap;
    }
  }

  /* The compact row: back and the name at base size, on screen only once the content has
     scrolled (the header-collapse controller, below). */
  .customer-page .detail-topbar {
    padding-bottom: 0;
  }

  .customer-page .detail-header {
    border-bottom: 1px solid var(--color-border);
  }

  .customer-body {
    padding: var(--section-gap) 0 calc(var(--section-gap) + env(safe-area-inset-bottom));
  }

  .customer-page .page-section-label {
    padding-top: 0;
  }

  .customer-page .page-section-content {
    gap: 0;
  }

  /* Sobre: one lead line for every customer, folded over the traits. */
  .customer-about-fold {
    summary {
      list-style: none;
      cursor: pointer;

      &::-webkit-details-marker { display: none; }
    }

    &[open] .customer-lifecycle-chevron {
      rotate: 90deg;
    }

    .customer-traits {
      padding-top: 14px;
    }
  }

  .customer-lifecycle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-md);
    color: var(--color-text);
  }

  .customer-lifecycle-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-lifecycle-chevron {
    flex: none;
    color: var(--color-muted);
    transition: rotate 0.15s ease-out;
  }

  /* Trait chips: small, two to a row, the reason behind a tap. Icon colour by role. */
  .customer-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .customer-trait {
    position: relative;
    display: inline-flex;
    max-width: 100%;
  }

  .customer-trait-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    height: 24px;
    padding: 0 11px 0 9px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--color-bg-secondary);
    color: var(--color-text);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;

    svg { flex: none; }

    &:active { background: var(--color-bg-tertiary); }
  }

  .customer-trait-label {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-trait--success svg { color: var(--color-success-text); }
  .customer-trait--brand svg { color: var(--color-brand); }
  .customer-trait--warning svg { color: var(--color-warning-text); }
  .customer-trait--muted svg { color: var(--color-muted); }

  /* The explanation bubble a chip or the ⓘ opens. */
  .customer-help {
    display: inline-flex;
    padding: 4px;
    margin: -4px 0;
    border: 0;
    background: none;
    color: var(--color-muted);
    cursor: help;
  }

  .customer-help-text {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: var(--z-tooltip);
    width: max-content;
    max-width: min(280px, 80vw);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--color-text);
    color: var(--color-bg);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-md);
    text-transform: none;
    letter-spacing: 0;
  }

  .customer-history .page-section-label {
    position: relative;
    justify-content: flex-start;
    gap: 8px;

    .customer-help-text { left: auto; right: 0; }
  }

  /* The contextual card: shaped like the thing it stands for, not like an alert. */
  .customer-context {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--color-bg-secondary);
    color: var(--color-text);
    text-decoration: none;

    &:active { background: var(--color-bg-tertiary); }
  }

  .customer-context--unpaid {
    background: var(--color-state-payment-due-bg);
  }

  .customer-context-icon {
    flex: none;
  }

  .customer-context-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    font-size: var(--text-sm);
    line-height: var(--line-height-md);
  }

  .customer-context-title,
  .customer-context-subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-context-title { font-weight: var(--font-weight-semibold); }
  .customer-context-subtitle { font-weight: var(--font-weight-light); }

  .customer-context-chevron {
    flex: none;
    color: var(--color-muted);
  }

  /* Recorrência: the ring beside its title and sentence, at the top of the history. */
  .customer-recurrence {
    display: flex;
    align-items: center;
    gap: 18px;
  }

  .customer-ring {
    position: relative;
    flex: none;
    width: var(--customer-ring);
    height: var(--customer-ring);

    svg {
      width: 100%;
      height: 100%;
      rotate: -90deg;
      stroke-width: 9;
    }
  }

  .customer-ring-track { stroke: var(--color-border); }
  .customer-ring-fill { stroke: var(--color-brand); }
  .customer-recurrence--warning .customer-ring-fill { stroke: var(--color-warning); }

  .customer-ring-centre {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .customer-ring-big {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
  }

  .customer-ring-unit {
    font-size: var(--text-xs);
    color: var(--color-muted);
  }

  .customer-recurrence-text {
    flex: 1;
    min-width: 0;
  }

  .customer-recurrence-title {
    display: block;
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-recurrence-body {
    margin: 3px 0 0;
    font-size: var(--text-sm);
    line-height: var(--line-height-md);
    color: var(--color-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* The offer: outlined, the glyph in the text colour like the label, no third colour under
     the ring. */
  .customer-recurrence-action {
    padding-top: 16px;
  }

  .customer-offer-button {
    width: 100%;
    gap: 10px;
    font-weight: var(--font-weight-semibold);

    svg { color: currentColor; }
  }

  /* The month grid: a year per row, twelve cells. */
  .customer-months {
    display: grid;
    grid-template-columns: 36px repeat(12, 1fr);
    gap: var(--customer-cell-gap);
    align-items: center;
    padding-top: 24px;
  }

  .customer-months-head {
    font-size: 10px;
    color: var(--color-muted);
    text-align: center;
  }

  .customer-months-year {
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-muted);
  }

  .customer-month {
    display: block;
    aspect-ratio: 1;
    border-radius: 6px;
    background: var(--color-bg-tertiary);
  }

  .customer-month--future { opacity: .45; }

  .customer-month--completed {
    background: var(--color-brand);

    &[data-strength="1"] { opacity: .55; }
    &[data-strength="2"] { opacity: .7; }
    &[data-strength="3"] { opacity: .85; }
  }

  .customer-month--due { background: var(--color-state-payment-due-border); }

  .customer-month--booked {
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--color-brand);
  }

  /* The last three atendimentos as tappable rows, then the full history. */
  .customer-rows {
    padding-top: 12px;
  }

  .customer-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: var(--row-padding) 0;
    border-bottom: 0.5px solid var(--color-border);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--text-sm);

    &:active { background: var(--color-bg-secondary); }
  }

  .customer-row-date,
  .customer-row-value,
  .customer-row-chevron {
    flex: none;
    color: var(--color-muted);
  }

  .customer-row-date,
  .customer-row-value {
    font-variant-numeric: tabular-nums;
  }

  .customer-row-services {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-history-button {
    margin-top: 16px;
    padding: var(--row-padding) 14px;
  }

  /* Detalhes: the settings page's rows, flush with the section label. */
  .customer-details .list-row {
    padding: var(--row-padding) var(--content-padding);
  }

  .customer-details .list-row-value {
    max-width: 60%;
  }

  /* Desktop pane: the hero stands in for the page chrome. */
  .detail-pane-view.customer-page {
    padding-top: 12px;

    .customer-hero {
      padding-bottom: 12px;
    }
  }

  /* The header shrinks with the content: the header-collapse controller sets the class once
     the content scrolls, and the hero folds into the compact row. */
  .customer-page .customer-hero {
    max-height: 200px;
    transition: max-height 0.2s ease-out, padding 0.2s ease-out, opacity 0.15s ease-out;
  }

  .customer-page--collapsed .customer-hero {
    max-height: 0;
    padding-block: 0;
    opacity: 0;
  }

  .customer-page .detail-topbar-title {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s ease-out, visibility 0.15s;
  }

  .customer-page--collapsed .detail-topbar-title {
    visibility: visible;
    opacity: 1;
  }
}
