/* ==========================================================================
   Home page: the scoping tool, its result, the two calls to action, the rules in plain words
   Loaded after css/site.css by the pages of this family ('styles' in render_page()).
   Conventions and tokens: css/README.md.

   Mobile first: the rules without a query are the phone, one column (form, result, the two calls to action,
   the rules). From 64em the tool has two columns. The conformity routes follow the width of the result card
   (container query), not the window. The cards, buttons, fields, badges and message boxes are the ones of
   site.css: only what is particular to this page is here.
   Markup: templates/views/home.php and, for everything that changes, js/cra-scoping.js.
   ========================================================================== */
@layer pages {
  /* ---- The page grid ---- */
  #cra-scoping {
    /* Text a person has to read (reasoning, descriptions, notes): 14px on a phone and a tablet; the two-column
       layout keeps the denser sizes it always had. */
    --home-text: var(--fs-md-plus);
    --home-text-dense: var(--fs-md-plus);

    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
    inline-size: 100%;
  }

  @media (min-width: 64em) {
    #cra-scoping {
      --home-text: var(--fs-sm-plus);
      --home-text-dense: var(--fs-xs-plus);

      grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
      align-items: stretch;
    }
  }

  /* ---- The form ---- */
  .search-fieldset {
    display: grid;
    gap: var(--space-4);
    min-inline-size: 0;   /* a fieldset is otherwise as wide as its longest word */
    border: 0;
  }

  .search-input-container {
    display: grid;
    gap: var(--space-1-5);
  }

  /* The description: a little lower than the textarea of the core, as it always was on this page */
  textarea.text-input-field {
    min-block-size: 7.5rem;
  }

  .kbd-shortcut {
    margin-inline-start: var(--space-1);
    font-size: max(0.75rem, 0.8em);
    opacity: 0.8;
  }

  /* ---- "Try:" examples ---- */
  .sample-pills-container {
    display: grid;
    gap: var(--space-2);
  }

  .sample-pills-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1-5);
  }

  .sample-label {
    margin-inline-end: var(--space-1);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-disabled);
  }

  .shuffle-samples-btn {
    background-color: var(--accent-tint-2);
    border-color: var(--border-accent-soft);
    color: var(--text-link);
  }

  /* ---- Recent scopings (a list: one row per scoping) ---- */
  .recent-scopes-stack {
    display: grid;
    gap: var(--space-1-5);
    list-style: none;
  }

  .recent-scope-standard {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-align: end;
    overflow-wrap: anywhere;
    color: var(--text-link);
  }

  .recent-scope-muted {
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--text-faint);
  }

  /* ---- The result column: empty, waiting, or the result ---- */
  .results-wrapper {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    inline-size: 100%;
    block-size: 100%;
  }

  .results-placeholder-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--space-2);
    block-size: 100%;
    padding: var(--space-8) var(--space-6);
    border: var(--border-width-strong) dashed var(--border-strong);
    border-radius: var(--radius-xl);
    background-color: var(--surface-sunken);
    text-align: center;
  }

  .placeholder-title {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text-strong);
  }

  .placeholder-description {
    max-inline-size: 22.5rem;
    font-size: var(--home-text);
    line-height: 1.5;
    color: var(--text-faint);
  }

  .spinner-container {
    display: grid;
    place-content: center;
  }

  .spinner-svg {
    inline-size: 2.5rem;
    block-size: 2.5rem;
    animation: spin 1s linear infinite;
  }

  @keyframes spin {
    100% {
      transform: rotate(360deg);
    }
  }

  .spinner-path {
    stroke: var(--text-link);
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
  }

  @keyframes dash {
    0% {
      stroke-dasharray: 1, 150;
      stroke-dashoffset: 0;
    }
    50% {
      stroke-dasharray: 90, 150;
      stroke-dashoffset: -35;
    }
    100% {
      stroke-dasharray: 90, 150;
      stroke-dashoffset: -124;
    }
  }

  /* ---- The result: its head ---- */
  .result-category-label {
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-faint);
  }

  .evaluated-product-name {
    font-size: var(--fs-3xl);
    font-weight: 800;
    overflow-wrap: anywhere;   /* typed by the visitor: may be one long word */
    color: var(--text-strong);
  }

  .result-badge-holder {
    display: grid;
    gap: var(--space-1-5);
    justify-items: start;
  }

  /* 40em: where .result-header-row (site.css) puts the badge beside the name */
  @media (min-width: 40em) {
    .result-badge-holder {
      justify-items: end;
    }
  }

  .confidence-text {
    font-size: var(--fs-xs);
    color: var(--text-faint);
  }

  .confidence-value {
    font-weight: 700;
    color: var(--text-strong);
  }

  /* Why the confidence is what it is, and what is missing from the description */
  .confidence-basis {
    display: grid;
    gap: var(--space-1-5);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-lg);
    background-color: var(--surface-sunken);
    font-size: var(--home-text);
    line-height: 1.5;
    color: var(--text-strong);
  }

  .confidence-missing {
    display: grid;
    gap: var(--space-1);
    padding-inline-start: var(--space-5);
  }

  /* ---- The result: "Looks correct" / "I don't agree", and the reassessment form ---- */
  .reassessment-action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
  }

  .disagreement-title {
    color: var(--text-link);
  }

  /* The two buttons stay on one line, to the right; the text of the long one wraps when the card is narrow */
  .reassessment-form-actions {
    display: grid;
    grid-auto-flow: column;
    justify-content: end;
    gap: var(--space-2);
    margin-block-start: var(--space-2);
  }

  /* ---- The result: "Save to my product catalogue" ---- */
  .catalogue-save-row {
    display: grid;
    gap: var(--space-1-5);
    justify-items: end;
    margin-block-start: var(--space-3);
  }

  .catalogue-save-note,
  .catalogue-save-hint {
    font-size: var(--home-text);
    text-align: end;
    color: var(--text-muted);
  }

  .catalogue-save-note {
    font-weight: 600;
    color: var(--text-link);
  }

  .catalogue-save-note.is-error {
    color: var(--danger-text-strong);
  }

  .catalogue-save-note a {
    font-weight: 700;
    text-decoration: underline;
  }

  .catalogue-save-links {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: flex-end;
    gap: var(--space-1-5);
  }

  .catalogue-save-note .catalogue-save-link-primary {
    padding: var(--space-1) var(--space-2-5);
    border-radius: var(--radius-sm);
    background-color: var(--accent);
    color: var(--text-on-accent);
    text-decoration: none;
  }

  /* ---- The result: the category that matched ---- */
  .statutory-finding-reasoning {
    font-size: var(--home-text);
    line-height: 1.6;
    color: var(--text-muted);
  }

  .statutory-source-footer {
    padding-block-start: var(--space-2);
    border-block-start: var(--border-width) solid var(--border);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    overflow-wrap: anywhere;
    color: var(--text-faint);
  }

  .source-tag {
    font-weight: 700;
    color: var(--text-muted);
  }

  /* ---- The result: conformity routes ----
     One card under the other; side by side as soon as the result card gives them 28em (two cards of 13.5rem),
     whatever the width of the window. Without container queries they stay under each other. */
  .routes-section {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    container: routes / inline-size;
  }

  .routes-section-title {
    font-size: var(--fs-md);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-strong);
  }

  .routes-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }

  @container routes (min-width: 28em) {
    .routes-grid {
      grid-template-columns: none;
      grid-auto-flow: column;
      grid-auto-columns: minmax(0, 1fr);
    }
  }

  .route-card-primary,
  .route-card-secondary {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }

  .route-card-primary {
    border: var(--border-width-strong) solid var(--border-accent);
    background-color: var(--accent-tint-1);
  }

  .route-card-secondary {
    border: var(--border-width) solid var(--border-strong);
    background-color: var(--surface-card);
  }

  /* The kind of route and its standard: on one line while they fit, the standard under the badge when not
     (it is never cut in two) */
  .route-card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-2);
  }

  .route-badge-primary,
  .route-badge-secondary {
    padding: var(--space-1) var(--space-2);
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 800;
    line-height: 1.25;
  }

  .route-badge-primary {
    background-color: var(--accent);
    color: var(--text-on-accent);
  }

  .route-badge-secondary {
    background-color: var(--surface-muted);
    border-color: var(--border);
    color: var(--text);
  }

  .route-standard-code {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-link);
  }

  .route-method-title {
    margin-block-start: var(--space-1);
    font-size: var(--fs-lg-plus);
    font-weight: 700;
    color: var(--text-strong);
  }

  .route-description {
    font-size: var(--home-text-dense);
    line-height: 1.5;
    color: var(--text);
  }

  /* The same for the last line: the answer beside its label while they fit, under it when not */
  .route-footer-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-0-5) var(--space-2);
    padding-block-start: var(--space-2);
    font-size: var(--fs-xs);
    font-weight: 600;
  }

  .primary-footer {
    border-block-start: var(--border-width) solid var(--border-accent-soft);
  }

  .secondary-footer {
    border-block-start: var(--border-width) solid var(--border);
  }

  .status-mandatory {
    font-weight: 700;
    color: var(--warning-text);
  }

  .status-optional {
    font-weight: 700;
    color: var(--success-text-strong);
  }

  .status-neutral {
    font-weight: 700;
    color: var(--text-strong);
  }

  .notified-bodies-banner {
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-lg);
    background-color: var(--surface-sunken);
  }

  .notified-bodies-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-2);
  }

  .notified-bodies-label {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .notified-bodies-link {
    font-size: var(--fs-xs);
    font-weight: 700;
  }

  /* ---- One call to action under each column (scoping | results) ----
     A .scoping-card with less padding; the text takes the room so that both buttons line up across the two
     columns. The right-hand one is the paid service, highlighted like the Pro plan of the pricing page. */
  .next-step-card {
    grid-template-rows: 1fr auto;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
  }

  .next-step-under-results {
    border: var(--border-width-strong) solid var(--border-accent);
    background-color: var(--accent-tint-1);
  }

  .next-step-text {
    display: grid;
    align-content: start;
    gap: var(--space-1);
  }

  .next-step-title {
    font-size: var(--fs-lg-plus);
    font-weight: 700;
    color: var(--text-link);
  }

  .next-step-description {
    font-size: var(--home-text);
    line-height: 1.5;
    color: var(--text-muted);
  }

  /* ---- "Is my product in scope of the CRA?": the rules in plain words, under the tool ---- */
  .scope-guide {
    grid-column: 1 / -1;
    gap: var(--space-4);
    block-size: auto;
    font-size: var(--fs-lg);
    line-height: 1.6;
    color: var(--text);
  }

  .scope-guide-heading {
    margin-block-end: var(--space-1-5);
    font-size: var(--fs-lg-plus);
    font-weight: 700;
    color: var(--text-link);
  }

  .scope-guide-heading:not(:first-child) {
    margin-block-start: var(--space-4);
  }

  .scope-guide-list {
    display: grid;
    gap: var(--space-2);
    padding-inline-start: var(--space-4);
  }

  .scope-guide-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4) var(--space-8);
  }

  /* the same two columns as the tool above */
  @media (min-width: 64em) {
    .scope-guide-columns {
      grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    }
  }

  .scope-guide-note {
    padding-block-start: var(--space-3-5);
    border-block-start: var(--border-width) solid var(--border);
    font-size: var(--home-text);
    color: var(--text-muted);
  }

  /* ---- The result card when the script brings it into view ----
     It takes the focus so that a screen reader reads the result; it is a region, not a control, and gets no
     ring (as #main in site.css). The room for the sticky header comes from scroll-padding of the page. */
  #scoper-result-card:focus {
    outline: none;
  }

  /* ---- Pointer feedback: only where there is a pointer that hovers ---- */
  @media (hover: hover) {
    .shuffle-samples-btn:hover:not(:disabled) {
      background-color: var(--accent-tint-4);
      border-color: var(--border-accent-mid);
    }

    .catalogue-save-note .catalogue-save-link-primary:hover {
      background-color: var(--accent-hover);
      color: var(--text-on-accent);
    }
  }

  /* ---- Touch: the small links of the result are 44px to touch (an invisible area around them) ---- */
  @media (pointer: coarse) {
    .notified-bodies-link,
    .catalogue-save-link-primary {
      position: relative;
    }

    .notified-bodies-link::before,
    .catalogue-save-link-primary::before {
      content: "";
      position: absolute;
      inset: min(0rem, (100% - var(--target-min)) / 2);
    }
  }

  /* ---- Forced colours: what is drawn with a background only ---- */
  @media (forced-colors: active) {
    .route-badge-primary,
    .catalogue-save-link-primary {
      border: var(--border-width) solid CanvasText;
    }

    .spinner-path {
      stroke: CanvasText;
    }
  }

  /* ---- Paper: the result and the rules, not the tool around them ---- */
  @media print {
    #cra-scoping {
      display: block;
    }

    .search-fieldset,
    .sample-pills-container,
    .recent-scopes-box,
    .results-placeholder-card,
    .reassessment-action-row,
    .catalogue-save-row,
    .next-step-card {
      display: none;
    }

    .results-wrapper,
    .scope-guide {
      margin-block-end: var(--space-6);
    }
  }
}
