/*
 * The login page is deliberately plain: it runs in a popup with no uu5 and no React, so
 * it loads in one request instead of pulling the whole app in (docs/auth.md, 5.2). One
 * document carries every mode, registration included.
 *
 * The --caio-* colours come from the app's manifest at build time (caio-devkit) and can
 * be overridden at runtime by the window that opened the popup, which resolves its
 * `primaryColorScheme` through UuGds and posts the result over (login.js, applyBranding,
 * docs/auth.md, 12). The values below are what applies when neither says anything.
 *
 * The neutral surfaces are uuGDS values (Shape.ground, ColorPalette.building) for a light
 * and a dark background. Which one applies is the app's colour mode, posted over by the
 * opener and set as `<html data-color-mode>` (login.js, setColorMode); without one, the
 * system's preference.
 */
:root {
  color-scheme: light;
  --caio-theme: #004191;
  --caio-theme-text: #ffffff;
  --caio-theme-hover: var(--caio-theme);
  --caio-theme-active: var(--caio-theme);
  --caio-link: var(--caio-theme);
  --page: #f5f5f5;
  --bg: #ffffff;
  --shadow: 0 1px 4px rgb(33 33 33 / 32%);
  --text: #212121;
  --muted: #616161;
  --border: rgb(33 33 33 / 32%);
  --line: #e0e0e0;
  --input-bg: #ffffff;
  --error: #b3261e;
  --message-bg: #fdecea;
  --message-text: var(--error);
  --info-bg: #eef3fb;
  --google-bg: #ffffff;
  --google-border: #747775;
  --google-text: #1f1f1f;
  --google-hover: #f7f8f8;
}

/*
 * The dark set, twice: once for an explicit dark mode from the app and once for the
 * system's dark preference when the app said nothing (or there is no app -- a link from
 * an e-mail). An explicit light mode beats a dark system, hence the :not().
 */
:root[data-color-mode="dark"] {
  color-scheme: dark;
  --page: #212121;
  --bg: #343434;
  --shadow: 0 1px 4px rgb(33 33 33 / 32%), 0 0 0 1px rgb(255 255 255 / 16%);
  --text: #ffffff;
  --muted: rgb(255 255 255 / 70%);
  --border: #9e9e9e;
  --line: rgb(255 255 255 / 24%);
  --input-bg: rgb(33 33 33 / 40%);
  --message-bg: #3a1f1d;
  --message-text: #ffb4ab;
  --info-bg: #22303f;
  /* Google's own dark variant of the button, rather than a white slab on a dark card.
     Facebook has no dark variant -- #1877f2 stays. */
  --google-bg: #131314;
  --google-border: #8e918f;
  --google-text: #e3e3e3;
  --google-hover: #1e1f20;
}

/*
 * Without an app to answer (a link from an e-mail), the brand colour is the manifest's
 * theme_color -- one colour, chosen for a light page, and often a dark one (CAIO's is
 * #0d0b1e). Links in it would vanish on a dark card, so they take the text colour there;
 * they are underlined anyway. The app's own colours come resolved for its mode and lift
 * this (login.js removes data-brand).
 */
:root[data-color-mode="dark"][data-brand="build"] {
  --caio-link: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-color-mode="light"])[data-brand="build"] {
    --caio-link: var(--text);
  }

  :root:not([data-color-mode="light"]) {
    color-scheme: dark;
    --page: #212121;
    --bg: #343434;
    --shadow: 0 1px 4px rgb(33 33 33 / 32%), 0 0 0 1px rgb(255 255 255 / 16%);
    --text: #ffffff;
    --muted: rgb(255 255 255 / 70%);
    --border: #9e9e9e;
    --line: rgb(255 255 255 / 24%);
    --input-bg: rgb(33 33 33 / 40%);
    --message-bg: #3a1f1d;
    --message-text: #ffb4ab;
    --info-bg: #22303f;
    --google-bg: #131314;
    --google-border: #8e918f;
    --google-text: #e3e3e3;
    --google-hover: #1e1f20;
  }
}

* {
  box-sizing: border-box;
}

