/* ========== The adventure's PNJ tab (8C): the list beside the open NPC ==========
   Mockup AdvNpcs (1440 GM, 1180 landscape, 820 portrait): two panes, gap 16 px, the list
   380 px (>= 1280), 340 px (1024-1279.98), 290 px (<= 1023.98). */

/* The Places recipe (places.css): the adventure title scrolls away, then both panes stick
   under the app bar and the sub-tab bar and each scrolls inside itself. */
.anima-main-content:has(.npcs-page) {
  padding-bottom: 12px;
}
.npcs-page {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.npc-list,
.npc-detail {
  position: sticky;
  top: calc(var(--chrome-h) + var(--subtab-bar-h) + 1px + 12px);
  max-height: calc(100dvh - var(--chrome-h) - var(--subtab-bar-h) - 1px - 24px);
  min-width: 0;
  box-sizing: border-box;
}
/* A sticky pane is a stacking context of its own: while one of its windows is open it rises
   above the app bar, the sub-tab bar and the ambient button, so the scrim covers them. The
   panes' own windows (« + Créer », « Éditer », the tag picker) leave them for the app root;
   the windows the sheet opens from inside the open NPC's pane (a stat's info, a module's
   detail, the portrait, the psychic launcher's side panel) are these. A bounded exception:
   moving those ~10 child windows to the root is a plan of its own (UiModal / UiSidePanel
   rendering at appRootElement() themselves). */
.npc-detail:has(.anima-modal-backdrop, .anima-modal-overlay, .anima-roll-backdrop, .anima-side-panel) {
  z-index: 1300;
}
/* The ambient button leaves the bottom-right corner, over the open NPC (the Places precedent). */
body:has(.npcs-page) .anima-ambient-fab {
  right: auto;
  left: 24px;
}

/* ── The list ── */
.npc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.npc-list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--touch-min);
}
.npc-list-title {
  flex: 1;
  margin: 0;
  font-family: var(--font-title);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.npc-new {
  min-height: var(--touch-min);
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
.npc-new:hover {
  background: var(--accent-hover);
}
.npc-search {
  flex: none;
  width: 100%;
  min-height: var(--touch-min);
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.npc-chips {
  display: flex;
  gap: 6px;
}
.npc-chip {
  flex: 1;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
}
.npc-chip[aria-pressed='true'] {
  border: 2px solid var(--accent);
  background: var(--selected);
}
@media (pointer: coarse) {
  .npc-chip {
    min-height: var(--touch-min);
  }
}

.npc-sections {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Room under the last row: it scrolls clear of the ambient button. */
  padding-bottom: 9rem;
  scrollbar-width: thin;
}
.npc-section-head {
  flex: none;
  min-height: 40px;
  margin-top: 4px;
  padding: 0 4px;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.npc-section-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.npc-section-dot--favorites {
  background: var(--accent);
}
.npc-section-dot--none {
  background: var(--muted);
}
.npc-section-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow-wrap: anywhere;
}
.npc-section-caret {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  transition: transform 0.15s;
}
.npc-section-head[aria-expanded='false'] .npc-section-caret {
  transform: rotate(-90deg);
}

.npc-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 0 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.npc-row:hover {
  border-color: var(--border-strong);
}
/* The open NPC: a 2 px accent border, the padding 1 px less so the row does not move. */
.npc-row--current {
  padding: 0 7px 0 1px;
  border: 2px solid var(--accent);
  background: var(--selected);
}
.npc-row-star {
  flex: none;
  width: 40px;
  height: var(--touch-min);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.npc-row-star svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.npc-row-star[aria-pressed='true'] {
  color: var(--accent);
}
.npc-row-star[aria-pressed='true'] svg {
  fill: currentColor;
}
.npc-row-select {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 4px 0 0;
  border: none;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-family: var(--font-body);
}
.npc-row-select .anima-character-avatar {
  flex: none;
  width: 36px;
  height: 36px;
}
.npc-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.25;
}
.npc-row-name {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.npc-row-meta {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.npc-row-meta:empty {
  display: none;
}
/* The eye is the svg itself (role img): 32 px box, 16 px glyph. */
.npc-row-eye {
  flex: none;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  padding: 8px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  color: var(--muted);
}
.npc-row-eye--on {
  color: var(--accent);
}
.npc-empty {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ── « + Créer »: a short window, 480 px ──
   The socle short window (components.css) sets 520 px: the third class makes this rule win
   by specificity, whatever order the stylesheets load in. */
.anima-modal.anima-modal--short.npc-form-window {
  width: min(480px, calc(100vw - 48px));
}
.npc-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.npc-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.npc-form-label {
  font-size: 0.8rem;
  color: var(--muted);
}
.npc-form-input {
  box-sizing: border-box;
  min-height: var(--touch-min);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.9rem;
}
.npc-form-input:focus {
  border: 2px solid var(--accent);
  outline: none;
  padding: 0 11px;
}
.npc-form-cancel,
.npc-form-submit {
  min-height: 48px;
  border-radius: 10px;
  font-size: 0.85rem;
}
.npc-form-cancel {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink);
  font-weight: 500;
}
.npc-form-submit {
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

/* ── The open NPC ──
   The pane is as tall as the space under the bars: the header and the GM row take what they
   need, the sheet card the rest, and the sheet scrolls inside itself. */
.npc-detail {
  height: calc(100dvh - var(--chrome-h) - var(--subtab-bar-h) - 1px - 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.npc-detail-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
}
.npc-detail-head .anima-character-avatar {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 12px;
}
.npc-detail-heading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.npc-detail-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.33rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.npc-detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.npc-detail-badge {
  padding: 3px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}
.npc-detail-edit {
  flex: none;
  min-height: var(--touch-min);
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
}
.npc-detail-edit:hover {
  border-color: var(--accent);
}
.npc-list-error,
.npc-detail-error {
  flex: none;
  margin: 0;
  font-size: 0.85rem;
  color: var(--danger);
}

/* The GM row: the switch card and the tags card side by side (one column <= 1023.98). */
.npc-detail-gm-row {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.npc-detail-card {
  box-sizing: border-box;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.npc-detail-visibility {
  display: flex;
  align-items: center;
  gap: 10px;
}
.npc-detail-visible-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.npc-detail-visible-label {
  font-size: 0.85rem;
  color: var(--ink);
}
.npc-detail-visible-hint {
  font-size: 0.8rem;
  color: var(--muted);
}
/* The track is 56 x 32; the button around it is the 44 px hit area (the places switch). */
.npc-switch {
  flex: none;
  position: relative;
  width: 56px;
  height: var(--touch-min);
  padding: 0;
  border: none;
  background: transparent;
}
.npc-switch::before {
  content: '';
  position: absolute;
  inset: 50% 0 auto;
  height: 32px;
  margin-top: -16px;
  border-radius: 16px;
  background: var(--border-strong);
}
.npc-switch[aria-checked='true']::before {
  background: var(--accent);
}
.npc-switch:disabled {
  opacity: 0.7;
}
.npc-switch-knob {
  position: absolute;
  top: 50%;
  margin-top: -12px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--on-accent);
}
.npc-switch[aria-checked='true'] .npc-switch-knob {
  left: auto;
  right: 4px;
}
.npc-detail-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.npc-detail-tags-label {
  margin-right: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}
.npc-tag-pill {
  min-height: 36px;
  max-width: 100%;
  box-sizing: border-box;
  gap: 6px;
  padding: 0 4px 0 10px;
  overflow-wrap: anywhere;
}
/* A 28 px cross in the pill; it answers a finger over a 44 px square. */
.npc-tag-remove {
  flex: none;
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
}
.npc-tag-remove::after {
  content: '';
  position: absolute;
  inset: -8px;
}
.npc-tag-remove svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
}
.npc-tag-add {
  min-height: 36px;
  padding: 0 12px;
  border-color: var(--border-strong);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
  position: relative;
}
.npc-tag-add::after {
  content: '';
  position: absolute;
  inset: -4px 0;
}

/* The sheet card: the character sheet's view, its tab bar sticky at the top of its scroll. */
.npc-detail-sheet {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}
.npc-detail-sheet .anima-char-sheet-modal-body {
  min-height: 0;
  padding: 0 16px 16px;
  scrollbar-width: thin;
}
.npc-detail-sheet .anima-sheet-tabs {
  background: var(--surface);
}
.npc-detail-sheet-error {
  margin: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.npc-detail-sheet-error-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.npc-detail-retry {
  min-height: var(--touch-min);
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.npc-detail--empty {
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
}
.npc-detail-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 1279.98px) {
  .npcs-page {
    grid-template-columns: 340px minmax(0, 1fr);
  }
}
@media (max-width: 1023.98px) {
  .npcs-page {
    grid-template-columns: 290px minmax(0, 1fr);
  }
  .npc-detail-gm-row {
    grid-template-columns: minmax(0, 1fr);
  }
}
