/* ============================================================
   Screen Definition Editor (admin) page.
   Structure in @layer layout, paint in @layer design. Content-named
   classes only — no legacy/appearance names, no hardcoded color.
   Reuses .app-screen and .btn/.btn--primary/.btn--outline from
   elements.css.

   ADMIN page: system admins / prosecutors author screen definitions under
   the default light .app-screen palette. This stylesheet only references
   --t-* semantic tokens, which app/theme.css rebinds per theme, so the
   page reskins without any role-specific color rules here. The controller
   toggles / queries the state classes restyled below (is-selected on the
   active definition row). The create / clone dialogs carry the .app-screen
   root class so the same --t-* tokens resolve when appended to the modal
   root.

   LIVE PREVIEW: the preview reads the definition's sections and renders a
   summary of them with design-system components. This stylesheet only places
   that pane; it never restyles the components inside it. See
   docs/FRONTEND-ARCHITECTURE.md.
   ============================================================ */

@layer layout {
  /* Page shell: intro, then a two-pane list / editor layout. */
  .admin-screens { display: grid; gap: var(--mea-space-5); align-content: start; }

  /* Page intro: heading block on the left, actions on the right. */
  .admin-screens__intro { display: flex; flex-wrap: wrap; align-items: flex-start;
                          justify-content: space-between; gap: var(--mea-space-3); }
  .admin-screens__heading { display: grid; gap: var(--mea-space-1); min-inline-size: 0; }
  .admin-screens__title, .admin-screens__subtitle { margin: 0; min-inline-size: 0; }
}

@layer design {
  /* .admin-screens__title is the page intro heading. Its default is the card
     text (--t-text, dark); only the intro heading is repainted below. */
  .admin-screens__title { font-family: var(--mea-font-citizen); font-size: var(--mea-text-2xl);
                          font-weight: var(--mea-w-bold); color: var(--t-text); }

  /* The page intro sits directly on the desk page background (--t-bg, the dark
     page), NOT on a card. --t-text there would be dark-on-dark.
     --t-text-inverse is the desk's on-dark text (white), so the intro reads
     like every .dashboard__intro. (mea-web's web.css now also gives the desk
     .app-screen light --t-bg-text*, so text with no colour of its own reads on
     the dark page; this rule predates that.) The subtitle is muted by opacity, not a second
     color token, to keep the title/subtitle hierarchy without a hardcoded shade. */
  .admin-screens__heading .admin-screens__title { color: var(--t-text-inverse); }
  .admin-screens__subtitle { font-size: var(--mea-text-md); color: var(--t-text-inverse); opacity: .72; }
}

/* The single-form settings pages built from design-system components. This
   sheet only places them: the cards are panes, the fields and buttons are
   components, and every rule hangs on the page's domain-concept class. */
