/* The Pi kiosk's in-app touch keyboard — see js/onscreen-keyboard.js for
   why the app draws its own instead of relying on an OS one. Nothing here
   applies on a phone or laptop: the element is only ever created on the
   touchscreen. */

.osk {
  /* Fixed to the bottom of the viewport even though the element is
     re-parented into the open <dialog> (see onscreen-keyboard.js) — the
     dialog sets no transform/filter, so `fixed` still resolves against
     the viewport and the keyboard is not confined to the dialog's box. */
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: none;
  margin: 0;
  border: none;
  border-top: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 1.5) calc(var(--radius) * 1.5) 0 0;
  padding: var(--spacing-unit) calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1.5);
  background-color: #e6e4de;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  overflow: visible;
  /* Above the <dialog>'s ::backdrop, which would otherwise dim the keys. */
  z-index: 100;
}

/* The dialog is sized to its content and would otherwise clip the
   keyboard, which lives inside it but is positioned against the viewport. */
body.osk-open .event-dialog {
  overflow: visible;
}

.osk__row {
  display: flex;
  justify-content: center;
  gap: calc(var(--spacing-unit) * 0.75);
  margin-bottom: calc(var(--spacing-unit) * 0.75);
}

.osk__row:last-child {
  margin-bottom: 0;
}

.osk__key {
  flex: 1 1 0;
  /* Keys are deliberately larger than the app's usual 48px tap target:
     they sit edge-to-edge with their neighbours, so a near-miss types the
     wrong letter rather than doing nothing. */
  min-height: 56px;
  max-width: 96px;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: none;
  border-radius: calc(var(--radius) * 0.75);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  /* A wall display gets tapped, never hovered, and the text-selection
     flash from a fast double tap looks like a glitch. */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.osk__key:hover {
  background-color: var(--color-surface);
}

.osk__key:active {
  background-color: var(--color-text-faint);
  box-shadow: none;
}

.osk__key--mod {
  flex-grow: 1.5;
  font-size: 1rem;
  color: var(--color-text);
  background-color: #cfccc4;
}

.osk__key--mod:hover {
  background-color: #cfccc4;
}

.osk__key--wide {
  flex-grow: 1.5;
}

.osk__key--space {
  flex-grow: 5;
  max-width: none;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* The numeric pad is a 3-column phone-style keypad rather than a full
   width row of ten digits. Centred, with keys allowed to grow well past
   the letter keys' width: a row of three stretched across a 10" screen
   would put the digits absurdly far apart, and hard against one edge
   looks like a rendering fault. */
.osk[data-layer="numeric"] .osk__row {
  justify-content: center;
}

/* Echoes the time being typed ("09:3·"), because a time input can't show
   a partial value and would otherwise sit blank until the fourth digit. */
.osk__readout {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  padding: calc(var(--spacing-unit) * 0.5) 0 calc(var(--spacing-unit));
}

.osk__readout--complete {
  color: var(--color-text);
}

.osk[data-layer="numeric"] .osk__key {
  flex: 0 0 auto;
  width: 132px;
  max-width: none;
}

/* While the keyboard is up, the dialog gives up exactly the space the
   keyboard occupies and fills everything above it — --osk-height is
   measured from the real element in onscreen-keyboard.js, because the
   layers differ in row count and the keys are sized in px, so any fixed
   vh guess leaves either a dead gap under the dialog or a bottom edge
   hidden behind the keys. The fallback only applies for the frame before
   the property is set. */
body.osk-open .event-dialog {
  height: calc(100dvh - var(--osk-height, 46vh) - var(--spacing-unit) * 2);
  max-height: calc(100dvh - var(--osk-height, 46vh) - var(--spacing-unit) * 2);
  /* Anchor to the top of the screen instead of staying vertically centred
     over the keyboard. */
  margin-top: var(--spacing-unit);
  margin-bottom: auto;
}

/* The form is the scroll container (it already has overflow-y: auto), so
   it has to be the full height of the dialog for a long form — Add task
   with a recurrence set — to scroll rather than clip. */
body.osk-open .event-form {
  max-height: 100%;
  height: 100%;
}

/* Same problem outside a dialog. The login card is vertically centred, so
   with the keyboard up its Sign in button sits behind the keys — pin the
   card to the top of the free space instead. */
body.osk-open .auth-page {
  min-height: 54vh;
  align-items: flex-start;
}

/* The dashboard pages scroll normally; they just need somewhere to scroll
   to, so the last row of a list can be brought clear of the keyboard. */
body.osk-open .app-content {
  padding-bottom: 54vh;
}
