/* ALAZ Alerts PWA. Colour tokens for the light and the graphite dark theme; the flame orange comes from the product icon.
   System (default) follows prefers-color-scheme; js/theme.js sets data-theme="light|dark" on <html> for a manual choice. */
:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface-2: #ececef;
  --text: #0a0a0b;
  --muted: #52525b;
  --border: #e4e4e7;
  --border-strong: #71717a;
  --accent: #e2703a;
  --on-accent: #0a0a0b;
  --link: #b34700;
  --danger: #b3261e;
  --on-danger: #ffffff;
  --success: #1e7a3c;
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c0c0e;
  --surface: #141417;
  --surface-2: #1d1d21;
  --text: #ededef;
  --muted: #a1a1aa;
  --border: #27272b;
  --border-strong: #6b6b74;
  --accent: #e2703a;
  --on-accent: #0c0c0e;
  --link: #ff8a3d;
  --danger: #ff8a80;
  --on-danger: #0c0c0e;
  --success: #5fd38d;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0c0e;
    --surface: #141417;
    --surface-2: #1d1d21;
    --text: #ededef;
    --muted: #a1a1aa;
    --border: #27272b;
    --border-strong: #6b6b74;
    --accent: #e2703a;
    --on-accent: #0c0c0e;
    --link: #ff8a3d;
    --danger: #ff8a80;
    --on-danger: #0c0c0e;
    --success: #5fd38d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--link); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }

[hidden] { display: none !important; }

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}
.site-header img { width: 40px; height: 40px; border-radius: 10px; }
.site-header h1 { font-size: 1.25rem; margin: 0; }
.site-header { position: relative; flex-wrap: nowrap; }
.site-header h1 { flex: 1; min-width: 0; }
.site-header .brand { display: flex; align-items: center; gap: 12px; min-width: 0; margin-right: auto; color: inherit; text-decoration: none; border-radius: 10px; }
.privacy-home { margin: 24px 0 0; }
.site-header .menu-toggle {
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  flex: none;
}

/* Header menu: a flat full-viewport sheet; the icon-only close button sits at the bottom. */
.header-menu {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 20px;
  background: var(--bg);
  animation: menu-in 0.16s ease-out;
}
.header-menu[hidden] { display: none; }
html.menu-open { overflow: hidden; }
.menu-label { margin: 0 0 10px; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted, var(--text)); }
.menu-footer {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: flex;
  justify-content: center;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}
.header-menu .menu-close {
  width: 56px;
  height: 56px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .header-menu { animation: none; } }

/* Theme switch (System / Light / Dark): a small segmented button group in the header. */
.theme-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 999px; padding: 2px; }
.theme-switch button {
  width: auto;
  margin: 0;
  padding: 4px 10px;
  min-height: 32px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
}
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
}
.card h2 { font-size: 1.1rem; margin: 0 0 12px; }

.status-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; text-align: right; font-weight: 600; }

label { display: block; margin-bottom: 8px; color: var(--muted); }

