/*
 * What every login-side page shares: the button, the field, the link and the login frame.
 * Colours, corners and fonts come from tokens.generated.css, which is loaded first.
 * Screens narrower than 768px (the tablet breakpoint in tokens.json) get the phone layout.
 */

:root {
  /* Sizes these pages use that tokens.json does not name. */
  --auth-control-height: var(--size-touch);
  --auth-control-text: 15px;
  --auth-button-height: 40px;
  --auth-button-text: var(--text-sub);
  --auth-code-height: 52px;
  --auth-code-text: 22px;
  --auth-link-height: 32px;
  --auth-form-gap: 20px;
}

@media (max-width: 767px) {
  :root {
    /* Inputs and buttons are 48px high, and their text is 16px so iOS does not zoom the page on focus. */
    --auth-control-height: 48px;
    --auth-control-text: 16px;
    --auth-button-height: 48px;
    --auth-button-text: 16px;
    --auth-code-height: 56px;
    --auth-code-text: 24px;
    --auth-link-height: var(--size-touch);
    --auth-form-gap: 18px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: var(--text-body--line-height);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
p,
dl,
dd {
  margin: 0;
}

.is-hidden {
  display: none !important;
}

/* ---- Button ---- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--auth-button-height);
  padding: 0 16px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: inherit;
  font-size: var(--auth-button-text);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.button:hover:not(:disabled) {
  border-color: var(--color-ink-muted);
}

.button:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.button--primary {
  border-color: var(--color-brand);
  background: var(--color-brand);
  color: var(--color-surface);
}

.button--primary:hover:not(:disabled) {
  border-color: var(--color-brand-hover);
  background: var(--color-brand-hover);
}

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

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

/* The one action of a form: as wide and as high as the inputs above it. */
.button--block {
  display: flex;
  width: 100%;
  min-height: var(--auth-control-height);
  font-size: var(--auth-control-text);
}

/* A button beside other content, such as a page header or a list row. */
.button--compact {
  min-height: var(--size-control);
  padding: 0 12px;
  font-size: var(--text-sub);
}

.button__icon {
  display: block;
  flex: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 767px) {
  .button--compact {
    min-height: var(--size-touch);
  }

  .button-row {
    flex-direction: column;
  }
}

/* ---- Field: a label, an input, and for passwords the hold-to-show button inside the input ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field__label {
  font-size: var(--text-sub);
  font-weight: 700;
}

.field__input {
  width: 100%;
  min-height: var(--auth-control-height);
  padding: 0 12px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: inherit;
  font-size: var(--auth-control-text);
  transition: border-color 0.15s ease;
}

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

.field__input:hover:not(:disabled) {
  border-color: var(--color-ink-muted);
}

.field__input:focus-visible {
  border-color: var(--color-brand);
  outline: 2px solid var(--color-brand);
  outline-offset: -1px;
}

.field__input:disabled {
  background: var(--color-canvas);
  color: var(--color-ink-muted);
  cursor: not-allowed;
}

.field__input--code {
  min-height: var(--auth-code-height);
  font-family: var(--font-number);
  font-size: var(--auth-code-text);
  letter-spacing: 0.3em;
  text-align: center;
}

.field__control {
  position: relative;
  display: flex;
}

.field__control .field__input {
  padding-right: 64px;
}

.field__peek {
  position: absolute;
  top: 4px;
  right: 4px;
  bottom: 4px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-tag);
  background: transparent;
  color: var(--color-brand);
  font-family: inherit;
  font-size: var(--text-sub);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.field__peek:hover,
.field__peek[data-revealing='true'] {
  background: var(--color-brand-soft);
  color: var(--color-brand-strong);
}

.field__peek:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 0;
}

.field__hint {
  color: var(--color-ink-muted);
  font-size: var(--text-sub);
  line-height: var(--text-sub--line-height);
}

.field__hint:empty {
  display: none;
}

@media (max-width: 767px) {
  .field__control .field__input {
    padding-right: 68px;
  }

  .field__peek {
    top: 2px;
    right: 2px;
    bottom: 2px;
    padding: 0 14px;
    font-size: var(--text-body);
  }
}

/* ---- Link: an underlined action that is not the main one ---- */

.link {
  min-height: var(--auth-link-height);
  padding: 0;
  border: 0;
  border-radius: var(--radius-tag);
  background: transparent;
  color: var(--color-brand);
  font-family: inherit;
  font-size: var(--text-sub);
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link:hover:not(:disabled) {
  color: var(--color-brand-hover);
}

.link:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

.link:disabled {
  color: var(--color-ink-muted);
  cursor: not-allowed;
}

.link--strong {
  font-weight: 700;
}

/* ---- Login frame: the municipality's name on dark green, the form on white ---- */

.auth-frame {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-surface);
}

.auth-frame__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--color-brand-strong);
  color: var(--color-surface);
}

.auth-frame__mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-brand-strong);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
}

