/* Leak Hunter Design System v1 foundation. Existing pages keep their local styles. */
:root {
  /* Canonical palette: RGB channels are the only numeric color definitions. */
  --lh-color-brand-navy-rgb: 10 25 41;
  --lh-color-brand-navy: rgb(var(--lh-color-brand-navy-rgb));
  --lh-color-brand-orange-rgb: 255 140 0;
  --lh-color-brand-orange: rgb(var(--lh-color-brand-orange-rgb));
  --lh-color-brand-orange-hover-rgb: 230 122 0;
  --lh-color-brand-orange-hover: rgb(var(--lh-color-brand-orange-hover-rgb));
  --lh-color-brand-yellow-rgb: 255 215 0;
  --lh-color-brand-yellow: rgb(var(--lh-color-brand-yellow-rgb));
  --lh-color-success-rgb: 40 167 69;
  --lh-color-success: rgb(var(--lh-color-success-rgb));
  --lh-color-danger-rgb: 220 53 69;
  --lh-color-danger: rgb(var(--lh-color-danger-rgb));
  --lh-color-info-rgb: 96 165 250;
  --lh-color-info: rgb(var(--lh-color-info-rgb));
  --lh-color-white-rgb: 255 255 255;
  --lh-color-black-rgb: 0 0 0;
  --lh-color-text-muted-rgb: 203 213 225;
  --lh-color-text-subtle-rgb: 148 163 184;
  --lh-color-surface-raised-rgb: 19 40 59;
  --lh-color-border-subtle-rgb: 148 163 184;
  --lh-color-glass-public-rgb: 15 23 42;

  --lh-surface-canvas: var(--lh-color-brand-navy);
  --lh-surface-raised: rgb(var(--lh-color-surface-raised-rgb));
  --lh-border-subtle: rgb(var(--lh-color-border-subtle-rgb) / 20%);
  --lh-surface-glass-app: rgb(var(--lh-color-white-rgb) / 10%);
  --lh-border-glass-app: rgb(var(--lh-color-white-rgb) / 20%);
  --lh-surface-glass-public: rgb(var(--lh-color-glass-public-rgb) / 75%);
  --lh-border-glass-public: rgb(var(--lh-color-border-subtle-rgb) / 45%);
  --lh-glass-app-blur: 10px;
  --lh-glass-public-blur: 14px;
  --lh-text-primary: rgb(var(--lh-color-white-rgb));
  --lh-text-muted: rgb(var(--lh-color-text-muted-rgb));
  --lh-text-subtle: rgb(var(--lh-color-text-subtle-rgb));
  --lh-focus-ring: rgb(var(--lh-color-brand-orange-rgb) / 45%);
  --lh-focus-outline-width: 2px;
  --lh-focus-outline-offset: 2px;

  /* Component-local sizing; global spacing/type scales remain deferred. */
  --lh-control-padding-x: 0.875rem;
  --lh-control-padding-y: 0.625rem;
  --lh-control-gap: 0.5rem;
  --lh-control-radius: 0.5rem;
  --lh-control-font-size: 1rem;
  --lh-control-line-height: 1.25;
  --lh-compact-font-size: 0.875rem;
  --lh-large-font-size: 1.125rem;
  --lh-card-radius: 0.75rem;
  --lh-card-padding: 1.25rem;
  --lh-field-gap: 0.5rem;
  --lh-component-shadow: 0 8px 24px rgb(var(--lh-color-black-rgb) / 18%);
}

/* Semantic alternatives for the two existing glass contexts. */
.lh-glass-app,
.lh-card--glass-app {
  background: var(--lh-surface-glass-app);
  -webkit-backdrop-filter: blur(var(--lh-glass-app-blur));
  backdrop-filter: blur(var(--lh-glass-app-blur));
  border: 1px solid var(--lh-border-glass-app);
}

.lh-glass-public,
.lh-card--glass-public {
  background: var(--lh-surface-glass-public);
  -webkit-backdrop-filter: blur(var(--lh-glass-public-blur));
  backdrop-filter: blur(var(--lh-glass-public-blur));
  border: 1px solid var(--lh-border-glass-public);
}

/* Button */
.lh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--lh-control-gap);
  min-height: 2.5rem;
  padding: var(--lh-control-padding-y) var(--lh-control-padding-x);
  border: 1px solid transparent;
  border-radius: var(--lh-control-radius);
  font: inherit;
  font-size: var(--lh-control-font-size);
  font-weight: 600;
  line-height: var(--lh-control-line-height);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease,
    box-shadow 160ms ease, transform 160ms ease;
}

