/* ═══════════════════════════════════════════════════
   shared.css — components used by BOTH halves of the
   system: the public portal (index.html) and the MIS.
   Barangay Conde Labak, Batangas City

   Rebuilt 2026-07. Three things changed:

     · Design tokens moved out to tokens.css. This file
       used to carry its own :root and [data-theme="dark"]
       blocks; every page must now load tokens.css first.

     · The "MODERN REFRESH" appendix is gone. It sat at
       the bottom re-declaring .btn, .modal-*, .form-*
       and .alert to beat the versions above it, so the
       real value of any property was whichever of the
       two declarations came last. Each component is now
       declared once, with the refreshed values.

     · The MIS shell (sidebar toggle, module launcher,
       staff user menu) moved to system.css. It was only
       ever used by pages/*.html, and keeping it here
       meant every landing-page visitor downloaded it.

   Load order: tokens.css → shared.css → {landing,system}.css
═══════════════════════════════════════════════════ */

/* ─── RESET ────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  /* Anchor targets clear the fixed navbar instead of hiding beneath it. */
  scroll-padding-top: calc(var(--navbar-h) + var(--space-4));
}

body {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  max-width: 100%;
}

/* ═══════════════════════════════════════════════════
   PUBLIC NAVBAR
   index.html only — the MIS carries its brand in the
   sidebar and has no second bar.
═══════════════════════════════════════════════════ */

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--navbar-h);
  padding: 0 var(--space-8);
  background: rgba(9, 18, 40, 0.88);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid rgba(245, 197, 24, 0.28);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  text-decoration: none;
}

.nav-logo img {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 2px solid var(--gold-400);
  object-fit: cover;
}

.nav-brand {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: var(--leading-snug);
  letter-spacing: 0.08em;
  color: var(--gold-400);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  list-style: none;
}

.nav-links a {
  position: relative;
  font-size: 0.82rem;
  font-weight: var(--weight-medium);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.75);
  transition: color var(--duration-base) var(--ease-out);
}

.nav-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -4px;
  width: 0;
  height: 2px;
  background: var(--gold-400);
  transition: width var(--duration-slow) var(--ease-out);
}

.nav-links a:hover {
  color: var(--gold-400);
}

.nav-links a:hover::after {
  width: 100%;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.btn-nav-signin {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  background: var(--gold-400);
  color: var(--navy-800);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.btn-nav-signin:hover {
  background: var(--gold-500);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(245, 197, 24, 0.4);
}

/* Avatar chips — shared because both the portal header and the MIS user menu
   render the same initials disc. */
.nav-user-avatar,
.nav-user-avatar-lg {
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--gold-400);
  color: var(--navy-800);
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
}

.nav-user-avatar {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.nav-user-avatar-lg {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.nav-user-name {
  font-size: 0.78rem;
  font-weight: var(--weight-medium);
  color: rgba(255, 255, 255, 0.85);
}

/* Mobile hamburger (public navbar) */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: var(--space-1);
  border: none;
  background: none;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: var(--gold-400);
  transition: all var(--duration-slow) var(--ease-out);
}

/* The menu button takes over at 1100px, not at the phone breakpoint: the row
   holds seven links once a staff member is signed in (six, plus MIS), and
   below this width it wrapped onto a second line or ran off the edge of the
   screen. */
@media (max-width: 768px) {
  .navbar {
    padding: 0 var(--space-4);
  }
}

@media (max-width: 1100px) {
  .nav-links {
    display: none;
  }

  .nav-links.open {
    position: fixed;
    top: var(--navbar-h);
    left: 0;
    right: 0;
    z-index: 899;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    padding: 1.5rem 2rem;
    background: rgba(9, 18, 40, 0.98);
    border-bottom: 3px solid var(--gold-400);
  }

  .nav-toggle {
    display: flex;
  }
}

/* ═══════════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: rgba(6, 14, 27, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  position: relative;
  width: 560px;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xl);
  animation: modalIn var(--duration-slow) var(--ease-out);
}

.modal-box.modal-lg {
  width: 720px;
}

.modal-box.modal-xl {
  width: 920px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* The header used to be a navy bar with white text — a heavy lid on every
   dialog, and a second brand colour competing with the content. It is now the
   same surface as the body, separated by a hairline. */
.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-4);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 1.05rem;
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-brand);
}