@layer layout {
  .admin-citation-phone { display: grid; gap: var(--t-space-5); align-content: start; }

  .admin-citation-phone .intro { display: flex; flex-wrap: wrap; align-items: flex-start;
                                 justify-content: space-between; gap: var(--t-space-3); }

  .admin-citation-phone .settings-form { display: grid; gap: var(--t-space-4); }

  /* The choice's own label and its help line stack, as the base's field grid
     did; the checkbox keeps the row to itself. */
  .admin-citation-phone .choice > span { display: grid; gap: var(--t-space-1); min-inline-size: 0; }
  .admin-citation-phone .choice .help { font-size: var(--t-font-size-sm); }

  .admin-officer-notifications { display: grid; gap: var(--t-space-5); align-content: start; }

  .admin-officer-notifications .intro { display: flex; flex-wrap: wrap; align-items: flex-start;
                                        justify-content: space-between; gap: var(--t-space-3); }

  .admin-officer-notifications .settings-form { display: grid; gap: var(--t-space-4); }
  .admin-officer-notifications .choice > span { display: grid; gap: var(--t-space-1); min-inline-size: 0; }
  .admin-officer-notifications .choice .help { font-size: var(--t-font-size-sm); }

  /* The transitions group leads with the section-scale heading the base's
     editor title had, and its choices share a grid as width allows. */
  .admin-officer-notifications .transitions:is(fieldset) { display: grid; gap: var(--t-space-3); }
  .admin-officer-notifications .transitions > legend { font-size: var(--t-font-size-lg);
                                                       font-weight: var(--t-font-weight-bold); }

  .admin-officer-notifications .transition-grid { display: grid; gap: var(--t-space-3);
                                                  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }

  .admin-session-policies { display: grid; gap: var(--t-space-5); align-content: start; }

  .admin-session-policies .intro { display: flex; flex-wrap: wrap; align-items: flex-start;
                                   justify-content: space-between; gap: var(--t-space-3); }
  .admin-session-policies .actions { display: flex; flex-wrap: wrap; gap: var(--t-space-2);
                                     flex-shrink: 0; max-inline-size: 100%; }

  /* One card per role, as width allows. The rows component draws the cards;
     this page only says how many stand side by side and how much air each
     card's stack of ceiling, form and save gets. */
  .admin-session-policies .rows.cards { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
                                        gap: var(--t-space-4); }
  .admin-session-policies .rows.cards > .row > .main { gap: var(--t-space-3);
                                                       align-content: start; }
  .admin-session-policies .ceiling { margin: 0; font-size: var(--t-font-size-sm); }
  .admin-session-policies .policy-form { display: grid; gap: var(--t-space-3); }

  .admin-program-config { display: grid; gap: var(--t-space-5); align-content: start; }

  .admin-program-config .intro { display: flex; flex-wrap: wrap; align-items: flex-start;
                                 justify-content: space-between; gap: var(--t-space-3); }
  .admin-program-config .actions { display: flex; flex-wrap: wrap; gap: var(--t-space-2);
                                   flex-shrink: 0; max-inline-size: 100%; }

  .admin-program-config .settings-form { display: grid; gap: var(--t-space-4); }

  /* The title, its subtitle and the explanatory lines under it are one block,
     so they stay together when the intro wraps beside the actions. */
  :is(.admin-citation-phone, .admin-officer-notifications,
      .admin-session-policies, .admin-program-config) .intro-copy {
    display: grid; gap: var(--t-space-1); min-inline-size: 0;
    /* It takes the room the actions leave, so a long explanatory line wraps
       inside it instead of pushing Refresh onto a line of its own. */
    flex: 1 1 20rem;
  }

  /* On these four settings pages the base drew the submit at its own width
     at the start of the form, not across it. */
  :is(.admin-citation-phone, .admin-officer-notifications, .admin-program-config)
    .settings-form > .button.primary,
  :is(.admin-citation-phone, .admin-officer-notifications, .admin-program-config)
    .settings-form > button.primary,
  .admin-session-policies .policy-form > :is(button, .button).primary {
    justify-self: start;
  }

  /* An explanatory line under the page title is plain page text. The base drew
     it directly on the page, not inside a callout box; it takes the page
     surface's muted ink. */
  :is(.admin-citation-phone, .admin-officer-notifications,
      .admin-session-policies, .admin-program-config) .intro-note {
    margin: var(--t-space-2) 0 0; font-size: var(--t-font-size-sm);
    color: var(--c-surface-text-color-muted);
  }

  /* A sentence that introduces a whole pane sits in the pane as plain text, so
     it keeps the card's ink and takes no box of its own. */
  .admin-program-config .pane-note { margin: 0; }

  /* One card per offering, as width allows, and its two action groups. The
     rows component draws each card; this page only says how many stand side
     by side and how much air the card's own stack of title, form and actions
     gets. */
  .admin-program-config .rows.cards { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
                                      gap: var(--t-space-4); }
  .admin-program-config .rows.cards > .row > .main { gap: var(--t-space-3);
                                                     align-content: start; }
  .admin-program-config .offering-ops { display: flex; flex-wrap: wrap; gap: var(--t-space-2); }
}

/* The admin catalog pages (agency codes, penal codes, eligibility gates) and
   their create/edit forms. This sheet only places them: the cards are panes,
   the lists are data tables or row cards, the fields and buttons are
   components, and every rule hangs on the page's domain-concept class. */
