/*
 * Member portal styles — tokens and components from DESIGN.md.
 * Loaded per page (via @push('styles')) so pages move over to it one at a time.
 */

:root {
  --lms-primary: #0f76bb;
  --lms-primary-hover: #0c5f97;
  --lms-primary-active: #0a4d7a;
  --lms-primary-soft: #eaf4fb;
  --lms-on-primary: #ffffff;
  --lms-teal: #38bbb5;
  --lms-teal-ink: #1a6e6a;
  --lms-teal-soft: #e6f6f5;
  --lms-background: #f5f7f8;
  --lms-surface: #ffffff;
  --lms-border: #dde3e7;
  --lms-border-strong: #7f8d98;
  --lms-border-subtle: #eceff1;
  --lms-text: #1b2830;
  --lms-text-muted: #5a6872;
  --lms-placeholder: #6b7880;
  --lms-success: #1f7a4d;
  --lms-success-soft: #e3f1e8;
  --lms-warning: #8a5a00;
  --lms-warning-soft: #fdf1d8;
  --lms-danger: #b42318;
  --lms-danger-soft: #fbe9e7;
  --lms-neutral-soft: #eceff1;

  --lms-font: 'Atkinson Hyperlegible Next', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --lms-text-display: 1.75rem;
  --lms-text-heading: 1.1875rem;
  --lms-text-body: 1.0625rem;
  --lms-text-small: 0.9375rem;
  --lms-text-label: 0.9375rem;
  --lms-text-tag: 0.875rem;

  --lms-radius-sm: 6px;
  --lms-radius-md: 10px;
  --lms-radius-lg: 12px;
  --lms-radius-full: 9999px;

  --lms-space-xs: 4px;
  --lms-space-sm: 8px;
  --lms-space-md: 16px;
  --lms-space-lg: 24px;
  --lms-space-xl: 32px;

  --lms-focus-ring: 0 0 0 2px var(--lms-surface), 0 0 0 4px var(--lms-primary);
  --lms-input-ring: 0 0 0 3px rgba(15, 118, 187, .25);
}

body {
  background-color: var(--lms-background) !important;
}

/* ---------- Page ---------- */

.portal-page [hidden],
.portal-sheet [hidden],
.action-bar[hidden] {
  display: none !important;
}

.portal-page,
.portal-sheet,
.action-bar {
  font-family: var(--lms-font);
  font-size: var(--lms-text-body);
  line-height: 1.55;
  color: var(--lms-text);
}

.portal-page {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--lms-space-sm) 4px 96px;
}

.portal-title {
  /* Scales with the screen so "{Locality} – Travel and visitor records" stays on one line on phones. */
  font-size: clamp(0.9375rem, 4.4vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  margin: 0 0 var(--lms-space-xs);
}

.portal-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 var(--lms-space-lg);
  margin-bottom: var(--lms-space-md);
}

.portal-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Focus ring for every interactive element: surface gap, then primary ring. */
.portal-page :is(a, button):focus-visible,
.portal-sheet :is(a, button, .form-check-input):focus-visible,
.action-bar :is(a, button):focus-visible {
  outline: none;
  box-shadow: var(--lms-focus-ring);
}

/* ---------- Links and buttons ---------- */

.link-quiet {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--lms-primary);
  font-family: inherit;
  font-size: var(--lms-text-label);
  font-weight: 700;
  text-decoration: none;
  border-radius: var(--lms-radius-sm);
}

.link-quiet:hover {
  color: var(--lms-primary-hover);
  text-decoration: underline;
}

.btn-portal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--lms-space-sm);
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--lms-radius-sm);
  font-family: var(--lms-font);
  font-size: var(--lms-text-label);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease-out, color .15s ease-out, border-color .15s ease-out;
}

.btn-portal--primary {
  background: var(--lms-primary);
  color: var(--lms-on-primary);
}

.btn-portal--primary:hover { background: var(--lms-primary-hover); color: var(--lms-on-primary); }
.btn-portal--primary:active { background: var(--lms-primary-active); }

.btn-portal--secondary {
  background: var(--lms-surface);
  border-color: var(--lms-primary);
  color: var(--lms-primary);
}

.btn-portal--secondary:hover { background: var(--lms-primary-soft); color: var(--lms-primary-hover); }

.btn-portal--quiet {
  background: none;
  color: var(--lms-primary);
  padding: 0 12px;
}

.btn-portal--quiet:hover { color: var(--lms-primary-hover); text-decoration: underline; }

.btn-portal--danger-outline {
  background: var(--lms-surface);
  border-color: var(--lms-danger);
  color: var(--lms-danger);
  padding: 0 14px;
}

.btn-portal--danger-outline:hover { background: var(--lms-danger-soft); }

.btn-portal--danger,
.btn-portal--danger:hover {
  background: var(--lms-danger);
  border-color: var(--lms-danger);
  color: var(--lms-on-primary);
}