.modal-title-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  color: var(--accent-fg);
  font-size: 1rem;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  position: sticky;
  bottom: 0;
  /* It is .modal-box that scrolls, not the body, so the footer sticks over
     content that is still there underneath it — and a positioned descendant
     with a z-index of its own paints straight through it. The GIS map inside
     the incident modal has several (its toolbar at 5, "Use my location" at
     10, the elements panel at 30), and on a phone, where the map's bottom
     edge lands on the footer, they were drawn across the Submit button.
     --z-sticky is above all of them and still local to the box. */
  z-index: var(--z-sticky);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ═══════════════════════════════════════════════════
   CONFIRM / PROMPT DIALOG
   Built by uiConfirm()/uiPrompt() in js/shell.js for the
   actions that used to raise window.confirm() and
   window.prompt() — deleting a record, adding a role,
   clearing the audit trail.

   Deliberately narrower and quieter than a full modal:
   no header bar, no close X. It is one question, and the
   only ways out are the two buttons or Escape. The
   layout answers three things in order — what is being
   done (icon + title), to what (the target chip), and
   what happens next (the notes list).
═══════════════════════════════════════════════════ */

.confirm-box {
  width: 460px;
  padding: var(--space-6);
}

.confirm-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

/* Big enough to register as a warning before the title is read. */
.confirm-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  font-size: 1.25rem;
}

.confirm-icon-danger {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}

.confirm-icon-accent {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent-fg);
}

.confirm-heading {
  min-width: 0;
}

.confirm-title {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-snug);
  color: var(--text-primary);
}

.confirm-message {
  margin: var(--space-2) 0 0;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}

/* The record itself, quoted back so there is no doubt which row was clicked. */
.confirm-target {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger-solid);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.confirm-target i {
  flex-shrink: 0;
  color: var(--text-muted);
}

.confirm-target-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* An accent-tone dialog is additive (Add Role), not destructive — its target
   chip should not wear a red edge. */
.confirm-box-accent .confirm-target {
  border-left-color: var(--accent);
}

.confirm-field {
  margin-top: var(--space-5);
}

.confirm-field .form-label {
  margin-bottom: var(--space-2);
}

.confirm-hint {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--text-muted);
}

/* What the action will actually do, one consequence per line. */
.confirm-notes {
  margin: var(--space-5) 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.confirm-notes li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
  color: var(--text-secondary);
}

.confirm-notes i {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--text-muted);
}

.confirm-error {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--danger);
}

.confirm-error[hidden] {
  display: none;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

/* On a phone the two buttons stack full-width, destructive one last. */
@media (max-width: 480px) {
  .confirm-box {
    padding: var(--space-5);
  }

  .confirm-actions {
    flex-direction: column-reverse;
  }

  .confirm-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ═══════════════════════════════════════════════════
   FORMS
═══════════════════════════════════════════════════ */

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: 11.5px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  outline: none;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:hover:not(:disabled):not(:focus) {
  border-color: var(--border-strong);
}

.form-control:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 16%, transparent);
}

