/* The pieces a screen is made of. Each is a class on its own block, with its parts as
   block__part and its variants as block--variant, and reads its colours from the tokens, so it
   follows light and dark and sits on any shell. */
@layer tokens, base, layout, components, screens;

@layer components {
  /* The product's name, top left of every shell. */
  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--ink);
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
  }

  .brand::before {
    content: "";
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 0.3125rem;
    background: var(--accent);
  }

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

  /* Buttons beyond the plain one in base.css. */
  .button--primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
  }

  .button--primary:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--accent-ink);
  }

  .button--danger {
    border-color: var(--danger);
    color: var(--danger);
  }

  .button--danger:hover {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
  }

  .button--quiet {
    min-height: 2.25rem;
    padding: var(--space-1) var(--space-3);
    border-color: transparent;
    background: transparent;
    color: var(--ink-soft);
    font-weight: 500;
  }

  .button--quiet:hover {
    border-color: var(--line-strong);
  }

  .button--block {
    width: 100%;
  }

  /* button_to wraps its button in a form; in a row of actions it must not break the row. */
  .button_to {
    display: flex;
    width: fit-content;
  }

  /* Things side by side that wrap when there is no room: actions, a title and its badge. */
  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
  }

  .cluster--apart {
    justify-content: space-between;
  }

  .cluster > * {
    margin-block-start: 0;
  }

  .muted {
    color: var(--ink-soft);
  }

  .eyebrow {
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  /* A label and its field, with an optional hint. */
  .field > * + * {
    margin-block-start: var(--space-1);
  }

  .field__hint {
    display: block;
    font-weight: 400;
  }

  /* Why a refused form refused this field, said in its label (Dashboard::HomeHelper#home_field). */
  .field__error {
    display: block;
    color: var(--danger);
    font-weight: 500;
  }

  .field--invalid :is(input, select, textarea) {
    border-color: var(--danger);
  }

  /* Read by assistive technology, not shown: an announcement, a label the eye does not need. */
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* The top of a page: its title and one line about it. */
  .page-header > * + * {
    margin-block-start: var(--space-2);
  }

  .page-header p {
    max-width: 42rem;
    color: var(--ink-soft);
  }

  /* A boxed part of a page. */
  .card {
    padding: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }

  .card--accent {
    border-color: var(--accent);
    box-shadow: inset 0.25rem 0 0 var(--accent);
  }

  .card--danger {
    border-color: var(--danger);
  }

  /* Cards side by side where there is room. */
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    gap: var(--space-4);
  }

  .grid > * {
    margin-block-start: 0;
  }

  /* A state in two words. */
  .badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem var(--space-3);
    border-radius: 999px;
    background: var(--sunken);
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
  }

  .badge--ok { background: var(--ok-soft); color: var(--ok); }
  .badge--warn { background: var(--warn-soft); color: var(--warn); }
  .badge--danger { background: var(--danger-soft); color: var(--danger); }

  /* A small note beside a name: "Soon", "Staff only". */
  .tag {
    display: inline-block;
    padding: 0 var(--space-2);
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
  }

  /* What the last action did, at the top of the page. */
  .flash {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border-inline-start: 0.25rem solid currentColor;
    font-weight: 500;
  }

  .flash--notice { background: var(--ok-soft); color: var(--ok); }
  .flash--alert { background: var(--danger-soft); color: var(--danger); }

  /* A state explained: what it is and what to do about it. */
  .callout {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    background: var(--sunken);
  }

  .callout > * + * {
    margin-block-start: var(--space-2);
  }

  .callout--ok { background: var(--ok-soft); }
  .callout--warn { background: var(--warn-soft); }
  .callout--danger { background: var(--danger-soft); }

  /* A table wider than a phone scrolls sideways inside this instead of widening the page. */
  .table-scroll {
    overflow-x: auto;
  }

  .table-scroll table {
    min-width: 34rem;
  }

  .table-scroll td form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .table-scroll td :is(select, input) {
    width: auto;
  }

  /* The dashboard's navigation (dashboard/_navigation). */
  .nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 0 var(--space-3) var(--space-4);
  }

  .nav__app {
    display: grid;
    gap: var(--space-1);
    margin: 0 var(--space-2) var(--space-4);
    padding: var(--space-3);
    border-radius: var(--radius);
    background: var(--sunken);
    overflow-wrap: anywhere;
  }

  .nav__app a {
    font-size: var(--text-sm);
  }

  .nav__panel {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--space-4);
  }

  .nav__heading {
    margin: 0 0 var(--space-1);
    padding-inline: var(--space-3);
    color: var(--ink-soft);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .nav__list {
    display: grid;
    gap: 0.125rem;
    padding: 0;
    list-style: none;
  }

  .nav__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: 2.5rem;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
  }

  a.nav__link:hover {
    background: var(--sunken);
    color: var(--ink);
  }

  .nav__link[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
  }

  .nav__link--soon {
    color: var(--ink-soft);
  }

  @media (max-width: 52rem) {
    .nav {
      padding: 0 var(--gutter);
    }

    .nav__app {
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      margin: 0 0 var(--space-3);
    }

    .nav__panel {
      display: none;
      padding-block-end: var(--space-4);
    }

    [data-menu-open] .nav__panel {
      display: flex;
    }
  }

  /* Who is signed in, the language, and the way out. */
  .account {
    display: grid;
    gap: var(--space-2);
    margin-block-start: auto;
    padding-block-start: var(--space-4);
    border-block-start: 1px solid var(--line);
    font-size: var(--text-sm);
  }

  .account > :is(.account__who, a) {
    padding-inline: var(--space-3);
  }

  .account__who {
    color: var(--ink-soft);
    overflow-wrap: anywhere;
  }

  .account--inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-2) var(--space-4);
    margin: 0;
    padding: 0;
    border: 0;
  }

  .account--inline > :is(.account__who, a) {
    padding-inline: 0;
  }

  .language {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
  }

  .language__current {
    padding: var(--space-1) var(--space-3);
    font-weight: 600;
  }

  /* The onboarding wizard: the steps on one side, the chosen step on the other. */
  .wizard {
    display: grid;
    grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
    align-items: start;
    gap: var(--space-5);
  }

  .wizard > * {
    margin-block-start: 0;
  }

  @media (max-width: 64rem) {
    .wizard {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  .steps {
    display: grid;
    gap: var(--space-1);
    padding: 0;
    list-style: none;
    counter-reset: step;
  }

  .steps__item {
    counter-increment: step;
  }

  .steps__link {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0 var(--space-3);
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
  }

  .steps__link:hover {
    background: var(--sunken);
    color: var(--ink);
  }

  .steps__link[aria-current="step"] {
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line-strong);
  }

  .steps__marker {
    display: grid;
    grid-row: span 2;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .steps__marker::before {
    content: counter(step);
  }

  .steps__item--done .steps__marker {
    border-color: var(--ok);
    background: var(--ok-soft);
    color: var(--ok);
  }

  .steps__item--done .steps__marker::before {
    content: "\2713";
  }

  .steps__item--current .steps__marker {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
  }

  .steps__title {
    font-weight: 600;
  }

  .steps__state {
    color: var(--ink-soft);
    font-size: var(--text-sm);
  }

  /* What to do, in order. */
  .how {
    display: grid;
    gap: var(--space-2);
  }

  .how > * {
    margin-block-start: 0;
  }

  /* A secret to copy: the connection key. */
  .key textarea {
    resize: vertical;
  }

  /* A list of things to pick one of: which app a store is for, which app to work on. */
  .choices {
    display: grid;
    gap: var(--space-2);
    padding: 0;
    list-style: none;
  }

  .choices > * {
    margin-block-start: 0;
  }

  .choices .button_to {
    display: flex;
  }

  .choices__button {
    flex: 1;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    font-weight: 400;
    text-align: start;
  }

  .choice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0 var(--space-3);
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    font-weight: 400;
    cursor: pointer;
  }

  .choice:has(:checked) {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
  }

  .choice__name {
    font-weight: 600;
  }

  .choice small {
    grid-column: 2;
  }

  /* The address a store gave, large enough to be read before it is trusted. */
  .address {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    background: var(--sunken);
    font-family: var(--font-mono);
    font-weight: 600;
    overflow-wrap: anywhere;
  }
}