/*
 * Atribut `hidden` musí přebít třídu. login.js skrývá uzly podle `data-modes` právě přes
 * `hidden`, jenže to je jen styl prohlížeče (`[hidden] { display: none }`) a jakékoli
 * pravidlo se třídou nad ním vyhraje specificitou -- `.separator { display: flex }` tak
 * nechávalo "nebo" viset nad e-mailem i tehdy, když nad ním nebylo žádné tlačítko
 * providera, a ani `el.separator.hidden = true` s tím nic neudělalo.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.card {
  width: 100%;
  max-width: 360px;
  background: var(--bg);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}

.providers {
  display: grid;
  gap: 8px;
}

.separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.separator::before,
.separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.row {
  margin-bottom: 14px;
}

label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
}

input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg);
  color: inherit;
}

input:focus-visible {
  outline: 2px solid var(--caio-theme);
  outline-offset: 1px;
  border-color: var(--caio-theme);
}

/*
 * Heslo se dá zobrazit. Tlačítko sedí uvnitř pole, takže si nebere řádek navíc a drží se
 * u vstupu i na mobilu; `padding-inline-end` na inputu mu dělá místo, aby text nikdy
 * nezajel pod ikonu. Stav nese `aria-pressed` -- odtud se řídí i to, která ikona je
 * vidět, takže není co synchronizovat ve dvou místech.
 */
.reveal-field {
  position: relative;
  display: flex;
}

.reveal-field input {
  padding-inline-end: 40px;
}

.reveal {
  position: absolute;
  inset-block: 1px;
  inset-inline-end: 1px;
  width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0 7px 7px 0;
  background: none;
  color: var(--muted);
}

.reveal:hover {
  color: var(--text);
}

.reveal:focus-visible {
  outline: 2px solid var(--caio-theme);
  outline-offset: -2px;
}

.reveal svg {
  display: block;
}

.reveal .icon-off,
.reveal[aria-pressed="true"] .icon-on {
  display: none;
}

.reveal[aria-pressed="true"] .icon-off {
  display: block;
}

button {
  font: inherit;
  cursor: pointer;
}

button[disabled] {
  opacity: 0.6;
  cursor: default;
}

.primary,
.provider {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.primary {
  background: var(--caio-theme);
  color: var(--caio-theme-text);
  font-weight: 600;
}

/*
 * Provider buttons follow each brand's own sign-in guidelines, not this page's palette
 * -- both Google and Facebook require their colours, their logo and their wording, in
 * light and dark alike. That is why these rules carry fixed colours and are not part of
 * the theming above.
 */
.provider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  text-align: left;
}

.provider-logo {
  display: flex;
  flex: 0 0 auto;
}

.provider-label {
  flex: 1 1 auto;
  text-align: center;
}

/* Google: white surface, #747775 border, #1f1f1f label, Roboto (dark: see :root). */
.provider--google {
  background: var(--google-bg);
  border: 1px solid var(--google-border);
  color: var(--google-text);
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.25px;
}

.provider--google:hover {
  background: var(--google-hover);
}

/* Facebook: #1877f2 with the white f and white label. */
.provider--facebook {
  background: #1877f2;
  border-color: #1877f2;
  color: #fff;
  font-family: Helvetica, Arial, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
}

.provider--facebook:hover {
  background: #166fe5;
}

/*
 * The filter stays even when an explicit hover colour arrives from the opener: GDS gives
 * the accent shade of the same scheme, so 4 % on top of it is imperceptible -- and
 * without it a deployment that sends no colours at all would have no hover feedback,
 * which CSS cannot branch on.
 */
.primary:hover {
  background: var(--caio-theme-hover);
  filter: brightness(0.96);
}

.primary:active {
  background: var(--caio-theme-active);
}

.hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/*
 * Úvodní odstavec stojí nad formulářem, ne pod polem jako ostatní `.hint` -- bez spodní
 * mezery se lepí na první popisek.
 */
#intro {
  margin: 0 0 16px;
}

.message {
  margin: 0 0 14px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--message-bg);
  color: var(--message-text);
  font-size: 13px;
}

.message.info {
  background: var(--info-bg);
  color: var(--text);
}

.switch {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--caio-link);
  text-decoration: underline;
  cursor: pointer;
}

/*
 * An invitation fixes the address (registration.js): the token was issued for one and
 * for no other, so the field shows it and says, by looking inert, that it is not a
 * choice.
 */
input[readonly] {
  background: color-mix(in srgb, var(--border) 25%, var(--bg));
  color: var(--muted);
  cursor: default;
}