.form-control:disabled {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Native selects render an OS-coloured arrow that clashes in dark mode; a
   drawn caret keeps the control on-theme. */
select.form-control {
  appearance: none;
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 2px),
    calc(100% - 13px) calc(50% + 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  color: var(--text-primary);
  cursor: pointer;
}

/* The certificate picker: a box to type in that narrows a list as you go
   (renderCertTypeGrid / bindCertCombo in js/portal-account.js). It wears the
   select's caret so it still reads as "pick one of these". */
.cert-combo {
  position: relative;
}

.form-control.cert-combo-input {
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 2px),
    calc(100% - 13px) calc(50% + 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.cert-combo-list {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  max-height: 264px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.cert-combo-list[hidden] {
  display: none;
}

.cert-combo-option,
.cert-combo-empty {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.cert-combo-option {
  color: var(--text-primary);
  cursor: pointer;
}

.cert-combo-option:hover,
.cert-combo-option.active {
  background: var(--surface-hover);
}

.cert-combo-option[aria-selected="true"] {
  font-weight: var(--weight-semibold);
}

.cert-combo-option mark {
  background: none;
  color: inherit;
  font-weight: var(--weight-bold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cert-combo-empty {
  color: var(--text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 90px;
  line-height: var(--leading-normal);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.form-error {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--danger);
}

.form-control[aria-invalid="true"],
.form-control.error {
  border-color: var(--danger-solid);
}

.form-control[aria-invalid="true"]:focus,
.form-control.error:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger-solid) 18%, transparent);
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ═══════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
  white-space: nowrap;
  /* .btn is worn by <a> as well as <button> (Cancel on claim-account, Preview
     in Site Content). Without this the anchors alone came out underlined. */
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--navy-800);
  border-color: var(--navy-800);
  color: var(--on-brand);
}

.btn-primary:hover:not(:disabled) {
  background: var(--navy-700);
  box-shadow: 0 6px 16px -6px rgba(13, 27, 62, 0.45);
}

.btn-gold {
  background: var(--gold-400);
  border-color: var(--gold-400);
  color: var(--navy-800);
}

.btn-gold:hover:not(:disabled) {
  background: var(--gold-500);
  box-shadow: 0 6px 16px -6px rgba(212, 160, 23, 0.55);
}

.btn-outline {
  background: var(--surface-raised);
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger-solid) 18%, var(--danger-bg));
}

/* Solid destructive — for the confirm step, never the trigger. */
.btn-danger-strong {
  background: var(--danger-solid);
  border-color: var(--danger-solid);
  color: #fff;
}

.btn-danger-strong:hover:not(:disabled) {
  background: var(--red-600);
  box-shadow: 0 6px 16px -6px rgba(220, 38, 38, 0.5);
}

.btn-danger-outline {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-ghost {
  background: none;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
}

/* Square icon-only button. */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ═══════════════════════════════════════════════════
   ALERTS
═══════════════════════════════════════════════════ */

/* NOT a flex row, deliberately. Flexbox makes every element child a flex item
   and wraps each run of text BETWEEN them in an anonymous one, so a message
   written as a sentence —
       For life-threatening emergencies, call <strong>911</strong> or the
       barangay hotline at <strong data-hotline>043-702-8875</strong> immediately.
   — was laid out as six columns side by side instead of as a sentence. On a
   390px phone that alert stood 107px tall with its words in four-line
   ribbons, the phone number squeezed into 30px, and "immediately." running
   54px past the right edge. 21 of the 85 alerts in the system are written
   that way (the emergency card on every MIS page, the three staff briefing
   notices, the SMS verification notes), so this is fixed here rather than by
   wrapping each message in a span.

   Block flow with a hanging indent: the message is ordinary inline text that
   wraps as prose, and the icon sits in the gutter the padding reserves. */
.alert {
  display: block;
  position: relative;
  margin-bottom: var(--space-3);
  padding: var(--space-3) var(--space-4);
  padding-inline-start: calc(var(--space-4) + 1rem + var(--space-3));
  border: 1px solid;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.alert-icon {
  position: absolute;
  inset-inline-start: var(--space-4);
  top: var(--space-3);
  display: inline-flex;
  align-items: center;
  /* As tall as the message's first line box, so the glyph centres on that
     line whatever the type size. Centring it on the alert as a whole — which
     is what `align-items: center` did — parked it halfway down the left edge
     of any alert that ran to more than one line. */
  height: calc(var(--text-sm) * var(--leading-normal));
  font-size: 1rem;
}

/* An alert that is a short stack of lines rather than one sentence: the
   emergency card puts 911 on one line and the barangay hotline on the next,
   so neither number can be pushed off the edge by the words around it. */
.alert-lines,
.alert-lines > span {
  display: block;
}

.alert-lines > span + span {
  margin-top: 2px;
}

.alert-close {
  flex-shrink: 0;
  margin-left: auto;
  padding: var(--space-1);
  border: none;
  border-radius: var(--radius-xs);
  background: none;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.6;
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.alert-close:hover {
  opacity: 1;
}

.alert-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}

.alert-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.alert-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

/* ═══════════════════════════════════════════════════
   BADGES
═══════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid;
  border-radius: var(--radius-full);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.badge-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

.badge-gold {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--accent-fg);
}

.badge-gray {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════
   PROGRESS
═══════════════════════════════════════════════════ */

.progress-bar {
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--gold-600);
  transition: width 1s var(--ease-out);
}

/* ═══════════════════════════════════════════════════
   PREFERENCES MODAL  (js/preferences.js)
   Grouped settings rows: an uppercase group label, a bordered card of
   rows separated by hairlines, an optional caption.
═══════════════════════════════════════════════════ */

.pref-group {
  margin-bottom: var(--space-6);
}

.pref-group:last-child {
  margin-bottom: 0;
}

.pref-group-title {
  margin: 0 0 var(--space-2) var(--space-1);
  font-size: 0.72rem;
  font-weight: var(--weight-extrabold);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pref-group-body {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.pref-group-caption {
  margin: var(--space-2) var(--space-1) 0;
  font-size: 0.82rem;
  line-height: var(--leading-normal);
  color: var(--text-muted);
}

/* One row. Buttons are reset to look like the non-interactive rows. */
.pref-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-4);
  border: 0;
  background: none;
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  color: var(--text-primary);
}

.pref-row + .pref-row {
  border-top: 1px solid var(--border);
}

.pref-row-btn {
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}

.pref-row-btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.pref-row-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* A <label> wrapping a switch: the whole row is the hit target, so it should
   say so rather than showing a text caret over the title. */
.pref-row-switch {
  cursor: pointer;
}

.pref-row-switch:hover {
  background: var(--surface-hover);
}

/* A switch the server will refuse: shown, not hidden, because the reason it
   cannot be turned on is the thing the person came to find out. */
.pref-row-switch.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.pref-row-switch.is-disabled:hover {
  background: none;
}

/* ── "My SMS alerts" checklist (js/sms-alerts.js) ───────────────────────
   Four conditions, all of which must hold before a report text reaches an
   official. Printed as a list rather than a sentence so the one that is
   missing is the one the eye lands on. */
.sms-checklist {
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.sms-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.sms-check i {
  flex: none;
  margin-top: 1px;
  color: var(--danger);
}

.sms-check.is-on {
  color: var(--text-secondary);
}

.sms-check.is-on i {
  color: var(--success-solid);
}

/* The reason a condition is not met, inline after it. */
.sms-check-why {
  color: var(--text-muted);
}

.sms-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.pref-row-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--navy-800) 8%, transparent);
  color: var(--navy-800);
}