.lh-btn--primary { color: var(--lh-color-brand-navy); background: var(--lh-color-brand-orange); }
.lh-btn--primary:hover { background: var(--lh-color-brand-orange-hover); }
.lh-btn--secondary { color: var(--lh-text-primary); background: var(--lh-surface-raised); border-color: var(--lh-border-subtle); }
.lh-btn--secondary:hover { background: rgb(var(--lh-color-surface-raised-rgb) / 80%); }
.lh-btn--ghost { color: var(--lh-text-primary); background: transparent; border-color: transparent; }
.lh-btn--ghost:hover { background: rgb(var(--lh-color-white-rgb) / 10%); }
.lh-btn--danger { color: var(--lh-text-primary); background: var(--lh-color-danger); }
.lh-btn--danger:hover { background: rgb(var(--lh-color-danger-rgb) / 85%); }
.lh-btn--success { color: var(--lh-color-brand-navy); background: var(--lh-color-success); }
.lh-btn--success:hover { background: rgb(var(--lh-color-success-rgb) / 85%); }
.lh-btn--link { min-height: 0; padding: 0; color: var(--lh-color-brand-orange); background: transparent; text-decoration: underline; text-underline-offset: 0.2em; }
.lh-btn--link:hover { color: var(--lh-color-brand-orange-hover); }
.lh-btn--sm { min-height: 2rem; padding: 0.375rem 0.625rem; font-size: var(--lh-compact-font-size); }
.lh-btn--md { min-height: 2.5rem; }
.lh-btn--lg { min-height: 3rem; padding: 0.75rem 1.25rem; font-size: var(--lh-large-font-size); }
.lh-btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(1px); }
.lh-btn:focus-visible { outline: 2px solid var(--lh-focus-ring); outline-offset: 2px; box-shadow: 0 0 0 4px rgb(var(--lh-color-brand-orange-rgb) / 18%); }
.lh-btn:disabled,
.lh-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.lh-btn.is-loading,
.lh-btn[aria-busy="true"] { cursor: progress; }
.lh-btn.is-loading::after,
.lh-btn[aria-busy="true"]::after {
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: lh-spin 700ms linear infinite;
}

/* Card */
.lh-card { border: 1px solid var(--lh-border-subtle); border-radius: var(--lh-card-radius); padding: var(--lh-card-padding); box-shadow: var(--lh-component-shadow); }
.lh-card--surface { background: var(--lh-surface-raised); }
.lh-card--flush { padding: 0; overflow: hidden; }
.lh-card--interactive { transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease; }
.lh-card--interactive:hover { transform: translateY(-2px); border-color: rgb(var(--lh-color-brand-orange-rgb) / 45%); }
.lh-card--interactive:focus-visible { outline: 2px solid var(--lh-focus-ring); outline-offset: 2px; }
.lh-card--stat { border-inline-start: 3px solid var(--lh-color-brand-orange); }

/* Field and controls */
.lh-field { display: grid; gap: var(--lh-field-gap); }
.lh-field__label { color: var(--lh-text-primary); font-weight: 500; }
.lh-field__help { color: var(--lh-text-muted); font-size: 0.875rem; }
.lh-field__error { color: var(--lh-color-danger); font-size: 0.875rem; }
.lh-input,
.lh-field input:not([type="checkbox"]):not([type="radio"]),
.lh-field textarea,
.lh-field select {
  width: 100%;
  min-height: 2.5rem;
  padding: var(--lh-control-padding-y) var(--lh-control-padding-x);
  border: 1px solid var(--lh-border-subtle);
  border-radius: var(--lh-control-radius);
  color: var(--lh-text-primary);
  background: rgb(var(--lh-color-brand-navy-rgb) / 72%);
  font: inherit;
  color-scheme: dark;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.lh-input::placeholder,
.lh-field textarea::placeholder { color: var(--lh-text-subtle); }
.lh-input--compact { min-height: 2rem; padding: 0.375rem 0.625rem; font-size: var(--lh-compact-font-size); }
.lh-input--default { min-height: 2.5rem; }
.lh-input:focus-visible,
.lh-field input:focus-visible,
.lh-field textarea:focus-visible,
.lh-field select:focus-visible { outline: 2px solid var(--lh-focus-ring); outline-offset: 1px; border-color: var(--lh-color-brand-orange); }
.lh-input:disabled,
.lh-field input:disabled,
.lh-field textarea:disabled,
.lh-field select:disabled { opacity: 0.55; cursor: not-allowed; }
.lh-field.lh-field--error .lh-input,
.lh-field.lh-field--error input:not([type="checkbox"]):not([type="radio"]),
.lh-field.lh-field--error textarea,
.lh-field.lh-field--error select,
.lh-input.is-error { border-color: var(--lh-color-danger); }

.lh-choice { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--lh-text-primary); cursor: pointer; }
.lh-choice input,
.lh-checkbox,
.lh-radio { width: 1rem; height: 1rem; accent-color: var(--lh-color-brand-orange); }
.lh-choice input:focus-visible,
.lh-checkbox:focus-visible,
.lh-radio:focus-visible { outline: 2px solid var(--lh-focus-ring); outline-offset: 2px; }
.lh-choice input:disabled,
.lh-checkbox:disabled,
.lh-radio:disabled { opacity: 0.55; cursor: not-allowed; }