.auth-frame__title {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.auth-frame__main {
  padding: 32px 20px 24px;
}

.auth-frame__content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.auth-frame__copyright {
  padding: 0 20px 20px;
  color: var(--color-ink-muted);
  font-family: var(--font-number);
  font-size: var(--text-note);
}

@media (min-width: 768px) {
  .auth-frame {
    /* The split a flex row gives to "1 1 420px" beside "1.4 1 480px". */
    grid-template-columns: calc(420px + (100% - 900px) / 2.4) 1fr;
    grid-template-rows: 1fr auto;
  }

  .auth-frame__brand {
    grid-area: 1 / 1;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 48px;
    padding: 40px 48px 0;
  }

  .auth-frame__mark {
    width: 40px;
    height: 40px;
    font-size: 19px;
  }

  .auth-frame__title {
    font-size: 44px;
    /* Never start a line with the long-vowel mark of a word such as データ. */
    line-break: strict;
  }

  /* A long name takes two lines of about the same length (会津若松市 / データ分析). */
  @supports (text-wrap: balance) {
    .auth-frame__title {
      max-width: 8em;
      text-wrap: balance;
    }
  }

  .auth-frame__main {
    display: flex;
    grid-area: 1 / 2 / 3 / 3;
    align-items: center;
    justify-content: center;
    padding: 48px 32px;
  }

  .auth-frame__content {
    width: 100%;
    max-width: 384px;
    gap: 28px;
  }

  .auth-frame__copyright {
    grid-area: 2 / 1;
    padding: 20px 48px 40px;
    background: var(--color-brand-strong);
    color: var(--color-brand-soft);
    color: color-mix(in srgb, var(--color-brand-soft) 87%, var(--color-brand-strong));
  }
}

/* ---- Inside the frame: the heading, the form and what a step adds to it ---- */

.auth-heading {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-heading__title {
  font-size: var(--text-title);
  font-weight: 700;
  line-height: 1.35;
  /* A heading that needs two lines splits them evenly instead of leaving one character behind. */
  text-wrap: balance;
}

.auth-heading__lead {
  color: var(--color-ink-secondary);
  text-wrap: pretty;
}

.auth-heading__note {
  color: var(--color-ink-muted);
  font-size: var(--text-sub);
  line-height: var(--text-sub--line-height);
}

.auth-heading__note:empty {
  display: none;
}

.state-error .auth-heading__lead {
  color: var(--color-danger);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--auth-form-gap);
  margin: 0;
}

.auth-form__link {
  align-self: center;
}

.auth-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-text {
  color: var(--color-ink-secondary);
}

@media (min-width: 768px) {
  .auth-heading {
    gap: 8px;
  }

  .auth-heading__title {
    font-size: 26px;
  }
}

@media (max-width: 767px) {
  .auth-form__link,
  .auth-form .field__aside {
    margin-top: -10px;
    font-size: var(--text-body);
  }

  /*
   * On a phone the link beside the password label moves under the submit button.
   * The field's own boxes step aside so that the link can be ordered last in the form.
   */
  .auth-form .field--with-aside,
  .auth-form .field--with-aside > .field__head {
    display: contents;
  }

  .auth-form .field--with-aside .field__label {
    margin-bottom: calc(6px - var(--auth-form-gap));
  }

  .auth-form .field__aside {
    order: 1;
    align-self: center;
  }
}

/* ---- Google sign-in ---- */

.google-sign-in-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.google-sign-in-button {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: var(--size-touch);
}

.google-sign-in-button[aria-busy='true'] {
  opacity: 0.55;
  pointer-events: none;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--color-ink-muted);
  font-size: var(--text-note);
}

.divider::before,
.divider::after {
  flex: 1;
  height: 1px;
  background: var(--color-line);
  content: '';
}

/* ---- Authenticator set-up: the QR code and the key to type by hand ---- */

.qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.qr canvas {
  /* The border goes around the code, so the code keeps the size it was drawn at. */
  box-sizing: content-box;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-control);
}

.secret-key {
  padding: 10px 12px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-control);
  background: var(--color-canvas);
  color: var(--color-ink-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sub);
  line-height: var(--text-sub--line-height);
  text-align: center;
  word-break: break-all;
}

/* ---- Messages ---- */

.message {
  display: none;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  font-size: var(--text-sub);
  line-height: var(--text-sub--line-height);
}

.message.visible {
  display: block;
}

.message.error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.message.success {
  background: var(--color-brand-soft);
  color: var(--color-brand-strong);
}

.message .button {
  margin-top: 8px;
}

.signout-complete h2 {
  font-size: var(--text-section);
  line-height: var(--text-section--line-height);
}

.signout-complete p {
  margin-top: 4px;
  color: var(--color-ink-secondary);
}

/* ---- Waiting ---- */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--color-surface);
  color: var(--color-ink-muted);
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-line);
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