/* On dark the navy tint disappears into the card — gold reads instead. */
[data-theme="dark"] .pref-row-icon {
  background: color-mix(in srgb, var(--gold-600) 14%, transparent);
  color: var(--gold-300);
}

.pref-row-icon svg {
  width: 19px;
  height: 19px;
}

.pref-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pref-row-title {
  font-size: 0.92rem;
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.pref-row-sub {
  font-size: 0.8rem;
  line-height: var(--leading-snug);
  color: var(--text-muted);
}

.pref-row-value {
  flex-shrink: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pref-row-check {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--border-strong);
}

.pref-row-check svg {
  width: 21px;
  height: 21px;
}

.pref-row.is-selected .pref-row-check {
  color: var(--gold-600);
}

.pref-row.is-selected .pref-row-icon {
  background: color-mix(in srgb, var(--gold-600) 18%, transparent);
  color: var(--gold-800);
}

[data-theme="dark"] .pref-row.is-selected .pref-row-icon {
  color: var(--gold-300);
}

/* Switch — a styled checkbox, so the row stays a <label> and keeps keyboard
   and assistive-tech behaviour for free. */
.pref-switch {
  flex-shrink: 0;
  position: relative;
  display: inline-grid;
  place-items: center;
}

.pref-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.pref-switch-track {
  display: block;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  transition: background var(--duration-fast) var(--ease-out);
}

.pref-switch-thumb {
  display: block;
  width: 20px;
  height: 20px;
  margin: 3px;
  border-radius: var(--radius-full);
  background: #f4f6fb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--duration-fast) var(--ease-out);
}

.pref-switch input:checked + .pref-switch-track {
  background: var(--gold-600);
}

.pref-switch input:checked + .pref-switch-track .pref-switch-thumb {
  transform: translateX(18px);
}

.pref-switch input:focus-visible + .pref-switch-track {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════
   CHANGE-PASSWORD MODAL  (js/change-password.js)
   Reveal toggles, three-segment strength meter, and the
   confirm-match line.
═══════════════════════════════════════════════════ */

.cp-field {
  position: relative;
}

/* Leave room for the reveal button so long values don't run under it. */
.cp-field .form-control {
  padding-right: 44px;
}

.cp-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.cp-eye:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.cp-eye svg {
  width: 18px;
  height: 18px;
}

.cp-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-5) 0;
}