@layer layout {
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) {
    display: grid; gap: var(--t-space-5); align-content: start;
  }

  /* Page intro: the title block takes the room the actions leave, so a long
     explanatory line wraps beside them instead of pushing the actions down. */
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .intro {
    display: flex; flex-wrap: wrap; align-items: flex-start;
    justify-content: space-between; gap: var(--t-space-3);
  }

  /* The title, its subtitle and the explanatory lines under it are one block,
     so they stay together when the intro wraps beside the actions. */
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .intro-copy {
    display: grid; gap: var(--t-space-3); min-inline-size: 0;
    flex: 1 1 20rem;
  }

  /* An explanatory line under the page title is plain page text. The base drew
     it directly on the page, not inside a callout box; it takes the page
     surface's muted ink. */
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .intro-note {
    margin: 0; font-size: var(--t-font-size-sm);
  }

  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .actions {
    display: flex; flex-wrap: wrap; gap: var(--t-space-2);
    flex-shrink: 0; max-inline-size: 100%;
  }

  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .settings-form {
    display: grid; gap: var(--t-space-4);
  }

  /* A sentence that introduces a whole pane sits in the pane as plain text, so
     it keeps the card's ink and takes no box of its own. */
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .pane-note { margin: 0; }

  /* The rule set's full content hash is one unbroken string; it breaks
     anywhere so it stays inside the pane on a phone. */
  .admin-eligibility-gates .pane-note code { overflow-wrap: anywhere; }

  /* One card per code, as width allows. The rows component draws the cards;
     this page only says how many stand side by side and how much air each
     card's own stack of title, form and actions gets. */
  .admin-agency-codes .rows.cards { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
                                    gap: var(--t-space-4); }
  .admin-agency-codes .rows.cards > .row > .main { gap: var(--t-space-3);
                                                   align-content: start; }
  .admin-agency-codes .agency-ops { display: flex; flex-wrap: wrap; gap: var(--t-space-2); }

  /* The base drew Add code at its own width at the start of the form, not
     across it. */
  .admin-agency-codes .settings-form > :is(button, .button).primary { justify-self: start; }

  /* Rule sets stay a sidebar beside the selected set's gates on a desk, and
     stack only when the column is too narrow for two. */
  .admin-eligibility-gates .layout {
    display: grid; gap: var(--t-space-5); align-items: start;
    grid-template-columns: minmax(16rem, 22rem) 1fr;
  }
  @container (max-width: 52rem) {
    .admin-eligibility-gates .layout { grid-template-columns: minmax(0, 1fr); }
  }

  /* A flush pane's empty state pads itself, since the pane sets no padding. */
  .admin-eligibility-gates .list-empty { padding: var(--t-space-4) var(--t-space-5); }

  /* The base drew Add Rule and Activate at their own width at the start of
     their forms, not across them. */
  .admin-eligibility-gates .settings-form > :is(button, .button).primary { justify-self: start; }

  /* The editor column stacks its panes under the catalog table. */
  /* min-inline-size: 0 lets the column shrink below its table's width, so the
     table scrolls inside its own region instead of pushing the pane off the
     page. */
  :is(.admin-penal-codes, .admin-eligibility-gates) .editor-col {
    display: grid; gap: var(--t-space-5); align-content: start; min-inline-size: 0;
  }

  /* The catalog search and its empty state sit inside a flush pane, so they
     keep the pane body's padding while the table's dividers run to the edges. */
  .admin-penal-codes .catalog-search,
  .admin-penal-codes .catalog-empty {
    padding: var(--t-space-4) var(--t-space-5);
  }

  /* A step's slug is an annotation beside its name, the way the base set it. */
  .admin-penal-codes .step-code {
    font-size: var(--t-font-size-sm);
  }

  /* The base drew the offense editor's Save at its own width; the wizard,
     remedy and upload submits it drew across their forms. */
  .admin-penal-codes .editor-form > :is(button, .button).primary { justify-self: start; }

  /* A knowledge-check group stacks its questions, and each question stacks its
     fields, the way the base's nested fieldsets did. */
  .admin-education fieldset.field {
    display: grid; gap: var(--t-space-4); margin: 0; padding: 0; border: 0;
  }
  /* A legend is not a grid item, so the fieldset's gap never reaches below
     it; it carries its own space down to the first field. */
  .admin-education fieldset.field > legend {
    margin-block-end: var(--t-space-3);
    font-size: var(--t-font-size-lg); font-weight: var(--t-font-weight-bold);
  }
  .admin-education fieldset.field fieldset.field {
    padding-inline-start: var(--t-space-4);
    border-inline-start-width: var(--t-border-width-interactive);
  }
  .admin-education fieldset.field fieldset.field > legend {
    font-size: var(--t-font-size-md);
  }

  /* The way back sits above the page title, as the base drew it. */
  .admin-education .back { margin: 0; }

  /* Add Rule is its own titled section in the editor: its heading, then its
     form, with the editor's spacing between them. */
  .admin-eligibility-gates .add-rule { display: grid; gap: var(--t-space-3); }
}

