/* pages/contacts.css — /contacts/ (spec §5.3).
 *
 * The page is a list/detail split built from the foundation's components:
 *   - the list: the M3 search bar (.split__search, m3.css) over a STANDARD
 *     list (ul.people.m3-list) of two-line items (button.person.m3-list-item)
 *     with an .m3-avatar and a trailing FILL 1 star;
 *   - the record: .card-detail (m3.css §3.28) with the sticky head
 *     (app.css §4.7) carrying the outlined Star toggle + outlined Edit as its
 *     last row (D16), the property sections drawn as SEGMENTED lists, and the
 *     outlined map card;
 *   - the editor: filled text fields (.fieldgrid, .entry), Cancel text then
 *     Save filled ink at the trailing edge (§5.5), capped at 720.
 * This file only says what is Contacts' own on top of those.
 *
 * PAGE-SCOPE RULE (§1.1, test_design check 9): every selector starts with a
 * class this file owns — `.people`, `.person*`, `.field__map` —
 * or with [data-page="contacts"]. All eleven page files load on every page.
 */

/* ── The list ──────────────────────────────────────────────────────────────
   The one scroller of the list column (§4.7): it fills what the search bar
   leaves. Its fade and hidden bar are the shell's (app.css §4.13). */
.people {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The supporting line is an <em>: the list item's role, not italics. It is
   ONE line ending in an ellipsis, like the headline beside it: the shared
   line-clamp cannot add an ellipsis to one long unbroken word (an email
   address), so it would be cut mid-letter. */
.person__text em {
  display: block;
  font-style: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A starred person's avatar is the SAME grey as anyone's (answer 1: an accent
   never fills a shape); the star at the end of the row says it. On the
   selected row the avatar steps one rung up the grey ladder, or the #333537
   disc would vanish into the #333537 selection. */
.person[aria-current="true"] .person__avatar { background: var(--md-sys-color-surface-variant); }

/* The trailing star: an indicator, not a control (the whole row is one
   button). 20px, FILL 1, on-surface-variant. */
.person__star {
  --_icon: var(--app-icon-size-medium);
  --_opsz: 20;
  --_fill: 1;
  color: var(--md-sys-color-on-surface-variant);
}
.person[aria-current="true"] .person__star { color: var(--md-sys-color-on-secondary-container); }

/* ON A PHONE, THE ROW OF A RECORD NOBODY OPENED IS NOT LIT. The page arrives
   with the first person in the detail (index.html marks that article
   [data-arrived]); beside a list that is fine, but below 840px the list is
   all there is, and a lit row would claim something is open. The first swap
   of the detail (a tap, a restore) drops the mark and the row lights as on
   every page. Only the selected look is undone: the mark stays in the DOM, so
   a search still keeps it and workspace.js still moves it. */
@media (max-width: 839px) {
  [data-page="contacts"] .split:has(> .split__detail > [data-arrived]) .person[aria-current="true"] {
    --_container: transparent;
    --_state-color: var(--md-sys-color-on-surface);
    --_head: var(--md-sys-color-on-surface);
    --_sup: var(--md-sys-color-on-surface-variant);
    --_head-w: var(--md-sys-typescale-body-large-weight);
    --_head-rond: 0;
  }
  [data-page="contacts"] .split:has(> .split__detail > [data-arrived]) .person[aria-current="true"] .person__avatar {
    background: var(--md-sys-color-secondary-container);
  }
  [data-page="contacts"] .split:has(> .split__detail > [data-arrived]) .person[aria-current="true"] .person__star {
    color: var(--md-sys-color-on-surface-variant);
  }
}
/* …and in a half of a split the list is all there is too (app.css, READING
   MODE: every <=839px rule has its twin, at the same weight, right after it). */
[data-page="contacts"] .split:has(> .split__detail > [data-arrived]):where(.content.is-split *) .person[aria-current="true"] {
  --_container: transparent;
  --_state-color: var(--md-sys-color-on-surface);
  --_head: var(--md-sys-color-on-surface);
  --_sup: var(--md-sys-color-on-surface-variant);
  --_head-w: var(--md-sys-typescale-body-large-weight);
  --_head-rond: 0;
}
[data-page="contacts"] .split:has(> .split__detail > [data-arrived]):where(.content.is-split *) .person[aria-current="true"] .person__avatar {
  background: var(--md-sys-color-secondary-container);
}
[data-page="contacts"] .split:has(> .split__detail > [data-arrived]):where(.content.is-split *) .person[aria-current="true"] .person__star {
  color: var(--md-sys-color-on-surface-variant);
}

/* ── The record ────────────────────────────────────────────────────────────
   The head: the 72px avatar (.m3-avatar--lg), the name in headline-small
   emphasized (m3.css), and its subtitle and nickname in body-large. */
.person__name { display: grid; gap: 4px; min-width: 0; flex: 1; }
[data-page="contacts"] .card-detail__sub {
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  font-weight: var(--md-sys-typescale-body-large-weight);
}

/* The property sections stack 24px apart (the record's 16px gap + 8). Each is
   a heading with its icon over a SEGMENTED list (§3.10): one tile per value,
   2px apart, 16px outer corners and 4px inner ones. The tiles are
   surface-container-high on the reading region. */
[data-page="contacts"] .card-detail > .field + .field { margin-top: 8px; }
[data-page="contacts"] .field { gap: 2px; }
/* The heading's icon sits on the record's one left edge: the tiles', the
   head avatar's, the map's and the buttons'. */
[data-page="contacts"] .field h3 { margin-bottom: 6px; padding-inline: 0; }
[data-page="contacts"] .field__row {
  box-sizing: border-box;
  min-height: var(--app-field-h);
  padding: 8px 16px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-high);
}
[data-page="contacts"] .field__row:first-of-type {
  border-start-start-radius: var(--md-sys-shape-corner-large);
  border-start-end-radius: var(--md-sys-shape-corner-large);
}
[data-page="contacts"] .field__row:last-of-type {
  border-end-start-radius: var(--md-sys-shape-corner-large);
  border-end-end-radius: var(--md-sys-shape-corner-large);
}
/* The type ("mobile", "home") is a label chip at the tile's end. */
[data-page="contacts"] .field__row > .field__tag { margin-inline-start: auto; }
/* A NUMBER OR AN ADDRESS IS THE WHOLE TILE. Calling or mailing is the main
   thing a phone does here, and the link text alone was a 24px target in a
   56px tile. The link's ::after covers the tile (a stretched link), so a tap
   anywhere on it, the label chip included, dials or writes; the tile takes
   the link's hover and focus as its own state layer and ring. */
[data-page="contacts"] .field__row:has(> a:is([href^="tel:"], [href^="mailto:"])) {
  position: relative;
  --_state: 0%;
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--_state), var(--md-sys-color-surface-container-high));
  -webkit-tap-highlight-color: transparent;
}
[data-page="contacts"] .field__row > a:is([href^="tel:"], [href^="mailto:"])::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
@media (hover: hover) {
  [data-page="contacts"] .field__row:has(> a:is([href^="tel:"], [href^="mailto:"]):hover) {
    --_state: var(--md-sys-state-hover-state-layer-opacity);
  }
}
[data-page="contacts"] .field__row:has(> a:is([href^="tel:"], [href^="mailto:"]):active) {
  --_state: var(--md-sys-state-pressed-state-layer-opacity);
}
[data-page="contacts"] .field__row:has(> a:is([href^="tel:"], [href^="mailto:"]):focus-visible) {
  --_state: var(--md-sys-state-focus-state-layer-opacity);
  outline: var(--app-focus-ring);
  outline-offset: var(--app-focus-offset-inner);
}
[data-page="contacts"] .field__row > a:is([href^="tel:"], [href^="mailto:"]):focus-visible { outline: none; }
/* A multi-line value (an address, the notes) keeps its <br>s in one flex
   item rather than each line becoming one. */