.cp-strength {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin: var(--space-2) 0 0 2px;
}

.cp-strength-seg {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--duration-fast) var(--ease-out);
}

.cp-strength-label {
  flex-shrink: 0;
  margin-left: 6px;
  font-size: 0.78rem;
  font-weight: var(--weight-bold);
}

/* Weak / fair / strong — red, gold, green. */
.cp-weak .cp-strength-seg.is-on {
  background: var(--danger-solid);
}
.cp-weak .cp-strength-label {
  color: var(--danger-solid);
}

.cp-fair .cp-strength-seg.is-on {
  background: var(--gold-600);
}
.cp-fair .cp-strength-label {
  color: var(--accent-fg);
}

.cp-strong .cp-strength-seg.is-on {
  background: var(--success-solid);
}
.cp-strong .cp-strength-label {
  color: var(--success);
}

.cp-match {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0 2px;
  font-size: 0.8rem;
}

.cp-match svg {
  width: 14px;
  height: 14px;
}

.cp-match.is-ok {
  color: var(--success);
}

.cp-match.is-bad {
  color: var(--danger-solid);
}

/* ═══════════════════════════════════════════════════
   AI LOADING + FALLBACK  (dashboard briefing, GIS briefing)
   Shared because both panels show the same two states: a regeneration in
   flight (several seconds — the model thinks before it writes), and
   figures-only mode when the quota is spent.
   ═══════════════════════════════════════════════════ */
.ai-loading-note {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.ai-spinner {
  flex: none;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
}
@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Skeleton lines in the final layout, so nothing jumps when the text lands. */
.ai-skel {
  height: 9px;
  margin-bottom: 6px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(127, 127, 127, 0.13) 25%,
    rgba(127, 127, 127, 0.22) 37%,
    rgba(127, 127, 127, 0.13) 63%
  );
  background-size: 400% 100%;
  animation: ai-shimmer 1.3s ease-in-out infinite;
}
.ai-skel-head {
  width: 55%;
  height: 8px;
  margin-bottom: 8px;
}
.ai-skel-short {
  width: 70%;
}
@keyframes ai-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* Figures-only banner. The numbers below it are real SQL results; only the
   phrasing and the recommendations are missing, so this must be unmistakable
   without looking like an error. */
.ai-fallback-note {
  grid-column: 1 / -1;
  margin-bottom: 8px;
  padding: 5px 9px;
  border-radius: var(--radius);
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.4);
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

/* The figures moved after this briefing was written. Amber, not grey: unlike
   the figures-only note, this one asks the reader to do something. */
.ai-stale-note {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.45);
  color: var(--text);
}
/* "Written <time> · <model>" under the dashboard briefing's columns. */
.ai-summary-stamp {
  grid-column: 1 / -1;
  font-size: 10.5px;
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .ai-spinner,
  .ai-skel {
    animation: none;
  }
}