/* Armed delete drops its icon so "Confirm delete" fits on one line at 360px. */
.btn-portal--danger .portal-icon { display: none; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -10px -10px -10px 0;
  padding: 0;
  border: 0;
  border-radius: var(--lms-radius-sm);
  background: none;
  color: var(--lms-primary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color .15s ease-out;
}

.icon-button:hover { background: var(--lms-primary-soft); color: var(--lms-primary-hover); }

/* ---------- Banner ---------- */

.portal-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: var(--lms-space-md);
  padding: 12px 16px;
  border-radius: var(--lms-radius-md);
  background: var(--lms-primary-soft);
  color: var(--lms-text);
  font-size: var(--lms-text-small);
}

.portal-banner .portal-icon { color: var(--lms-primary-hover); }

/* ---------- Tabs ---------- */

.portal-tabs.nav-tabs {
  flex-wrap: nowrap;
  gap: var(--lms-space-sm);
  margin-bottom: var(--lms-space-md);
  overflow-x: auto;
  border-bottom: 1px solid var(--lms-border);
  font-family: var(--lms-font);
}

.portal-tabs .nav-link {
  min-height: 44px;
  padding: 0 12px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--lms-text-muted);
  font-size: var(--lms-text-label);
  font-weight: 700;
  white-space: nowrap;
}

.portal-tabs .nav-link:hover { color: var(--lms-text); border-bottom-color: var(--lms-border); }

.portal-tabs .nav-link.active,
.portal-tabs .nav-link.active:hover {
  color: var(--lms-primary);
  background: none;
  border-bottom-color: var(--lms-primary);
}

.portal-tabs .nav-link:focus-visible { outline: none; box-shadow: var(--lms-focus-ring); }

/* ---------- Sections and lists ---------- */

.portal-section + .portal-section { margin-top: 22px; }

.portal-heading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0 0 var(--lms-space-sm);
  font-size: var(--lms-text-heading);
  font-weight: 700;
  line-height: 1.25;
}

.portal-heading .portal-icon { align-self: center; color: var(--lms-text-muted); }

.portal-count {
  color: var(--lms-text-muted);
  font-size: var(--lms-text-small);
  font-weight: 400;
}

.portal-subheading {
  margin: var(--lms-space-md) 0 var(--lms-space-sm);
  font-size: var(--lms-text-label);
  font-weight: 700;
  color: var(--lms-text);
}

.portal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--lms-surface);
  border-top: 1px solid var(--lms-border);
  border-bottom: 1px solid var(--lms-border);
}

.list-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 56px;
  padding: 14px 16px;
  background: var(--lms-surface);
}

.list-row + .list-row { border-top: 1px solid var(--lms-border-subtle); }

.list-row__body { flex: 1; min-width: 0; }

.list-row__title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.list-row__meta {
  margin-top: 2px;
  font-size: var(--lms-text-small);
  line-height: 1.45;
  color: var(--lms-text-muted);
  overflow-wrap: anywhere;
}

.list-row__dates {
  margin-top: 4px;
  font-size: var(--lms-text-small);
  line-height: 1.45;
  color: var(--lms-text-muted);
}

.list-row--empty {
  align-items: center;
  flex-wrap: wrap;
  gap: 0 6px;
  color: var(--lms-text-muted);
  font-size: var(--lms-text-small);
}

.list-row--empty .link-quiet { min-height: 32px; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--lms-radius-sm);
  background: var(--lms-neutral-soft);
  color: var(--lms-text-muted);
  font-size: var(--lms-text-tag);
  font-weight: 700;
  line-height: 1.5;
}

/* A status is a word plus a shape: the sub-heading carries the word. */
.status-marker {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-top: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-marker--now { background: var(--lms-success); }

.status-marker--upcoming {
  background: var(--lms-surface);
  border: 2px solid var(--lms-border-strong);
}

/* The one authored moment: a saved row tints teal-soft, then settles. */
.row-new { animation: lms-row-new 1.6s ease-out; }

@keyframes lms-row-new {
  0% { background-color: var(--lms-teal-soft); transform: translateY(-6px); }
  15% { background-color: var(--lms-teal-soft); transform: none; }
  75% { background-color: var(--lms-teal-soft); }
  100% { background-color: var(--lms-surface); }
}

/* ---------- Sticky action bar ---------- */

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1020;
  background: var(--lms-surface);
  border-top: 1px solid var(--lms-border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

.action-bar__inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
}

.action-bar .btn-portal { width: 100%; padding: 0 12px; }

/* ---------- Bottom sheet (Bootstrap modal) ---------- */

.portal-sheet .modal-dialog {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.portal-sheet.fade .modal-dialog {
  transform: translateY(100%);
  transition: transform .2s ease-out;
}

.portal-sheet.show .modal-dialog { transform: none; }

.portal-sheet .modal-content {
  max-height: 90vh;
  border: 0;
  border-radius: var(--lms-radius-lg) var(--lms-radius-lg) 0 0;
  box-shadow: 0 -1rem 3rem rgba(0, 0, 0, .2);
}

.sheet-handle {
  display: block;
  width: 36px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: var(--lms-radius-full);
  background: var(--lms-border);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 10px 20px;
  border-bottom: 1px solid var(--lms-border);
}

.sheet-title {
  margin: 0;
  font-size: var(--lms-text-heading);
  font-weight: 700;
}

.sheet-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--lms-radius-sm);
  background: none;
  color: var(--lms-text-muted);
}

