/* sp_manage_patients_html — the Manage Patient Assignments pop-up's own rules,
 * kept here because the server strips a template's <style> block.
 *
 * SCOPED ON THE OVERLAY ID, NEVER ON THE SHELL'S .sp-dashboard. pxShowOverlay
 * moves #sp-patients-overlay into #px-modal-portal on every open, so the
 * overlay and everything inside it leave .sp-dashboard the moment the dialog
 * opens. The overlay IS this form's root (the template has one top-level node),
 * so an id scope travels with the node and every rule keeps matching wherever
 * the node is parked.
 *
 * :where() contributes zero specificity, so every .sp-patients-* rule keeps the
 * weight it has today. Three kinds of rule are deliberately NOT written that
 * way:
 *
 *   1. Rules whose SUBJECT is the root itself (.sp-patients-overlay.active
 *      .sp-patients-modal, and the media query's overlay rule) stay bare: the
 *      root is not a descendant of itself.
 *   2. Rules that TIE with something the dependency injects into <head> at
 *      startup, which lands after every head link and so wins every tie on
 *      document order. Today they sat in a body <style> block and won that tie
 *      by position; from a head link they need a second class instead.
 *      Each is marked ORDER below with the rule it beats.
 *   3. .sp-patients-row .sp-patients-unit-select, written as the two-class form
 *      the blueprint's pin 4 authorises, for the same reason.
 *
 * No designer gate: .sp-patients-modal declares transform, not opacity, so the
 * dialog's contents are visible on the canvas, shifted 20px — exactly as today.
 * On that canvas the pop-up also renders in flow rather than
 * fixed and dimmed, because .px-modal-overlay and .px-modal are injected from
 * Python and the designer runs no Python. That is expected, not a fault.
 *
 * .themed-scrollbar is the dependency's and is declared nowhere here.
 */

/* ========================================
   SP MANAGE PATIENTS MODAL
   Uses shared px-modal-overlay styles
   ======================================== */
.sp-patients-overlay.active .sp-patients-modal {
  transform: translateY(0);
}

:where(#sp-patients-overlay) .sp-patients-modal {
  max-width: 700px;
  width: 90%;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ========================================
   MODAL HEADER - uses px-modal-header pattern
   ======================================== */
:where(#sp-patients-overlay) .sp-patients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--px-border);
  flex-shrink: 0;
}

:where(#sp-patients-overlay) .sp-patients-title {
  font-family: var(--px-font);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--px-text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

:where(#sp-patients-overlay) .sp-patients-title::before {
  content: '';
  width: 4px;
  height: 24px;
  background: var(--accent);
  border-radius: 2px;
}

/* R3-65: the X button takes the shared `.px-modal-close` chrome from
   theme.css. Only the focus ring is kept locally (the shared class has
   no :focus-visible rule) and scoped to this overlay. */
#sp-patients-overlay .px-modal-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The Save button's full width came off the shell's style block, where it was
   declared once for both pop-ups. Scoped to .sp-dashboard it would stop
   matching the moment the button is portaled out of the shell, so it is written
   here instead, on the root that travels with it. */
:where(#sp-patients-overlay) .px-btn-full {
  width: 100%;
}

/* ========================================
   MODAL BODY - uses px-modal-body pattern
   ======================================== */
:where(#sp-patients-overlay) .sp-patients-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ========================================
   PATIENT ROWS CONTAINER
   ======================================== */
:where(#sp-patients-overlay) .sp-patients-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 60px;
}

:where(#sp-patients-overlay) .sp-patients-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--px-border-subtle);
  transition: background 0.15s ease;
}

:where(#sp-patients-overlay) .sp-patients-row:last-child {
  border-bottom: none;
}

:where(#sp-patients-overlay) .sp-patients-row:hover {
  background: var(--accent-subtle);
}

:where(#sp-patients-overlay) .sp-patients-name {
  font-family: var(--px-font);
  font-size: 14px;
  font-weight: 600;
  color: var(--px-text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ORDER: beats the dependency's `.px-input, .px-select { width: 100% }`, which
   is injected into <head> after every head link. The select carries both
   classes, so a one-class rule would tie and lose the dropdown's 200px width. */
.sp-patients-row .sp-patients-unit-select {
  width: 200px;
  flex-shrink: 0;
}

:where(#sp-patients-overlay) .sp-patients-empty {
  text-align: center;
  padding: 32px 16px;
  font-family: var(--px-font);
  font-size: 14px;
  color: var(--px-text-muted);
  font-style: italic;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 600px) {
  /* ORDER: max-height and border-radius both tie with the dependency's
     `.px-modal`, injected after every head link, so the modal class is doubled
     with the shared one it sits beside. */
  :where(#sp-patients-overlay) .sp-patients-modal.px-modal {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  /* ORDER: align-items ties with the dependency's `.px-modal-overlay`, same
     injection. Root subject, so no :where() scope; the shared class it already
     carries is what doubles it. */
  .sp-patients-overlay.px-modal-overlay {
    align-items: stretch;
  }

  :where(#sp-patients-overlay) .sp-patients-header {
    padding: 16px 16px 12px;
  }

  :where(#sp-patients-overlay) .sp-patients-body {
    padding: 16px;
  }

  :where(#sp-patients-overlay) .sp-patients-title {
    font-size: 1.1rem;
  }

  :where(#sp-patients-overlay) .sp-patients-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px 4px;
  }

  :where(#sp-patients-overlay) .sp-patients-name {
    font-size: 15px;
    white-space: normal;
  }

  .sp-patients-row .sp-patients-unit-select {
    width: 100%;
  }
}