/* ═══════════════════════════════════════════════════
   SERVER WAKE-UP  (js/api.js)
   Covers the page while the hosted server starts after a quiet spell, so
   nobody reads its empty tables as "no records". Opaque on purpose, and above
   everything: nothing under it has its data yet.
   ═══════════════════════════════════════════════════ */
.server-wake {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-toast) + 10);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--surface);
  font-family: var(--font-sans);
  animation: server-wake-in var(--duration-slow) var(--ease-out);
}
.server-wake.is-leaving {
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-out);
}
.server-wake-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.server-wake-seal {
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
}
.server-wake-title {
  margin: 0 0 8px;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.server-wake-body {
  margin: 0 0 16px;
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--text-secondary);
}
.server-wake-wait {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.server-wake-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
}
.server-wake-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.server-wake-actions button {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}
.server-wake-reload {
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
}
.server-wake-continue {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-secondary);
}
.server-wake-actions button:hover {
  filter: brightness(1.08);
}
.server-wake-actions button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
@keyframes server-wake-in {
  from {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .server-wake,
  .server-wake-spinner {
    animation: none;
  }
  .server-wake.is-leaving {
    transition: none;
  }
}

/* ═══════════════════════════════════════════════════
   EDIT MY DETAILS  (Settings → My Account, js/account-edit.js)
   The resident-facing half of the profile-change flow. The staff half
   (review / approve) lives on the Residency page and uses .er-* below.
═══════════════════════════════════════════════════ */

.acct-edit-loading {
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
}

.acct-edit-error {
  min-height: 16px;
  margin-top: 4px;
  font-size: 13px;
  color: #b91c1c;
}

/* Shown instead of the form while a request is still awaiting review. It
   replaces the form rather than disabling it: filling in ten fields only to be
   told at submit that the API refuses a second open request is a worse
   experience than being told first. */
.acct-edit-pending {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.35);
}

.acct-edit-pending-icon {
  flex-shrink: 0;
  font-size: 20px;
  color: #a16207;
}

.acct-edit-pending p {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: var(--leading-snug);
  color: var(--text-secondary);
}

.acct-edit-pending-reason {
  font-style: italic;
}

.acct-edit-history {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.acct-edit-history-title {
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: var(--weight-extrabold);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.acct-edit-history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.acct-edit-history-item:last-child {
  border-bottom: 0;
}

.acct-edit-history-fields {
  flex: 1;
  min-width: 120px;
  color: var(--text-secondary);
}

.acct-edit-history-date {
  color: var(--text-muted);
}

.acct-edit-history-remarks {
  flex-basis: 100%;
  color: var(--text-muted);
  font-style: italic;
}

/* Profile photo picker (Settings → Edit my details). Preview on the left,
   the controls and the "proper pictures only" note on the right. */
.acct-edit-photo-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.acct-edit-photo {
  flex-shrink: 0;
  width: 84px;
  height: 84px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-hover);
}

.acct-edit-photo-empty {
  display: grid;
  place-items: center;
  font-size: 30px;
  color: var(--text-muted);
}

.acct-edit-photo-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* The note is the rule staff will reject against, so it takes the full row
   under the buttons rather than being squeezed beside them. */
.acct-edit-photo-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 12px;
  line-height: var(--leading-snug);
  color: var(--text-muted);
}

.acct-edit-photo-note i {
  color: var(--gold-600);
}

/* ── Household picker (Edit My Details) ───────────────────────────────────
   A search, not a dropdown: the staff household list carries member counts
   and classifications, which a resident must not be handed about their
   neighbours. See GET /api/households/lookup. */
.acct-edit-household {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-hover);
}

/* A picked household differs from the record — say so before it is submitted,
   since this is the one field whose "before" is not visible in an input. */
.acct-edit-household.is-changed {
  border-color: var(--gold-600);
}

.acct-edit-household-now {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 600;
}

.acct-edit-household-now > span:first-of-type {
  flex: 1;
  min-width: 0;
}

.acct-edit-household-now i {
  color: var(--gold-600);
}

.acct-edit-household-none {
  font-weight: 400;
  color: var(--text-muted);
}