/* The screen-definition list and its create/clone form, built from
   design-system components. This sheet only places them: the cards are panes,
   the list is a data table, the fields and buttons are components, and every
   rule hangs on the page's domain-concept class. */
@layer layout {
  .admin-screens .intro {
    display: flex; flex-wrap: wrap; align-items: flex-start;
    justify-content: space-between; gap: var(--t-space-3);
  }

  /* The title block takes the room the actions leave, so a long explanatory
     line wraps beside them instead of pushing the actions down. */
  .admin-screens .intro-copy {
    display: grid; gap: var(--t-space-1); min-inline-size: 0; flex: 1 1 20rem;
  }

  .admin-screens .actions {
    display: flex; flex-wrap: wrap; gap: var(--t-space-2);
    flex-shrink: 0; max-inline-size: 100%;
  }

  /* The definitions table takes the full width, and the editor sits below
     it, so the table's columns never scroll on a desk. */
  .admin-screens .screen-defs-layout {
    display: grid; gap: var(--t-space-5); align-items: start;
    grid-template-columns: minmax(0, 1fr);
  }

  /* A flush pane's empty state pads itself. */
  .admin-screens .list-empty { padding: var(--t-space-4) var(--t-space-5); }

  .admin-screens .screen-defs-editor {
    display: grid; gap: var(--t-space-5); align-content: start; min-inline-size: 0;
  }

  .admin-screens .settings-form { display: grid; gap: var(--t-space-4); }

  /* The preview form holds only hidden fields; its button is in the row. */
  .admin-screens .preview-form { display: none; }


  .admin-screens .preview-meta { margin: 0; }

  /* The sections field holds JSON, as the base's code field did. */
  /* The field component sets every control's font at (0,3,1); this rule has
     to outrank it for the JSON box to stay monospace. */
  .admin-screens .field textarea.input.code-input {
    font-family: var(--t-font-family-mono); font-size: var(--t-font-size-sm);
  }

  /* The create/clone card is one column, as the base's dialog was, and its
     submit spans the form. */
  .admin-screens .screen-def-form-pane { max-inline-size: 32rem; }
  .admin-screens .wide-submit { inline-size: 100%; }
}

/* The catalog pages' paint: the muted ink of the intro lines and step slugs,
   and the rule that sets a nested question group in from its course. */
@layer design {
  :is(.admin-agency-codes, .admin-penal-codes, .admin-eligibility-gates,
      .admin-penal-codes-form, .admin-eligibility-gates-form,
      .admin-education) .intro-note,
  .admin-penal-codes .step-code {
    color: var(--c-surface-text-color-muted);
  }

  .admin-education fieldset.field fieldset.field {
    border-inline-start-style: solid;
    border-inline-start-color: var(--t-border);
  }
}

/* The identity-provider admin pages, built from design-system components.
   This sheet only places them: the cards are panes, the lists are row cards
   or data tables, the fields and buttons are components, and every rule hangs
   on the page's domain-concept class. */
