/* The Debra page (digon-tech/chaxter#3985): the browser's light or dark preference (ML63 SPEC S5.6). */
:root {
  color-scheme: light dark;
  --background: #ffffff;
  --foreground: #1b1d21;
  --muted: #5d636e;
  --border: #d9dce1;
  --accent: #2f6fde;
  /* A filled button's label on `--accent`: 4.7:1 here, 6.7:1 in dark (digon-tech/chaxter#4118). */
  --on-accent: #ffffff;
  /* A filled button under the pointer (digon-tech/chaxter#4140): darker here, lighter in dark, so
     its label reads above the 4.5:1 of the resting fill. */
  --accent-hover: #2559b8;
  font-family: 'Inter Variable', system-ui, sans-serif;
}

/*
 * The page's own font (digon-tech/chaxter#4124, #4120), the app's Inter, as digon-tech/chaxter#4072
 * set the sign-in link page to it: Inter Variable 4.001, weights 100 to 900, served beside this
 * file (`page/fonts/`, SIL Open Font License 1.1). Its Latin face is the app's own file
 * (`@fontsource-variable/inter` 5.3.0, `inter-latin-wght-normal.woff2`); Latin Extended-A is a
 * subset of the package's `latin-ext` face, declared first so the Latin face wins where the two
 * ranges meet, as the package declares them. With `system-ui` alone each machine drew the page in a
 * font of its own, and a line that fits in one broke in another: CI run 44533588544 put the magic
 * link heading on two lines at 390 and left a word alone on the reason line at 320.
 */
@font-face {
  font-family: 'Inter Variable';
  src: url('inter-latin-ext-a.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-017F;
}

@font-face {
  font-family: 'Inter Variable';
  src: url('inter-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #15171a;
    --foreground: #e8eaee;
    --muted: #a1a7b2;
    --border: #2e3238;
    --accent: #6d9bff;
    --on-accent: #15171a;
    --accent-hover: #93b6ff;
  }
}

/* `hidden` hides whatever display a class sets: the closed side panel and the closed menu. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

/*
 * One row of 64 px where it fits; on a narrow screen the header wraps onto more rows, so every
 * control stays whole and in reach and the page never scrolls sideways (digon-tech/chaxter#4113).
 * The side panel opens below it at whatever height it takes (`page/main.ts`).
 */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  box-sizing: border-box;
  min-height: 64px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

/*
 * In debra-shell, above Debra's transparent backdrop (z-index 2147482998 in @debra/widget 0.8.1),
 * which takes every click outside her panel, and level with her panel (2147482999), which comes
 * later in the page and so stays on top: a visible «Sign out» takes its click with the panel open,
 * and the panel keeps its own Close where it covers the header (digon-tech/chaxter#4114). Not in
 * host-shell, where Debra draws inside the side panel and her full-page dialogs must cover the
 * header.
 */
header[data-debra-mode='debra-shell'] {
  position: relative;
  z-index: 2147482999;
}

/* The account's name takes its own row when the row is too narrow for it, whole. */
header .account {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

/*
 * «Help» and «Sign out» wrap together and keep to the right edge of their row, so the menu, which
 * opens leftwards from Help's right edge, stays on the screen.
 */
header .actions {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

/* The account's Debra switch (digon-tech/chaxter#4000): a checkbox and its label on one line. */
header .switch {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

header .switch input {
  padding: 0;
}

header .message:empty {
  display: none;
}

main {
  max-width: 420px;
  margin: 32px auto;
  padding: 0 16px;
}

/* Headings in lines of even length, so a phone never leaves a word alone on the last one
   (digon-tech/chaxter#4124, #4125). */
main h1,
main h2 {
  text-wrap: balance;
}

.card {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
}

input,
button {
  font: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
}

button {
  cursor: pointer;
}

button[type='submit'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

button[type='submit']:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.line,
.message {
  color: var(--muted);
}

.help {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  z-index: 10;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 200px;
}

.menu button {
  width: 100%;
  text-align: left;
  border: 0;
}

.panel {
  position: fixed;
  top: 64px;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--background);
  border-left: 1px solid var(--border);
  z-index: 20;
}

/*
 * The page's «Close» at the foot of the panel, below Debra's root: her toolbar at the top of her root
 * is the panel's one header (digon-tech/chaxter#4125), and in host-shell she draws no close of her own.
 */
.panel .close {
  align-self: flex-end;
  margin: 8px;
}

.panel .root {
  flex: 1;
  min-height: 0;
}

/*
 * The page's own line when Debra cannot be reached, with its «Retry» (digon-tech/chaxter#4149,
 * 64-D66): words and button on one row where they fit, the button below them where they do not.
 */
.reason {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
}

/* Its words take the row's whole width, «Retry» below them, where beside it they would be too narrow
   for the support address and the word before it (digon-tech/chaxter#4120). */
.reason p {
  flex: 1 1 15em;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  /* Lines of even length, so the words never end on one alone (digon-tech/chaxter#4160). */
  text-wrap: balance;
}

.reason button {
  white-space: nowrap;
}

/* host-shell: at the top of the side panel, above Debra's own copy. */
.panel .reason {
  margin: 0 8px 8px;
}

/*
 * debra-shell: Debra's panel covers the page (widget 0.8.1: down to 96 px above the bottom, her
 * launcher in the bottom-right corner, 56 px at 24 px from the edges), so the line sits in the band
 * under her panel, right beside her launcher (digon-tech/chaxter#4160), level with her panel and
 * above her backdrop, which would otherwise take its click. On a phone the line that says what to do
 * (digon-tech/chaxter#4120) is taller than that band and lies over the blank lower part of her failed
 * panel (her words and «Try again» are at its top). It comes after her root in the page, and at the
 * same level it is drawn above her panel: its words and «Retry» are what the screen shows at their
 * centres (`test/page/debra-reason.e2e.ts`).
 */
main > .reason {
  position: fixed;
  right: 88px;
  bottom: 8px;
  width: min(480px, calc(100vw - 96px));
  z-index: 2147482999;
  box-shadow: 0 4px 16px #10182826;
}