.acct-edit-household-results:empty {
  display: none;
}

.acct-edit-household-results {
  display: flex;
  flex-direction: column;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.acct-edit-household-hit {
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.acct-edit-household-hit:last-child {
  border-bottom: 0;
}

.acct-edit-household-hit:hover,
.acct-edit-household-hit:focus-visible {
  background: var(--surface-hover);
}

.acct-edit-household-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.acct-edit-household-note {
  margin: 0;
  font-size: 12px;
  line-height: var(--leading-snug);
  color: var(--text-muted);
}

.acct-edit-household-note i {
  color: var(--gold-600);
}

@media (max-width: 520px) {
  .acct-edit-photo-row {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .acct-edit-photo-actions {
    justify-content: center;
  }
}

/* ── Session avatar photo ──────────────────────────────────────────────────
   The sidebar pill, the topbar trigger and the dropdown header all render the
   signed-in user's initials by default. When that user has a profile photo,
   loadSessionAvatar() (js/account-edit.js) sets it as a background image and
   adds .has-photo, which hides the initials underneath rather than swapping
   the element — several places query these ids and they have to survive.

   In shared.css, not system.css: the landing page paints the same avatar and
   only loads this stylesheet. */
.user-avatar.has-photo,
.nav-user-avatar.has-photo,
.nav-user-avatar-lg.has-photo {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* The gold/navy fill is the initials backdrop; behind a photo it would show
     as a rim on a source that isn't perfectly square. */
  background-color: var(--surface-hover);
  color: transparent;
  /* A hairline keeps a light photo from bleeding into a light bar. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}


/* ── Language sweep ──────────────────────────────────────────────────────
   The wipe that plays when the language changes, driven by js/i18n.js.

   A MASK, not one span per letter. Splitting the landing page's 3,386
   on-screen translated characters into their own elements would take a
   1,037-element page past 4,400 — and a character sitting in its own
   inline-block no longer wraps like a character inside a word, so lines
   would break mid-word. A mask adds no nodes at all and never reaches
   layout: it is paint only, and the text keeps wrapping the way it always
   did.

   The mask is three times the width of the element — a clear third, a
   ramp, and an opaque third — so sliding it from 100% to 0% walks the
   boundary across the text from left to right. WHICH third starts under
   the text is the only difference between the half that takes the old
   words away and the half that brings the new ones in, which is why both
   animate in the same direction and only the gradient is swapped.

   --sweep-pos is the only thing that moves. Everything else is set once by
   the script, and the whole lot is stripped off the element when the sweep
   finishes, so nothing here is paid for while the page is just sitting
   there.                                                                   */
[data-i18n-sweep] {
  -webkit-mask-image: var(--sweep-img);
  mask-image: var(--sweep-img);
  -webkit-mask-size: 300% 100%;
  mask-size: 300% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: var(--sweep-pos, 100% 0);
  mask-position: var(--sweep-pos, 100% 0);
}

/* Leaving: clear third first, so the text empties from the left. */
[data-i18n-sweep="go"] {
  --sweep-img: linear-gradient(
    90deg,
    transparent 0%,
    transparent 40%,
    #000 60%,
    #000 100%
  );
}

/* Arriving: opaque third first, so the text fills from the left. */
[data-i18n-sweep="come"] {
  --sweep-img: linear-gradient(
    90deg,
    #000 0%,
    #000 40%,
    transparent 60%,
    transparent 100%
  );
}

/* Added a frame after the starting position is committed — set together,
   the browser folds the two into one and nothing moves. */
[data-i18n-sweep].is-sweeping {
  transition:
    -webkit-mask-position var(--sweep-ms, 200ms) linear var(--sweep-delay, 0ms),
    mask-position var(--sweep-ms, 200ms) linear var(--sweep-delay, 0ms);
}

/* The script checks this too and swaps the text outright; this is here so a
   sweep already running when the setting changes cannot leave text masked. */
@media (prefers-reduced-motion: reduce) {
  [data-i18n-sweep] {
    -webkit-mask-image: none;
    mask-image: none;
    transition: none;
  }
}