.code-input {
  width: 100%;
  font: 600 1.6rem/1.2 ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  padding: 12px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

/* Code input with the Scan QR code button beside it; the button wraps below on narrow screens. */
.code-row { display: flex; flex-wrap: wrap; gap: 8px; }
.code-row .code-input { flex: 999 1 11em; width: auto; min-width: 0; }
.code-row button { flex: 1 0 auto; width: auto; margin-top: 0; }

.code-display.small { font-size: 1.6rem; }

.code-display {
  font: 700 2.4rem/1.2 ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: 0.15em;
  text-align: center;
  margin: 12px 0;
}

button, .button {
  display: inline-block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 20px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.secondary { background: transparent; border: 2px solid var(--border-strong); color: var(--text); }
/* Compact secondary button (formerly a link-styled action): remove, pair again, add a site, clear all. */
.link-button {
  width: auto;
  min-height: 36px;
  margin-top: 8px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  text-decoration: none;
}
.link-button:hover:not(:disabled) { background: color-mix(in srgb, var(--surface-2) 88%, var(--text)); }
.link-button.site-remove, #alerts-clear { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 60%, transparent); }

.pair-checking { margin: 0; }
.card h3 { font-size: 1rem; margin: 16px 0 12px; }

/* Sites this device is paired with (S30-F1): one row per site and channel, its state on the right. */
.site-list { list-style: none; margin: 0; padding: 0; }
.site-row { border-left: 4px solid var(--border-strong); border-radius: 6px; background: var(--surface-2); margin: 0 0 8px; padding: 10px 12px; }
.site-row.site-active { border-left-color: var(--success); }
.site-row.site-unreachable { border-left-color: var(--link); }
.site-row.site-removed { border-left-color: var(--danger); }
.site-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.site-name { font-weight: 600; overflow-wrap: anywhere; }
.site-state { font-size: 0.9rem; color: var(--muted); }
.site-active .site-state { color: var(--success); }
.site-unreachable .site-state { color: var(--link); }
.site-removed .site-state { color: var(--danger); }
.site-channel { display: block; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.site-actions { display: flex; flex-wrap: wrap; gap: 0 8px; }
.site-confirm { margin-top: 8px; }
.site-confirm p { margin: 0 0 4px; }
.site-remove-alerts { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 8px; }
.site-remove-alerts input { flex: none; width: auto; margin-top: 3px; }
button.danger { background: var(--danger); color: var(--on-danger); }

/* Recent alerts filter (shown only with two or more sites): "All" and one chip per site. */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chip {
  width: auto;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Recent alerts pager: Previous / "Page X of Y" / Next, ten alerts per page. */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.pager button { width: auto; margin: 0; padding: 8px 14px; }
.pager button:disabled { opacity: 0.5; cursor: default; }
.pager span { flex: 1; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* Recent alerts toolbar: site filter chips on the left (wrapping), Clear all on the right; no row when both are hidden. */
.alerts-toolbar { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.alerts-toolbar:not(:has(> :not([hidden]))) { display: none; }
/* Basis = the chips' own width: when chips and the clear button do not fit on one line, the button wraps below. */
.alerts-toolbar .chip-row { flex: 1 1 auto; min-width: min(100%, 14rem); margin: 0; }
.alerts-toolbar .link-button { margin: 0 0 0 auto; }

/* Recent alerts kept on this device, newest first. The kind shows as the left border. */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { border-left: 4px solid var(--border-strong); border-radius: 6px; background: var(--surface-2); margin: 0 0 8px; }
.alert-item.alert-start { border-left-color: var(--danger); }
.alert-item.alert-reminder { border-left-color: var(--link); }
.alert-item.alert-end { border-left-color: var(--success); }
.alert-content { display: block; padding: 10px 12px; color: var(--text); text-decoration: none; }
.alert-site { display: block; color: var(--link); font-size: 0.85rem; font-weight: 600; overflow-wrap: anywhere; }
.alert-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.alert-body { display: block; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.alert-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-top: 4px; font-size: 0.85rem; color: var(--muted); }
/* "Open image": the same compact secondary button look, a little smaller; a span because the whole entry is the link. */
.alert-open.link-button { display: inline-flex; align-items: center; min-height: 32px; margin: 0; padding: 4px 12px; font-size: 0.9rem; color: var(--link); }

/* Pairing QR scanner overlay: the camera picture is shown and decoded on the device only. */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 12, 14, 0.94);
}
.scanner-panel { width: 100%; max-width: 480px; background: var(--surface); border-radius: var(--radius); padding: 20px; }
.scanner-panel h2 { font-size: 1.1rem; margin: 0 0 12px; }
.scanner video { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); background: #000; }

.message { margin: 12px 0 0; }
.message.error { color: var(--danger); }
.message.ok { color: var(--success); }

.steps { padding-left: 1.4em; }
.steps li { margin-bottom: 8px; }

.note { color: var(--muted); font-size: 0.95rem; }
.moved-notice { border-color: var(--accent); }
.moved-notice p { margin: 0; }
.moved-notice p + p { margin-top: 8px; font-weight: 600; }

.privacy h2 { font-size: 1.1rem; margin-top: 24px; }
.privacy section + section { border-top: 1px solid var(--border); margin-top: 32px; }

.site-footer {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer p { margin: 4px 0; }

/* Incident page (design §18.12): the image fits the card width; pinch zoom stays enabled. */
.snapshot { margin: 0; }
.snapshot img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--bg);
}
.snapshot figcaption { margin-top: 8px; }
/* A grouped alert (owner bug report 2026-10-17): one line per alarm in the inbox, steps and details on the image page. */
.alert-alarms { list-style: none; margin: 6px 0 0; padding: 0; }
.alert-alarm { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 4px 0; border-top: 1px solid var(--border); font-size: 0.9rem; }
.alert-alarm-title { flex: 1 1 100%; overflow-wrap: anywhere; }
.alert-alarm-time, .alert-alarm-number { color: var(--muted); }
.incident-steps { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 8px; }
.incident-details { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 12px; }
.incident-details dt { color: var(--muted); }
.incident-details dd { margin: 0; overflow-wrap: anywhere; }

/* Collapsible cards (This device, Sites): the heading is the toggle; the chevron follows aria-expanded. */
.card h2:has(.panel-toggle) { margin: 0; }
.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: left;
}
.panel-toggle::after {
  content: "";
  flex: none;
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.panel-toggle[aria-expanded="true"]::after { transform: rotate(-135deg); }
#status-body, #sites-body, #alerts-body { margin-top: 12px; }
#status-body[hidden], #sites-body[hidden] { display: none; }
/* Remembered card state, flagged on <html> by js/boot.js before the first paint and removed by js/app.js. */
html[data-panels-closed~="status"] #status-body { display: none; }
html[data-panels-closed~="status"] #status-toggle::after { transform: rotate(45deg); }
html[data-panels-open~="status"] #status-body[hidden] { display: block; }
html[data-panels-open~="status"] #status-toggle::after { transform: rotate(-135deg); }
html[data-panels-closed~="sites"] #sites-body { display: none; }
html[data-panels-closed~="sites"] #sites-toggle::after { transform: rotate(45deg); }
html[data-panels-open~="sites"] #sites-body[hidden] { display: block; }
html[data-panels-open~="sites"] #sites-toggle::after { transform: rotate(-135deg); }
html[data-panels-closed~="alerts"] #alerts-body { display: none; }
html[data-panels-closed~="alerts"] #alerts-toggle::after { transform: rotate(45deg); }
html[data-panels-open~="alerts"] #alerts-body[hidden] { display: block; }
html[data-panels-open~="alerts"] #alerts-toggle::after { transform: rotate(-135deg); }

/* Recent alerts: confirm line of Clear all and the per-alert delete button (a trash icon, no text). */
.inline-confirm { margin: 0 0 12px; }
.inline-confirm p { margin: 0 0 4px; }
.alert-item { position: relative; }
.alert-content { padding-right: 48px; }
.alert-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18M8 6V4h8v2m-9 0 1 14h8l1-14M10 11v6m4-6v6'/%3E%3C/svg%3E") center / 20px no-repeat;
}
.alert-delete:hover, .alert-delete:focus-visible { background-color: rgba(128, 128, 128, 0.2); outline: 2px solid var(--link); }

/* Selected theme and filter chips: neutral grey, not the accent (orange is kept for primary actions). */
.theme-switch button[aria-pressed="true"],
.chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--text) 13%, var(--surface)); color: var(--text);
  border-color: color-mix(in srgb, var(--text) 22%, transparent);
}

