/* ─────────────────────────────────────────────────────────────────────────
   Family Links — shared styles for the panel, the strip and the link modal.

   Every colour here is a theme.css token, so the whole component re-skins with
   the platform and works in both themes for free. A page that loads this file
   MUST also load /css/theme.css — an undefined var() invalidates the whole
   declaration, so a missing link paints these surfaces transparent rather than
   throwing anything. (`npm run theme:check` enforces both halves.)

   Used by public/js/character-relations.js. See docs/CHARACTER_RELATIONSHIPS.md.
   ───────────────────────────────────────────────────────────────────────── */

/* ── Avatars ──────────────────────────────────────────────────────────── */
.cr-av {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex: none;
  overflow: hidden;
  line-height: 1;
}
.cr-av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cr-av-xs { width: 24px; height: 24px; font-size: 0.68rem; }
.cr-av-md { width: 38px; height: 38px; }
.cr-av-lg { width: 46px; height: 46px; font-size: 1rem; }
.cr-av-xl { width: 62px; height: 62px; font-size: 1.4rem; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.cr-btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.5rem 0.95rem;
  border-radius: 0.45rem;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cr-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.cr-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.cr-btn-primary { background: var(--brand-fill); color: var(--brand-ink); }
.cr-btn-primary:hover:not([disabled]) { background: var(--brand-fill-hover); }

.cr-btn-ghost {
  background: var(--surface-page);
  color: var(--ink);
  border-color: var(--line-strong);
}
.cr-btn-ghost:hover:not([disabled]) { background: var(--surface-sunken); }

.cr-btn-quiet { background: none; color: var(--ink-muted); }
.cr-btn-quiet:hover:not([disabled]) { color: var(--status-danger); background: var(--surface-sunken); }

.cr-btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

.cr-spacer { margin-left: auto; }

/* ── Panel ────────────────────────────────────────────────────────────── */
.cr-panel { color: var(--ink); }

.cr-person { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.9rem; }
.cr-person-name { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; }
.cr-person-sub { font-size: 0.8rem; color: var(--ink-muted); }

.cr-list { display: flex; flex-direction: column; }
.cr-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.15rem;
  border-bottom: 1px solid var(--line);
  min-height: 46px;
}
.cr-row:first-child { border-top: 1px solid var(--line); }
.cr-row-who { min-width: 0; }
.cr-row-name { font-weight: 600; }
.cr-row-rel { color: var(--ink-muted); font-size: 0.86rem; }
.cr-row-actions { display: flex; gap: 0.25rem; flex: none; }

.cr-panel-foot { margin-top: 0.9rem; }

.cr-empty {
  border: 1px dashed var(--line-strong);
  border-radius: 0.6rem;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
}
.cr-empty p { margin: 0 0 0.75rem; }
.cr-empty-inline { color: var(--ink-muted); font-size: 0.82rem; }

/* Skeleton rows rather than a spinner: the panel keeps its shape while it loads. */
.cr-skeleton { display: flex; flex-direction: column; gap: 0.55rem; padding: 0.4rem 0; }
.cr-skeleton span {
  display: block;
  height: 44px;
  border-radius: 0.5rem;
  background: var(--surface-sunken);
  opacity: 0.75;
  animation: cr-pulse 1.4s ease-in-out infinite;
}
.cr-skeleton span:nth-child(2) { animation-delay: 0.15s; }
.cr-skeleton span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cr-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.9; } }

/* ── Generation strip ─────────────────────────────────────────────────── */
.cr-strip-host { display: block; }
.cr-strip-label {
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  margin-bottom: 0.45rem;
}
.cr-strip {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  scrollbar-width: thin;
}
.cr-member {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem 0.25rem 0.25rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-page);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  min-height: 34px;
}
.cr-member:hover { background: var(--surface-sunken); }
.cr-member:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.cr-member small { color: var(--ink-muted); }
.cr-member-used {
  background: var(--brand-fill);
  color: var(--brand-ink);
  border-color: var(--brand-fill);
}
.cr-member-used small { color: var(--brand-ink-soft); }
.cr-member-used .cr-av { background: var(--glass-strong); border-color: transparent; color: inherit; }
.cr-strip-hint { font-size: 0.7rem; color: var(--ink-muted); margin-top: 0.45rem; }

/* ── Modal ────────────────────────────────────────────────────────────── */
body.cr-modal-open { overflow: hidden; }

