/*
 * The sign-in hero, the rest of the sign-in flow, and the error pages.
 *
 * The middleware loads this on standalone pages as well as the shell. The shell
 * needs it because an error page can arrive as an htmx fragment, and it holds
 * nothing but rc-auth and rc-error selectors, so it is inert on every other page.
 *
 * The hero is the one bold page in the product, and it is drawn from the mark,
 * so it uses the named brand values rather than the company theme. Controls on
 * it still come from --primary.
 */

html:not(#\#) {
  /* These pages have no Tailwind preflight of their own to rely on. */
  .rc-auth,
  .rc-auth *,
  .rc-error,
  .rc-error * {
    box-sizing: border-box;
  }

  /* The field ------------------------------------------------------------- */

  .rc-auth {
    --rc-hero-sky: var(--rc-signal-teal);
    --rc-hero-ground: color-mix(in srgb, var(--rc-signal-teal) 84%, var(--rc-deep-teal));
    --rc-hero-road: var(--rc-asphalt);

    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    overflow-x: hidden;
    min-height: 100vh;
    margin: 0;
    padding: 32px clamp(32px, 9vw, 136px);
    background: var(--rc-hero-sky);
    color: var(--foreground);
    font-family: var(--font-sans);
    font-size: var(--type-14);
    line-height: var(--leading-base);
  }

  &.dark .rc-auth {
    --rc-hero-sky: color-mix(in srgb, var(--rc-deep-teal) 62%, var(--rc-asphalt));
    --rc-hero-ground: color-mix(in srgb, var(--rc-deep-teal) 46%, var(--rc-asphalt));
    --rc-hero-road: #0B0E10;
  }

  /* The box clips, because below the tablet width the drawing is wider than
     the page, and overflow on <body> would not stop it adding to scrollWidth. */
  .rc-hero {
    position: absolute;
    inset: 0;
    overflow: hidden;
  }

  .rc-hero__road {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .rc-hero__sky {
    fill: var(--rc-hero-sky);
  }

  .rc-hero__ground {
    fill: var(--rc-hero-ground);
  }

  .rc-hero__asphalt {
    fill: var(--rc-hero-road);
  }

  .rc-hero__dash {
    fill: #fff;
  }

  /* The panel ------------------------------------------------------------- */

  .rc-auth__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
    box-shadow: var(--shadow-float);
    color: var(--card-foreground);
  }

  .rc-auth__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    color: var(--foreground);
    font-family: var(--font-display);
    font-size: var(--type-16);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 20px;

    img {
      width: 36px;
      height: 36px;
    }
  }

  .rc-auth__title {
    margin: 0 0 4px;
    color: var(--foreground);
    font-family: var(--font-display);
    font-size: var(--type-24);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 30px;
  }

  .rc-auth__sub {
    margin: 0 0 24px;
    color: var(--muted-foreground);
  }

  .rc-auth__form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0;
  }

  .rc-auth__field {
    display: flex;
    flex-direction: column;
    gap: 6px;

    label {
      color: var(--foreground);
      font-size: var(--type-13);
      font-weight: 500;
      line-height: 18px;
    }

    input {
      width: 100%;
      height: 36px;
      padding: 0 10px;
      border: 1px solid var(--input);
      border-radius: var(--radius-sm);
      background: var(--card);
      color: var(--foreground);
      font-size: var(--type-14);

      &::placeholder {
        color: var(--muted-foreground);
      }

      &:focus {
        outline: 2px solid var(--ring);
        outline-offset: 2px;
      }
    }

    .oh-input--password {
      padding-right: 40px;
    }

    .oh-password-input--toggle {
      position: absolute;
      top: 0;
      right: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 36px;
      height: 36px;
      padding: 0;
      border: 0;
      background: transparent;
      box-shadow: none;
      color: var(--muted-foreground);
      cursor: pointer;
    }
  }

  .rc-auth__row {
    display: flex;
    justify-content: flex-end;
    margin-top: -6px;
  }

  .rc-auth__link {
    color: var(--muted-foreground);
    font-size: var(--type-13);
    text-decoration: underline;
    text-underline-offset: 2px;

    &:hover {
      color: var(--foreground);
    }
  }

  .rc-auth__button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--primary-foreground);
    font-family: inherit;
    font-size: var(--type-14);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease;

    &:hover {
      background: var(--primary-700);
      color: var(--primary-foreground);
    }

    /* Never remove the ring without replacing it: on the Zoho page this is the
       only control, so keyboard users have nowhere else to go. */
    &:focus-visible {
      outline: 2px solid var(--ring);
      outline-offset: 2px;
    }
  }

  .rc-auth__button--quiet {
    border-color: var(--border);
    background: var(--card);
    color: var(--foreground);

    &:hover {
      background: var(--muted);
      color: var(--foreground);
    }
  }

  .rc-auth__setup {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }

  .rc-auth__note {
    margin: 14px 0 0;
    color: var(--muted-foreground);
    font-size: var(--type-13);
  }

  .rc-auth__alert {
    display: flex;
    gap: 10px;
    margin: 12px 0 20px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--stop-soft);
    color: var(--stop);
    font-size: var(--type-13);
    line-height: 18px;

    svg {
      flex: none;
      margin-top: 1px;
    }
  }

  .rc-auth__foot {
    margin: 24px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted-foreground);
    font-size: var(--type-13);
    text-align: center;

    a {
      color: inherit;
      text-decoration: underline;
      text-underline-offset: 2px;

      &:hover {
        color: var(--foreground);
      }
    }
  }

  .rc-auth__chip {
    display: inline-block;
    margin-bottom: 6px;
    padding: 0 8px;
    border-radius: var(--radius-full);
    background: var(--caution-soft);
    color: var(--caution);
    font-size: var(--type-12);
    font-weight: 500;
  }

  /* Tablet: the panel centres, so it sits on the road instead of beside it. */
  @media (max-width: 991.98px) {
    .rc-auth {
      justify-content: center;
    }

    .rc-hero__road {
      /* Keep the vanishing point on the page's centre line. It sits at 33.75% of
         the drawing, and the box keeps the drawing's own 1.6 aspect ratio. */
      --rc-road-height: max(100vh, 640px);

      left: calc(50vw - var(--rc-road-height) * .54);
      width: calc(var(--rc-road-height) * 1.6);
      height: var(--rc-road-height);
    }
  }

  /* Phone: the road on top, the panel as a sheet rising out of it. */
  @media (max-width: 639.98px) {
    .rc-auth {
      align-items: flex-end;
      padding: 0;
    }

    .rc-hero__road {
      --rc-road-height: 96vh;

      top: -34vh;
    }

    .rc-auth__panel {
      max-width: none;
      margin-top: 36vh;
      padding: 24px 20px 28px;
      border-width: 1px 0 0;
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .rc-auth__button,
    .rc-auth__field input,
    .rc-auth__field .oh-password-input--toggle {
      height: 44px;
    }
  }

  /* Error pages ------------------------------------------------------------ */

  /* No hero here. Someone who hit an error wants the way out, so this is plain
     text on the canvas with one strip of road along the bottom. */
  & body.rc-error {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: var(--foreground);
    font-family: var(--font-sans);
    font-size: var(--type-14);
    line-height: var(--leading-base);
  }

  .rc-error__panel {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 48px 24px;
  }

  .rc-error__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 40px;
    color: var(--foreground);
    font-family: var(--font-display);
    font-size: var(--type-16);
    font-weight: 700;
    letter-spacing: -.01em;

    img {
      width: 32px;
      height: 32px;
    }
  }

  .rc-error__code {
    margin: 0 0 8px;
    color: var(--muted-foreground);
    font-size: var(--type-13);
    font-weight: 500;
    font-feature-settings: var(--numeric-features);
  }

  .rc-error__title {
    margin: 0 0 8px;
    color: var(--foreground);
    font-family: var(--font-display);
    font-size: var(--type-30);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 36px;
  }

  .rc-error__text {
    margin: 0;
    color: var(--muted-foreground);
    font-size: var(--type-16);
    line-height: 24px;
  }

  .rc-error__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
  }

  .rc-error__button {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--primary-foreground);
    font-family: inherit;
    font-size: var(--type-14);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease;

    &:hover {
      background: var(--primary-700);
      color: var(--primary-foreground);
    }

    &:focus-visible {
      outline: 2px solid var(--ring);
      outline-offset: 2px;
    }
  }

  .rc-error__button--quiet {
    border-color: var(--border);
    background: var(--card);
    color: var(--foreground);

    &:hover {
      background: var(--muted);
      color: var(--foreground);
    }
  }

  /* The strip: asphalt with a dashed lane. "ends" stops the lane short, "stop"
     paints a solid stop line across the road where it ends, as on a junction. */
  .rc-error__road {
    position: relative;
    flex: none;
    height: 88px;
    background: var(--rc-asphalt);
  }

  &.dark .rc-error__road {
    background: var(--rc-asphalt-2);
  }

  .rc-error__lane {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    margin-top: -2px;
    background: repeating-linear-gradient(to right, #fff 0 44px, transparent 44px 76px);
  }

  [data-road="ends"] .rc-error__lane,
  [data-road="stop"] .rc-error__lane {
    width: 58%;
  }

  .rc-error__stop {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(58% + 16px);
    width: 10px;
    background: #fff;
  }

  [data-road="stop"] .rc-error__stop {
    display: block;
  }

  @media (max-width: 639.98px) {
    .rc-error__panel {
      justify-content: flex-start;
      padding: 32px 16px;
    }

    .rc-error__title {
      font-size: var(--type-24);
      line-height: 30px;
    }

    .rc-error__road {
      height: 64px;
    }
  }
}