/* Badge */
.lh-badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.55rem; border: 1px solid transparent; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; line-height: 1.25; }
.lh-badge--neutral { color: var(--lh-text-muted); background: rgb(var(--lh-color-white-rgb) / 8%); border-color: var(--lh-border-subtle); }
.lh-badge--info { color: var(--lh-color-info); background: rgb(var(--lh-color-info-rgb) / 12%); border-color: rgb(var(--lh-color-info-rgb) / 35%); }
.lh-badge--success { color: var(--lh-color-success); background: rgb(var(--lh-color-success-rgb) / 12%); border-color: rgb(var(--lh-color-success-rgb) / 35%); }
.lh-badge--warning { color: var(--lh-color-brand-yellow); background: rgb(var(--lh-color-brand-yellow-rgb) / 12%); border-color: rgb(var(--lh-color-brand-yellow-rgb) / 35%); }
.lh-badge--danger { color: var(--lh-color-danger); background: rgb(var(--lh-color-danger-rgb) / 12%); border-color: rgb(var(--lh-color-danger-rgb) / 35%); }
.lh-badge--brand { color: var(--lh-color-brand-orange); background: rgb(var(--lh-color-brand-orange-rgb) / 12%); border-color: rgb(var(--lh-color-brand-orange-rgb) / 35%); }

/* Page Header */
.lh-page-header {
  width: 100%;
  max-width: none;
  min-height: 3.5rem;
  margin: 0 0 1.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  color: var(--lh-text-primary);
}
.lh-page-header__spacer { min-width: 0; }
.lh-page-header__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 0;
  max-width: 100%;
  text-align: center;
}
.lh-page-header__title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  max-width: 100%;
  min-width: 0;
}
.lh-page-header__icon {
  flex: 0 0 auto;
  color: var(--lh-color-brand-orange);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
}
.lh-page-header__title {
  margin: 0;
  min-width: 0;
  color: var(--lh-text-primary);
  font-size: clamp(1.5rem, 2.3vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
}
.lh-page-header__description {
  max-width: 64rem;
  margin: 0;
  color: var(--lh-text-muted);
  font-size: 0.9375rem;
  line-height: 1.5;
  text-align: center;
}
.lh-page-header__actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.lh-section-heading { margin-bottom: 1.25rem; }
.lh-section-heading__title-row { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.lh-section-heading__icon { flex: 0 0 auto; color: var(--lh-color-brand-orange); }
.lh-section-heading__title { margin: 0; color: var(--lh-text-primary); font-size: 1.125rem; font-weight: 600; line-height: 1.35; }
.lh-section-heading__description { margin: 0.35rem 0 0; color: var(--lh-text-muted); font-size: 0.875rem; line-height: 1.5; }
@media (max-width: 640px) {
  .lh-page-header {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 0.75rem;
    text-align: center;
  }
  .lh-page-header__spacer { display: none; }
  .lh-page-header__actions { justify-content: center; flex-wrap: wrap; }
}

/* Alert */
.lh-alert { padding: 0.875rem 1rem; border: 1px solid transparent; border-radius: var(--lh-control-radius); color: var(--lh-text-primary); }
.lh-alert--info { background: rgb(var(--lh-color-info-rgb) / 12%); border-color: rgb(var(--lh-color-info-rgb) / 35%); }
.lh-alert--success { background: rgb(var(--lh-color-success-rgb) / 12%); border-color: rgb(var(--lh-color-success-rgb) / 35%); }
.lh-alert--warning { background: rgb(var(--lh-color-brand-yellow-rgb) / 12%); border-color: rgb(var(--lh-color-brand-yellow-rgb) / 35%); }
.lh-alert--danger { background: rgb(var(--lh-color-danger-rgb) / 12%); border-color: rgb(var(--lh-color-danger-rgb) / 35%); }

@keyframes lh-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .lh-btn,
  .lh-card--interactive { transition-duration: 0.01ms; }
  .lh-btn.is-loading::after,
  .lh-btn[aria-busy="true"]::after { animation-duration: 1400ms; }
}

/* Keep fixed modal overlays and their panels within the visible viewport. */
.fixed.inset-0 {
  box-sizing: border-box;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.fixed.inset-0 > :not(.absolute):not(.fixed) {
  box-sizing: border-box;
  max-height: calc(100vh - 24px);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@supports (height: 100dvh) {
  .fixed.inset-0 > :not(.absolute):not(.fixed) {
    max-height: calc(100dvh - 24px);
  }
}