@layer layout {
  :is(.admin-identity-providers, .admin-identity-provider-attributes,
      .admin-identity-provider-certificate-remove,
      .admin-identity-provider-certificates, .admin-identity-provider-form,
      .admin-identity-provider-portals, .admin-identity-provider-prelink,
      .admin-identity-provider-probe, .admin-identity-provider-role-mappings,
      .admin-identity-provider-roster-import) {
    display: grid; gap: var(--t-space-5); align-content: start;
  }

  /* The page header is the page-header component. A pane's own row of links,
     such as the probe's re-run or the service-provider downloads, wraps its
     links at their own width. */
  :is(.admin-identity-provider-form, .admin-identity-provider-probe) .pane .actions {
    display: flex; flex-wrap: wrap; gap: var(--t-space-2);
    max-inline-size: 100%;
  }

  /* A form's fields stack, and its action sits under them. */
  :is(.admin-identity-provider-certificates,
      .admin-identity-provider-certificate-remove,
      .admin-identity-provider-form, .admin-identity-provider-portals,
      .admin-identity-provider-prelink, .admin-identity-provider-probe,
      .admin-identity-provider-role-mappings,
      .admin-identity-provider-roster-import) .settings-form {
    display: grid; gap: var(--t-space-4);
  }

  /* Every submit on these pages sits at its own width at the start of its
     form, as the base's action row drew it, never across the form. */
  :is(.admin-identity-provider-certificates,
      .admin-identity-provider-certificate-remove,
      .admin-identity-provider-form, .admin-identity-provider-portals,
      .admin-identity-provider-prelink, .admin-identity-provider-probe,
      .admin-identity-provider-role-mappings,
      .admin-identity-provider-roster-import)
    .settings-form > :is(button, .button) {
    justify-self: start;
  }

  /* One card per provider or group, as width allows. The rows component draws
     the cards; this page only says how many stand side by side and how much
     air each card's own stack of title, details and actions gets. */
  :is(.admin-identity-providers, .admin-identity-provider-portals,
      .admin-identity-provider-role-mappings) .rows.cards {
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--t-space-4);
  }

  :is(.admin-identity-providers, .admin-identity-provider-portals,
      .admin-identity-provider-role-mappings) .rows.cards > .row > .main {
    gap: var(--t-space-3); align-content: start;
  }

  /* The doors an identity provider can serve, side by side as width allows. */
  .admin-identity-provider-portals .door-grid {
    display: grid; gap: var(--t-space-2);
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  }

  /* A certificate's full SHA-256 fingerprint is one unbroken string. It wraps
     inside its pane on a narrow screen instead of forcing the pane wider than
     the phone and clipping itself and the note under it. */
  .admin-identity-provider-certificate-remove .certificate-fingerprint {
    overflow-wrap: anywhere;
  }
}

/* The portal-admin pages (appointments, grantable capabilities, grants under
   review), built from design-system components. This sheet only places them:
   the cards are panes, the rows are card rows, the fields and buttons are
   components, and every rule hangs on the page's domain-concept class. */
@layer layout {
  :is(.admin-portal-appointments, .admin-portal-grantable-capabilities,
      .admin-portal-grants-under-review) {
    display: grid; gap: var(--t-space-5); align-content: start;
  }

  /* A form's fields stack, and its submit sits at its own width at the start,
     as the base drew it. */
  :is(.admin-portal-appointments, .admin-portal-grantable-capabilities,
      .admin-portal-grants-under-review) .settings-form {
    display: grid; gap: var(--t-space-4);
  }
  :is(.admin-portal-appointments, .admin-portal-grantable-capabilities,
      .admin-portal-grants-under-review)
    .settings-form > :is(button, .button) {
    justify-self: start;
  }

  /* One card per appointment, portal or flagged grant, as width allows. The
     rows component draws the cards; this page only says how many stand side
     by side and how much air each card's own stack gets. */
  :is(.admin-portal-appointments, .admin-portal-grantable-capabilities,
      .admin-portal-grants-under-review) .rows.cards {
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--t-space-4);
  }
  :is(.admin-portal-appointments, .admin-portal-grantable-capabilities,
      .admin-portal-grants-under-review) .rows.cards > .row > .main {
    gap: var(--t-space-3); align-content: start;
  }

  /* A row's one action sits at its own width at the start, as the base drew
     it. */
  :is(.admin-portal-appointments, .admin-portal-grants-under-review)
    .revoke-form {
    margin: 0; justify-self: start;
  }

  /* A legend is not a grid item, so the fieldset's gap never reaches below
     it; it carries its own space down to the first choice. */
  .admin-portal-grantable-capabilities fieldset.field > legend {
    margin-block-end: var(--t-space-3);
  }

  /* Each capability is one choice, stacked so a long name stays on its line.
     The choices stay a list, as on the base, so a screen reader counts them;
     the list draws no bullets or indent of its own. */
  .admin-portal-grantable-capabilities .capability-grid {
    display: grid; gap: var(--t-space-2);
    margin: 0; padding: 0; list-style: none;
  }
}
