/* Onboarding — the welcome dialog a new company opens on, and the screens the
   set-up runs through: the company, the invoices, the summary. */

@layer components {

  /* ─── The dialog ─────────────────────────── */

  /* `display` is set only under `[open]`: a closed `<dialog>` would otherwise
     override the UA's `display: none` and stay on the page. */
  .onb {
    background: none;
    block-size: 100dvh;
    border: none;
    inline-size: 100dvw;
    max-block-size: 100dvh;
    max-inline-size: 100dvw;
    padding: 0;
  }

  /* Centred while it fits, scrolled from the top when it does not: `auto`
     margins on the panel centre it, and collapse to nothing once it is taller
     than the dialog. `place-items: center` would clip its head instead, with
     nothing to scroll back to. */
  .onb[open] {
    display: grid;
    overflow-y: auto;
  }

  /* Opaque, not a dimmed view of the app: setting up is the whole task while
     it lasts, and a page showing through it only competes for the eye. */
  .onb::backdrop {
    background: var(--color-canvas);
  }

  .onb__panel {
    margin: auto;
    max-inline-size: 68rem;
    padding: 2rem 1.25rem 3rem;
    position: relative;

    @media (width >= 768px) {
      padding: 3rem 2rem;
    }
  }

  .onb__head {
    margin-block-end: 2.5rem;
    text-align: center;
  }

  .onb__logo {
    display: flex;
    justify-content: center;
    margin-block-end: 1.75rem;
  }

  .onb__title {
    color: var(--color-ink);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0;
    text-wrap: balance;

    @media (width >= 768px) {
      font-size: 2.5rem;
    }
  }

  .onb__subtitle {
    color: var(--color-ink-muted);
    font-size: 1rem;
    margin: 0.625rem 0 0;
  }

  /* ─── The cross ──────────────────────────── */

  /* A form, since closing the onboarding is a change on the server: in the
     dialog's corner, or the head's third column on a step. */
  .onb-close--dialog {
    inset-block-start: 1rem;
    inset-inline-end: 1rem;
    position: absolute;
  }

  .onb-close--head {
    grid-column: 3;
    justify-self: end;
  }

  .onb-close__btn {
    align-items: center;
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-pill);
    block-size: 40px;
    color: var(--color-ink-muted);
    cursor: pointer;
    display: flex;
    inline-size: 40px;
    justify-content: center;
    padding: 0;
  }

  .onb-close__btn:hover {
    border-color: var(--color-border-strong);
    color: var(--color-ink);
  }

  .onb-close__btn:focus-visible {
    box-shadow: var(--shadow-focus);
    outline: none;
  }

  /* ─── The three ways in ──────────────────── */

  .onb__choices {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr);
    list-style: none;
    margin: 0;
    padding: 0;

    /* Three even columns that stay even whatever the copy: a bare `1fr` is
       `minmax(auto, 1fr)`, so the longest card would take more than a third. */
    @media (width >= 1024px) {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  .onb-choice {
    background: var(--color-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-xl);
    /* The action sits at the foot of every card, level across the row, however
       many lines the text above it runs to. */
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    padding: 1.5rem;
  }

  /* The way in that takes a file: dashed, like the invoice's add-line-item
     button, so it reads as a place to drop something. */
  .onb-choice--dashed {
    border: 1.5px dashed var(--color-border-strong);
  }

  .onb-choice__step {
    align-items: center;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-pill);
    block-size: 26px;
    color: var(--color-ink-muted);
    display: flex;
    font-size: 0.8125rem;
    font-weight: 600;
    inline-size: 26px;
    justify-content: center;
  }

  .onb-choice__icon {
    align-items: center;
    background: var(--color-brand-tint);
    border-radius: var(--radius-md);
    block-size: 44px;
    color: var(--color-brand);
    display: flex;
    inline-size: 44px;
    justify-content: center;
    margin-block-start: 1.25rem;
  }

  .onb-choice__title {
    color: var(--color-ink);
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 1.25rem 0 0;
    text-wrap: balance;
  }

  .onb-choice__text {
    color: var(--color-ink-muted);
    font-size: 0.9375rem;
    line-height: 1.55;
    margin: 0.625rem 0 0;
  }

  .onb-choice__action {
    margin-block-start: 1.5rem;
  }

  /* The file input covers its label so the whole pill is the picker, and stays
     in the layout so the keyboard still reaches it. */
  .onb-choice__file {
    block-size: 100%;
    cursor: pointer;
    inline-size: 100%;
    inset: 0;
    opacity: 0;
    position: absolute;
  }

  /* ─── The registry search ────────────────── */

  /* A search the registry answers with nothing: the shared list hides itself
     and its own "nothing found" message stays out of sight; in its place the
     welcome dialog offers the long way in, the way its third card does. */
  .onb-search .inv-sug-results:has(.inv-sug-empty) {
    display: block;
  }

  .onb-search .inv-sug-empty,
  .onb-search__manual {
    display: none;
  }

  .onb-search .inv-sug-results:has(.inv-sug-empty) .onb-search__manual {
    align-items: center;
    color: var(--color-brand);
    display: flex;
    font-size: 0.9375rem;
    font-weight: 600;
    gap: 0.375rem;
    padding: 0.75rem 0.875rem;
    text-decoration: none;
  }

  .onb-search__manual:hover,
  .onb-search__manual[aria-selected="true"] {
    background: var(--color-surface-tint);
  }

  /* ─── Buttons ────────────────────────────── */

  .onb-btn {
    display: flex;
    position: relative;
  }

  /* ─── The standalone step screens ────────── */

  /* The page grid reserves the app navigation's height at the top of every
     body; these screens have no navigation, so the reservation was a blank
     band above the head — a whole thumb's worth on a phone. */
  .onb-body {
    padding-block-start: 0;
  }

  .onb-page {
    margin-inline: auto;
    max-inline-size: 44rem;
    padding: 1.5rem 1rem 4rem;
  }

  .onb-page__head {
    align-items: center;
    display: grid;
    /* The logo stays centred on the page whatever the two sides' width. */
    grid-template-columns: 1fr auto 1fr;
    margin-block-end: 1.75rem;
  }

  .onb-page__logo {
    display: flex;
    grid-column: 2;
    justify-content: center;
  }

  .onb-back {
    color: var(--color-ink-secondary);
    justify-self: start;
  }

  .onb-back:hover {
    border-color: var(--color-border-strong);
    color: var(--color-ink);
  }

  .onb-progress {
    display: flex;
    gap: 0.5rem;
    margin-block-end: 1.5rem;
  }

  .onb-progress__segment {
    background: var(--color-brand-tint);
    block-size: 4px;
    border-radius: var(--radius-pill);
    flex: 1;
  }

  .onb-progress__segment.is-done {
    background: var(--color-brand);
  }

  .onb-card {
    padding: 1.75rem 1.25rem;

    @media (width >= 768px) {
      padding: 2.5rem;
    }
  }

  .onb-card__step {
    color: var(--color-brand);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    margin: 0 0 0.625rem;
    text-transform: uppercase;
  }

  .onb-card__title {
    color: var(--color-ink);
    font-size: 1.875rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0;
    text-wrap: balance;
  }

  .onb-card__subtitle {
    color: var(--color-ink-muted);
    font-size: 0.9375rem;
    line-height: 1.55;
    margin: 0.5rem 0 1.75rem;
  }

  .onb-card__actions {
    display: flex;
    margin-block-start: 1.75rem;
  }

  /* A button with a quiet way back beside it. */
  .onb-card__actions--pair {
    align-items: center;
    gap: 1rem;
  }

  /* ─── Fields ─────────────────────────────── */

  .onb-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-block-end: 1rem;
    min-inline-size: 0;
  }

  .onb-label {
    font-size: 0.75rem;
    font-weight: 700;
  }

  .onb-label--block {
    display: block;
    margin-block-end: 0.5rem;
  }

  /* "optional" beside a label: the field may be left empty. */
  .onb-label__hint {
    color: var(--color-ink-faint);
    font-weight: 500;
    text-transform: none;
  }

  .onb-input {
    block-size: 52px;
    font-size: 1rem;
  }

  /* The numbering run: the year, shown but not the company's to change. */
  .onb-input--readonly {
    background: var(--color-surface-tint);
    color: var(--color-ink-muted);
  }

  .onb-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr);

    @media (width >= 768px) {
      &.onb-grid--two {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      &.onb-grid--three {
        grid-template-columns: repeat(3, minmax(0, 1fr));
      }
    }
  }

  .onb-rule {
    border: none;
    border-block-start: 1px solid var(--color-border-subtle);
    margin: 1.5rem 0;
  }

  /* ─── What the invoice read said ─────────── */

  .onb-found {
    align-items: center;
    color: var(--color-positive);
    display: flex;
    font-size: 0.875rem;
    font-weight: 600;
    gap: 0.375rem;
    margin: 0 0 1.25rem;
  }

  .onb-reading {
    align-items: center;
    border-radius: var(--radius-md);
    display: flex;
    font-size: 0.875rem;
    font-weight: 600;
    gap: 0.5rem;
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem;
  }

  /* The read under way stands in for the form: the mascot at its laptop,
     the word under it, both centred. */
  .onb-reading--pending {
    color: var(--color-brand);
    flex-direction: column;
    gap: 1.25rem;
    justify-content: center;
    margin: 0;
    padding: 2.5rem 1rem;
    text-align: center;
  }

  .onb-reading__text {
    margin: 0;
  }

  .onb-reading--failed {
    background: var(--color-negative-tint);
    color: var(--color-negative-strong);
  }

  /* ─── The summary's checklist ────────────── */

  .onb-check {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .onb-check__row {
    align-items: center;
    background: var(--color-surface-tint);
    border-radius: var(--radius-md);
    display: flex;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
  }

  .onb-check__mark {
    color: var(--color-positive);
    display: flex;
    flex-shrink: 0;
  }

  .onb-check__label {
    color: var(--color-ink-muted);
    font-size: 0.9375rem;
  }

  .onb-check__value {
    align-items: center;
    display: flex;
    gap: 0.375rem;
    margin-inline-start: auto;
    min-inline-size: 0;
  }

  .onb-check__text {
    color: var(--color-ink);
    display: flex;
    flex-direction: column;
    font-size: 0.9375rem;
    font-weight: 700;
    text-align: end;
  }

  .onb-check__meta {
    color: var(--color-ink-muted);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 400;
  }

  /* ─── What is left for later ─────────────── */

  .onb-later {
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-lg);
    margin-block-start: 1.25rem;
    padding: 1rem 1.25rem;
  }

  .onb-later__title {
    color: var(--color-ink);
    font-size: 0.9375rem;
    font-weight: 700;
    margin: 0 0 0.375rem;
  }

  .onb-later__text {
    color: var(--color-ink-muted);
    font-size: 0.9375rem;
    line-height: 1.55;
    margin: 0;
  }

  /* ─── E-invoicing, asked for with the company ─ */

  .onb-peppol {
    align-items: flex-start;
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    gap: 0.75rem;
    margin-block-start: 1.25rem;
    padding: 1rem 1.25rem;

    input {
      accent-color: var(--color-brand);
      block-size: 1.125rem;
      flex: none;
      inline-size: 1.125rem;
      margin-block-start: 0.125rem;
    }
  }

  .onb-peppol__title {
    color: var(--color-ink);
    display: block;
    font-size: 0.9375rem;
    font-weight: 700;
  }

  .onb-peppol__text {
    color: var(--color-ink-muted);
    display: block;
    font-size: 0.875rem;
    line-height: 1.5;
  }

  /* ─── Hints under a field ────────────────── */

  .onb-hint {
    color: var(--color-ink-muted);
    font-size: 0.875rem;
    margin: 0.5rem 0 0;
  }

  .onb-hint__value {
    color: var(--color-ink);
    font-family: var(--font-mono);
  }

  /* ─── Payment terms ──────────────────────── */

  .onb-due {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* A pill over its radio, two lines: the number is what the eye picks out,
     the unit only says what the number means. */
  .onb-due__option {
    align-items: center;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    justify-content: center;
    min-inline-size: 4.5rem;
    padding: 0.625rem 0.875rem;
    position: relative;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }

  .onb-due__option:hover {
    border-color: var(--color-border-strong);
  }

  .onb-due__option:has(input[type="radio"]:checked) {
    background: var(--color-brand-tint);
    border-color: var(--color-brand);
  }

  .onb-due__option:has(:focus-visible) {
    box-shadow: var(--shadow-focus);
    outline: none;
  }

  .onb-due__number {
    color: var(--color-ink);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.1;
  }

  .onb-due__option:has(input[type="radio"]:checked) .onb-due__number,
  .onb-due__option:has(input[type="radio"]:checked) .onb-due__unit {
    color: var(--color-brand);
  }

  .onb-due__unit {
    color: var(--color-ink-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  /* The typed one: wide enough for two digits and the spinner Firefox
     reserves room for — at 3ch the second digit was clipped. */
  .onb-due__input {
    background: none;
    border: none;
    color: var(--color-ink);
    font-size: 1.25rem;
    font-weight: 700;
    inline-size: 4ch;
    padding: 0;
    text-align: center;
  }

  .onb-due__input:focus {
    outline: none;
  }

  /* ─── Links ──────────────────────────────── */

  .onb-link {
    color: var(--color-ink-muted);
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
  }

  .onb-link:hover {
    color: var(--color-ink);
  }
}