.sheet-close:hover { background: var(--lms-neutral-soft); color: var(--lms-text); }

.sheet-body {
  padding: 18px 20px 4px;
  overflow-y: auto;
}

.sheet-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--lms-border);
}

.sheet-footer__end { display: flex; gap: 8px; margin-left: auto; }

.sheet-footer .btn-portal--quiet { padding: 0 8px; }
.sheet-footer .btn-portal--primary { padding: 0 18px; }
.sheet-footer [data-delete] { padding: 0 12px; }

/* ---------- Form fields ---------- */

.field { margin-bottom: var(--lms-space-md); }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--lms-text-label);
  font-weight: 700;
}

.field-help {
  display: block;
  margin-top: 4px;
  font-size: var(--lms-text-small);
  color: var(--lms-text-muted);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.field-row--count { grid-template-columns: minmax(0, 1fr) 96px; }

.portal-sheet .form-control {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--lms-border-strong);
  border-radius: var(--lms-radius-sm);
  color: var(--lms-text);
  font-family: var(--lms-font);
  font-size: var(--lms-text-body);
}

.portal-sheet input[type="date"].form-control { font-size: var(--lms-text-small); }

.portal-sheet .form-control::placeholder { color: var(--lms-placeholder); }

.portal-sheet .form-control:focus {
  border-color: var(--lms-primary);
  box-shadow: var(--lms-input-ring);
}

.portal-sheet .form-control.is-invalid,
.portal-sheet .is-invalid + .select2-container .select2-selection {
  border-color: var(--lms-danger);
  background-image: none;
  padding-right: 12px;
}

.portal-sheet .invalid-feedback {
  display: block;
  margin-top: 4px;
  font-size: var(--lms-text-small);
  font-weight: 700;
  color: var(--lms-danger);
}

.portal-toggle.form-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-bottom: var(--lms-space-md);
  padding-left: 0;
}

.portal-toggle .form-check-input {
  width: 2.75rem;
  height: 1.5rem;
  margin: 0;
  float: none;
  flex-shrink: 0;
  border-color: var(--lms-border-strong);
  cursor: pointer;
}

.portal-toggle .form-check-input:checked {
  background-color: var(--lms-primary);
  border-color: var(--lms-primary);
}

.portal-toggle .form-check-input:focus { box-shadow: var(--lms-input-ring); border-color: var(--lms-primary); }

.portal-toggle .form-check-label { font-size: var(--lms-text-body); cursor: pointer; }

/* Select2 styled as a 48px portal input. The bootstrap-5 theme stylesheet isn't loaded. */
.portal-sheet .select2-container--bootstrap-5 .select2-selection {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--lms-border-strong);
  border-radius: var(--lms-radius-sm);
  font-size: var(--lms-text-body);
}

.portal-sheet .select2-container--bootstrap-5 .select2-selection__rendered {
  padding: 0;
  line-height: 1.5;
  color: var(--lms-text);
}

.portal-sheet .select2-container--bootstrap-5 .select2-selection__placeholder { color: var(--lms-placeholder); }

.portal-sheet .select2-container--bootstrap-5 .select2-selection__arrow {
  position: absolute;
  top: 0;
  right: 8px;
  height: 100%;
}

.portal-sheet .select2-container--bootstrap-5.select2-container--focus .select2-selection,
.portal-sheet .select2-container--bootstrap-5.select2-container--open .select2-selection {
  border-color: var(--lms-primary);
  box-shadow: var(--lms-input-ring);
}

.portal-sheet .select2-dropdown { border-color: var(--lms-border-strong); font-family: var(--lms-font); }

.portal-sheet .select2-search__field { min-height: 40px; }

.portal-sheet .select2-results__options {
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.portal-sheet .select2-results__option { padding: 10px 12px; }

.portal-sheet .select2-results__option--highlighted { background: var(--lms-primary) !important; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .portal-page *,
  .portal-sheet,
  .portal-sheet *,
  .action-bar * {
    transition: none !important;
  }

  .row-new { animation-name: lms-row-new-tint; }

  @keyframes lms-row-new-tint {
    0%, 75% { background-color: var(--lms-teal-soft); }
    100% { background-color: var(--lms-surface); }
  }
}