.person__value { min-width: 0; }

/* The contact's map: an OUTLINED CARD under the Address tiles, its own
   document (map.html; its colours are hand copies of these tokens).
   ⚠️ A fixed height because an iframe has no intrinsic one and would collapse
   to 150px (the HTML default) or to nothing, depending on the browser. */
.field__map {
  box-sizing: border-box;
  display: block;
  width: 100%;
  height: 240px;
  margin-top: 6px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-low);
  color-scheme: dark;
}
.field__map[hidden] { display: none; }

/* The actions are the head's last row (D16): in reach on a long contact,
   riding the sticky head as Mail's do (mail.css spaces its row the same).
   A FULL-WIDTH row under avatar and name, on the record's left edge, not a
   row in the name's column: at 360 that column is ~190px and Star + Edit
   broke onto two rows, making the sticky head 240px tall. */
[data-page="contacts"] .split__detail .card-detail__head:has(> .person__name) { flex-wrap: wrap; row-gap: 12px; }
[data-page="contacts"] .card-detail__head > .card-detail__actions { flex-basis: 100%; gap: 8px; }

/* The Star toggle's label reserves the width of "Starred" (.m3-label, D18);
   centre the shorter "Star" in that width rather than leaving its spare
   space all on the right. */
[data-page="contacts"] .card-detail__actions .m3-label { align-items: center; }

/* ── The editor ────────────────────────────────────────────────────────────
   Everything under the head is held to the form measure (720); the head
   itself keeps the record's full width. Two field columns from 560px of
   form width (a container query: the form's width, not the window's, is
   what a split pane or reading mode changes). */
[data-page="contacts"] form.card-detail { container-type: inline-size; }
[data-page="contacts"] form.card-detail > :not(.card-detail__head) { max-inline-size: var(--app-form-max); }
[data-page="contacts"] form.card-detail .fieldgrid { grid-template-columns: minmax(0, 1fr); }
/* Cancel, then Save at the trailing edge of the 720 measure (§5.5). */
[data-page="contacts"] form.card-detail > .card-detail__actions { justify-content: flex-end; }
/* The heading takes focus when the form swaps in (autofocus, tabindex -1):
   a programmatic landing place, not a control, so no ring (as the Calendar's). */
[data-page="contacts"] form.card-detail h2[tabindex="-1"]:focus { outline: none; }
@container (min-width: 560px) {
  [data-page="contacts"] form.card-detail .fieldgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* A phone-width form: the entry's label field gives up 48px so the address
   or number beside it keeps a readable width (at 360 the 160px label left
   the value 144px). */
@container (max-width: 479px) {
  [data-page="contacts"] form.card-detail .entry { grid-template-columns: minmax(0, 1fr) 112px; }
}
