/*
 * The emergency numbers panel (index.html, #emergency-panel). Its own file, linked from the head, so a page
 * whose script and main stylesheet never arrived still shows it. Every colour reads the design token with
 * the token's own value as the fallback. Neutral ink, not a safety colour: it isn't an alert.
 *
 * It is the first thing on the page (order: -1 in the body's column) and sticks to the top. Its height is
 * --nms-emergency-h, which the app's sticky things add to their own offsets (packages/ui/src/styles.css
 * reads it for --nms-sticky-top). Keep this height in step with the real one: e2e/emergency-panel.spec.ts
 * measures it.
 */

:root {
  /* A phone: a row of four (number over purpose, 50px) and the line about test calls (21px). */
  --nms-emergency-h: 4.75rem;
}
@media (min-width: 48rem) {
  :root {
    /* An upright tablet: a row of four (44px) and the line about test calls under it. */
    --nms-emergency-h: 4.3125rem;
  }
}
@media (min-width: 64rem) {
  :root {
    /* A sideways tablet and up: all of it in one row. */
    --nms-emergency-h: 3rem;
  }
}
/* A window this narrow (a phone at 200% zoom) wraps too much to hold a height: it scrolls away. */
@media (max-width: 14.99rem) {
  :root {
    --nms-emergency-h: 0px;
  }
}
/* Not on the parent app: it is for staff (set by theme-boot.js and by the root layout). */
html[data-surface='parent'] {
  --nms-emergency-h: 0px;
}
html[data-surface='parent'] #emergency-panel {
  display: none;
}

body {
  display: flex;
  flex-direction: column;
}
#root {
  flex: 1 0 auto;
  min-width: 0;
}

#emergency-panel {
  --ep-bg: var(--surface, #ffffff);
  --ep-ink: var(--ink, #24262f);
  --ep-muted: var(--ink-muted, #646876);
  --ep-line: var(--border-strong, #85888f);
  --ep-focus: var(--focus, #1a56db);
  order: -1;
  position: sticky;
  top: 0;
  z-index: 40;
  box-sizing: border-box;
  min-height: var(--nms-emergency-h);
  display: grid;
  /* Each as wide as its own words, spread along the row, so no width needs a second line. */
  grid-template-columns: repeat(4, auto);
  justify-content: space-between;
  align-content: center;
  padding-block: 0.125rem;
  padding-inline: max(0.25rem, env(safe-area-inset-left), env(safe-area-inset-right));
  background: var(--ep-bg);
  color: var(--ep-ink);
  box-shadow: 0 1px 0 var(--ep-line);
  font-size: 0.875rem;
  line-height: 1.5;
}
html[data-theme='dark'] #emergency-panel {
  --ep-bg: var(--surface, #1e2028);
  --ep-ink: var(--ink, #f1f1f4);
  --ep-muted: var(--ink-muted, #b0b3bf);
  --ep-line: var(--border-strong, #7d8291);
  --ep-focus: var(--focus, #9cc0ff);
}
@media (max-width: 14.99rem) {
  #emergency-panel {
    position: static;
  }
}
@media (min-width: 48rem) {
  #emergency-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    justify-content: normal;
    /* Lines up with the navigation below it: the same frame and gutter. */
    padding-inline: max(1.5rem, calc((100% - var(--nms-frame, 90rem)) / 2 + 1.5rem));
  }
}
@media (min-width: 80rem) {
  #emergency-panel {
    /* The navigation's own gutter from xl up (top-nav.tsx: px-6 xl:px-8). */
    padding-inline: max(2rem, calc((100% - var(--nms-frame, 90rem)) / 2 + 2rem));
  }
}
@media (min-width: 64rem) {
  #emergency-panel {
    /* The line about test calls goes to the end of the row of four. */
    grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.4fr);
    align-items: center;
  }
}

#emergency-panel a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 3.125rem;
  min-width: 2.75rem;
  padding-inline: 0.125rem;
  color: inherit;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
}
/* The design system's phone target (48px): a short purpose ("شرطة") is narrower than that. Not in a window
   too narrow for four of them (a phone at 200% zoom), which keeps the 44px floor. */
@media (min-width: 15rem) {
  #emergency-panel a {
    min-width: 3rem;
  }
}
@media (min-width: 48rem) {
  #emergency-panel a {
    flex-direction: row;
    gap: 0.5rem;
    min-height: 2.75rem;
  }
}
#emergency-panel:focus-visible {
  /* Where the "Emergency numbers" skip link puts focus. */
  outline: 2px solid var(--ep-focus);
  outline-offset: -2px;
}
#emergency-panel a:focus-visible {
  outline: 2px solid var(--ep-focus);
  outline-offset: -2px;
}
#emergency-panel .ep-number {
  font-size: 1.125rem;
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
#emergency-panel .ep-status {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--ep-muted);
}
@media (min-width: 64rem) {
  #emergency-panel .ep-status {
    grid-column: auto;
    text-align: end;
  }
}

/* The language of the page picks the words, with no script. Arabic unless the page is English. */
#emergency-panel [lang='en'] {
  display: none;
}
html[lang^='en'] #emergency-panel [lang='en'] {
  display: block;
}
html[lang^='en'] #emergency-panel [lang='ar'] {
  display: none;
}

@media print {
  #emergency-panel {
    display: none;
  }
}

/* What is scrolled or tabbed into view lands clear of the panel and of the header under it: the design system's
   scroll padding adds --nms-emergency-h (packages/ui/src/styles.css). Not set here, where it would replace that. */
