/*
 * Expert cast: the compact per-course expert cards and the detail modal.
 *
 * Loaded by BOTH public design systems - styles.css (catalogue, course page,
 * archive) and home.css (landing page). Those two do not share a palette:
 * styles.css is hex and defines --line/--panel, home.css is oklch and defines
 * --border/--surface/--radius, and their --muted values sit on OPPOSITE sides
 * of the lightness scale (home's is a light tone meant for the dark page
 * background, and using it here would be unreadable on the light card). So
 * this component resolves its own locals from whichever variables the host
 * page happens to define, with a fallback for the other one, and never touches
 * --muted. Every fallback is the value the host system uses for the same
 * purpose, so the component looks native in both.
 */

.expert-cast,
.expert-modal {
  --ec-ink: var(--ink, #173851);
  --ec-soft: color-mix(in oklch, var(--ec-ink) 58%, white);
  --ec-line: var(--line, oklch(70% 0.03 235 / 40%));
  --ec-surface: var(--panel, var(--surface, #ffffff));
  --ec-radius: var(--radius, 8px);
  --ec-accent: var(--accent, #c97042);
}

/* ---- compact cards --------------------------------------------------- */

.expert-cast {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

/* A full button reset: this element lands inside two unrelated stylesheets,
   each with its own opinionated global button rules. The WHOLE card is the
   control - there is no inner icon to hit - so it is also the whole touch
   target on a phone. */
.expert-chip {
  -webkit-appearance: none;
  appearance: none;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  flex: 1 1 210px;
  min-width: 0;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--ec-line);
  border-radius: var(--ec-radius);
  background: var(--ec-surface);
  color: var(--ec-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  /* A tap must not be swallowed by the browser's 300ms dbl-tap-zoom wait, and
     the card must not be selected instead of activated on a long press. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

/* No photo: no empty column, no placeholder, no broken image - the card is
   simply a text block. */
.expert-chip--no-photo {
  grid-template-columns: minmax(0, 1fr);
}

/* The one non-interactive case: a legacy free-text teacher, who has no
   directory record and therefore nothing for a modal to show. It must not
   advertise an affordance it does not have. */
.expert-chip--static {
  cursor: default;
}

.expert-chip:not(.expert-chip--static):hover {
  border-color: var(--ec-accent);
  background: color-mix(in oklch, var(--ec-surface) 94%, var(--ec-accent));
}

.expert-chip:focus-visible {
  outline: 2px solid var(--ec-accent);
  outline-offset: 2px;
  border-color: var(--ec-accent);
}

.expert-chip-photo {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in oklch, var(--ec-ink) 8%, white);
}

.expert-chip-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.expert-chip-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.expert-chip-role {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ec-soft);
}

.expert-chip-name {
  font-size: 14px;
  font-weight: 700;
  /* Long names wrap rather than widening the card or overflowing it. */
  overflow-wrap: anywhere;
}

.expert-chip-position {
  font-size: 12px;
  line-height: 1.35;
  color: var(--ec-soft);
  /* At most two lines here; the full text is one click away in the modal.
     This is what keeps a five-expert card from becoming a wall of text. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- the course page sidebar ---------------------------------------- */

/* One card per row: the sidebar column is narrow, and the list is the whole
   point of the block rather than a detail inside a card. */
.expert-cast--sidebar {
  display: grid;
  gap: 8px;
}

.expert-cast--sidebar .expert-chip {
  flex: none;
  width: 100%;
}

/* ---- the archive row ------------------------------------------------- */

/* The cast is a direct child of the row shell, a sibling of the course link,
   so it needs no column spanning of its own. It is separated from the link by
   a rule, because the two are different controls and a visitor should see
   where the course link stops. */
.archive-item .expert-cast {
  padding-top: 12px;
  border-top: 1px solid var(--ec-line);
}

/* ---- modal ---------------------------------------------------------- */

/* Class selectors, not `dialog`, on purpose: home.css already styles the bare
   `dialog` element for its own contact form, and this component must not
   inherit that sizing. Specificity here is higher, so both pages get exactly
   these rules. */
.expert-modal {
  width: min(560px, calc(100% - 24px));
  max-width: none;
  /* padding:0 is load-bearing, not cosmetic: the inner wrapper then covers the
     entire dialog box, so a click that reports the <dialog> itself as its
     target can only have come from the backdrop. That is how outside-click
     closing is detected. */
  padding: 0;
  border: 1px solid var(--ec-line);
  border-radius: var(--ec-radius);
  background: var(--ec-surface);
  color: var(--ec-ink);
  box-shadow: 0 40px 120px oklch(10% 0.04 245 / 45%);
}

.expert-modal::backdrop {
  background: oklch(12% 0.04 245 / 72%);
  backdrop-filter: blur(6px);
}

.expert-modal-inner {
  position: relative;
  /* Long regalia scroll inside the modal, never the page behind it. */
  max-height: min(85vh, 760px);
  overflow-y: auto;
  padding: 24px;
}

.expert-modal-close {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--ec-line);
  border-radius: var(--ec-radius);
  background: var(--ec-surface);
  color: var(--ec-ink);
  font: 400 22px/1 system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.expert-modal-close:focus-visible {
  outline: 2px solid var(--ec-accent);
  outline-offset: 2px;
}

.expert-modal-head {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 18px;
  align-items: start;
  /* Keeps the identity block clear of the absolutely positioned close button. */
  padding-right: 44px;
}

.expert-modal--no-photo .expert-modal-head {
  grid-template-columns: 1fr;
}

.expert-modal-photo {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: var(--ec-radius);
  overflow: hidden;
  background: color-mix(in oklch, var(--ec-ink) 8%, white);
}

.expert-modal-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.expert-modal-ident {
  min-width: 0;
}

.expert-modal-role {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ec-soft);
}

.expert-modal-name {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.expert-modal-position {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ec-soft);
}

.expert-modal-description {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--ec-line);
  font-size: 14px;
  line-height: 1.6;
}

.expert-modal-description > :first-child { margin-top: 0; }
.expert-modal-description > :last-child { margin-bottom: 0; }
.expert-modal-description img { max-width: 100%; height: auto; }

@media (max-width: 640px) {
  /* One card per row on a phone, so the whole width is the touch target. */
  .expert-chip { flex: 1 1 100%; }

  .expert-modal { width: calc(100% - 20px); }
  .expert-modal-inner { padding: 18px; max-height: 88vh; }
  .expert-modal-head {
    grid-template-columns: 72px 1fr;
    gap: 14px;
  }
  .expert-modal-photo { width: 72px; height: 72px; }
  .expert-modal-name { font-size: 19px; }
}