/* Touch: no browser tap-highlight flash on buttons and links; a subtle pressed state instead. Keyboard focus keeps
   its :focus-visible ring. */
html { -webkit-tap-highlight-color: transparent; }
.panel-toggle { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.panel-toggle:active { opacity: 0.7; }

/* Privacy page: the first heading of each language section starts right under the header. */
main.privacy section > h2:first-child { margin-top: 8px; }

/* Desktop browsers (js/layout.js WIDE_LAYOUT_QUERY; below it the pages stay phone-first). The header spans the page
   with its content up to 1200px; the burger sheet's content becomes an inline row on the right (the same switch
   elements: js/app.js keeps the sheet shown and the burger hidden here); the sheet chrome is hidden. The home page is a
   two-column dashboard (This device and Sites stacked on the left, Recent alerts on the right, every card open by default and collapsible on its own);
   the other pages are a centred column up to 720px; the footer follows the content width. */
@media (min-width: 900px) {
  .site-header { width: 100%; max-width: 1200px; margin: 0 auto; padding: 16px 24px; }
  .site-header .menu-toggle { display: none; }
  .site-header .header-menu,
  .site-header .header-menu[hidden] {
    position: static;
    inset: auto;
    z-index: auto;
    display: flex !important;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    height: auto;
    overflow: visible;
    padding: 0;
    background: none;
    animation: none;
  }
  .header-menu .menu-label,
  .header-menu .menu-footer { display: none; }
  html.menu-open { overflow: visible; }

  main { max-width: 720px; padding: 0 24px 24px; }
  .site-footer { width: 100%; max-width: 720px; padding: 16px 24px 24px; }

  body[data-page="home"] main,
  body[data-page="home"] .site-footer { max-width: 1200px; }
  body[data-page="home"] main {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    gap: 16px 24px;
    align-items: start;
    padding-top: 16px;
  }
  body[data-page="home"] main > .card { margin: 0; min-width: 0; }
  body[data-page="home"] #status { grid-column: 1; grid-row: 1; }
  body[data-page="home"] #pair { grid-column: 1; grid-row: 2; }
  body[data-page="home"] #alerts { grid-column: 2; grid-row: 1 / span 2; }
  /* Sprint 44 D7: the "moved" notice of the former address spans both columns above the cards. */
  body[data-page="home"] main.has-moved-notice { grid-template-rows: auto auto 1fr; }
  body[data-page="home"] main.has-moved-notice #moved-notice { grid-column: 1 / -1; grid-row: 1; }
  body[data-page="home"] main.has-moved-notice #status { grid-row: 2; }
  body[data-page="home"] main.has-moved-notice #pair { grid-row: 3; }
  body[data-page="home"] main.has-moved-notice #alerts { grid-row: 2 / span 2; }
}

/* Full-screen image viewer (incident page). */
.snapshot img.zoomable { cursor: zoom-in; }
.image-viewer { position: fixed; inset: 0; z-index: 1000; background: #000; overflow: hidden; display: flex; align-items: center; justify-content: center; touch-action: none; }
.image-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; user-select: none; -webkit-user-select: none; }
.image-viewer-bar { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
.image-viewer-bar button { min-width: 44px; min-height: 44px; border-radius: 22px; border: 0; background: rgba(255, 255, 255, 0.85); color: #000; font-size: 1.1rem; }