.cr-modal-root { position: fixed; inset: 0; z-index: 2200; }
.cr-scrim { position: absolute; inset: 0; background: var(--surface-veil); }
.cr-modal {
  position: relative;
  margin: 6vh auto 0;
  width: min(480px, calc(100% - 2rem));
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface-overlay);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 0.8rem;
  box-shadow: var(--shadow-lg);
}
.cr-modal-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}
.cr-modal-title { font-weight: 600; }
.cr-modal-sub { font-size: 0.78rem; color: var(--ink-muted); }
.cr-x {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--ink-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.cr-x:hover { color: var(--ink); }

.cr-modal-body { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.cr-field-label {
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* Search + scrolling list. A creator can have dozens of characters; a wrapping
   chip row would push the sentence preview and the Save button out of the
   modal, so the list scrolls inside a fixed height instead. */
.cr-search {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.45rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.45rem;
  background: var(--surface-page);
  color: var(--ink);
}
.cr-search::placeholder { color: var(--ink-muted); }
.cr-search:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.cr-search[hidden] { display: none; }

.cr-who {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-height: 224px;          /* ~5 rows, then it scrolls */
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.25rem;
  scrollbar-width: thin;
}
.cr-who-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid transparent;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
}
.cr-who-btn:hover { background: var(--surface-sunken); }
.cr-who-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.cr-who-btn[aria-selected="true"] {
  background: var(--brand-fill);
  color: var(--brand-ink);
  border-color: var(--brand-fill);
}
.cr-who-btn[aria-selected="true"] .cr-av { background: var(--glass-strong); border-color: transparent; color: inherit; }
.cr-who-btn[aria-selected="true"] .cr-who-meta { color: var(--brand-ink-soft); }
.cr-who-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.cr-who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-who-meta { font-size: 0.72rem; color: var(--ink-muted); }

.cr-no-match { font-size: 0.8rem; color: var(--ink-muted); padding: 0.5rem 0.1rem 0; }
.cr-no-match[hidden] { display: none; }

/* Two sections of relationship words — family and professional. */
.cr-groups { display: flex; flex-direction: column; gap: 0.7rem; }
.cr-group-label {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.cr-list-label { margin-top: 0.9rem; }
.cr-list-label:first-child { margin-top: 0; }

/* A real menu, not a styled <select>: appearance:none never reaches the
   option list, which stays OS-rendered and off-theme.

   Four columns, because both groups hold exactly eight words — so the last row
   is always full and the grid never shows a gap. The 1px gap over a line-
   coloured background draws the dividers, which beats per-cell border rules
   that have to know where the row ends. */
.cr-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  overflow: hidden;
}
.cr-type {
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.2;
  padding: 0.55rem 0.3rem;
  background: var(--surface-page);
  color: var(--ink-soft);
  border: 0;
  cursor: pointer;
  text-transform: capitalize;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.cr-type:hover { background: var(--surface-sunken); }
.cr-type:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -3px; }
.cr-type[aria-pressed="true"] {
  background: var(--brand-fill);
  color: var(--brand-ink);
  font-weight: 600;
}

.cr-preview {
  background: var(--surface-sunken);
  border-radius: 0.5rem;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cr-line { font-size: 0.92rem; }
.cr-line-two { font-size: 0.85rem; color: var(--ink-soft); }
.cr-hint { font-size: 0.74rem; color: var(--ink-muted); }
.cr-hint:empty { display: none; }

.cr-flips { display: inline-flex; gap: 0.3rem; margin-left: 0.2rem; vertical-align: middle; }
.cr-flip {
  font: inherit;
  font-size: 0.75rem;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-page);
  color: var(--ink-soft);
  cursor: pointer;
  text-transform: capitalize;
}
.cr-flip[aria-pressed="true"] {
  background: var(--brand-fill);
  color: var(--brand-ink);
  border-color: var(--brand-fill);
}

/* The error sits in the form, not in a toast — the user is still looking here. */
.cr-error {
  font-size: 0.82rem;
  color: var(--status-danger);
  border-left: 2px solid var(--status-danger);
  padding-left: 0.6rem;
}

.cr-modal-foot {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--surface-raised);
}

/* ── Toast (only used when the page has no showToast of its own) ───────── */
.cr-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 2400;
  background: var(--brand-fill);
  color: var(--brand-ink);
  border-radius: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  box-shadow: var(--shadow-md);
  max-width: min(420px, calc(100% - 2rem));
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.cr-toast-error { background: var(--status-danger); color: var(--status-ink); }
.cr-toast-out { opacity: 0; transform: translate(-50%, 0.5rem); }

/* ── Phone ────────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  /* The link modal becomes a bottom sheet — the thumb is at the bottom, and
     the sentence preview stays above the fold with the keyboard closed. */
  .cr-modal {
    margin: 0;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 92vh;
    border-radius: 0.9rem 0.9rem 0 0;
    border-bottom: 0;
  }
  .cr-picker { grid-template-columns: repeat(2, 1fr); }
  .cr-who { max-height: 40vh; }
  .cr-modal-foot { flex-wrap: wrap; }
  .cr-modal-foot .cr-btn-primary { flex: 1 1 100%; order: -1; }
  .cr-row-actions .cr-btn { padding: 0.35rem 0.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cr-btn, .cr-toast, .cr-skeleton span { transition: none; animation: none; }
}
