/* Mobile-first styles for the counseling opportunity map. The blue system is
   intentionally quiet around the map; the connected-dot lockup is the single
   expressive gesture and can be replaced cleanly when the logo arrives. */

:root {
  --primary: #0D5A88;
  --nav: #0C5B84;
  --accent: #118ABF;
  --deep: #084864;
  --muted: #757575;
  --surface: #FFFFFF;
  --surface-soft: #FAFAFA;
  --surface-tint: #EFF8FC;
  --ink: #162A33;
  --ink-soft: var(--muted);
  --line: #DCE9EF;
  --line-strong: #B9D2DE;
  --pin-open: var(--deep);
  --pin-covered: var(--accent);
  --panel-shadow: 0 8px 24px rgba(8, 72, 100, 0.16);

  --header-height: 64px;
  --notice-height: 0px;
}

* {
  box-sizing: border-box;
}

/* The hidden attribute must always win, even over display: flex below */
[hidden] {
  display: none !important;
}

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

body {
  font-family: "Assistant", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.upload-page {
  min-height: 100vh;
  background: var(--surface-soft);
}

/* Deep blue headings create a steady visual anchor across both pages. */
h1, h2, h3 {
  color: var(--deep);
  font-weight: 700;
}

/* ---------------------------------------------------------- brand header */

.site-header {
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  padding-left: 18px;
  background: var(--nav);
  box-shadow: 0 2px 12px rgba(8, 72, 100, 0.24);
  position: relative;
  z-index: 1500; /* above the map's overlaid controls */
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--surface);
  line-height: 1;
}

.brand-copy {
  display: grid;
  gap: 4px;
}

.brand-copy strong {
  color: var(--surface);
  font-size: 17px;
  letter-spacing: 0.01em;
}

.brand-copy > span {
  color: rgba(255, 255, 255, 0.82);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Three connected points suggest a supported path through school placement. */
.brand-route {
  position: relative;
  width: 38px;
  height: 34px;
  flex: 0 0 38px;
}

.brand-route::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 16px;
  width: 27px;
  height: 2px;
  background: rgba(255, 255, 255, 0.72);
  transform: rotate(-15deg);
  transform-origin: center;
}

.brand-route > span {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--nav);
}

.brand-route > span:nth-child(1) { left: 1px; bottom: 4px; }
.brand-route > span:nth-child(2) { left: 15px; top: 11px; }
.brand-route > span:nth-child(3) { right: 0; top: 3px; }

.has-mode-notice {
  --notice-height: 76px;
}

.mode-notice {
  min-height: var(--notice-height);
  padding: 10px 16px 11px 18px;
  display: grid;
  align-content: center;
  gap: 2px;
  border-left: 5px solid var(--accent);
  background: var(--deep);
  color: var(--surface);
  position: relative;
  z-index: 1450;
}

.mode-notice strong {
  color: var(--surface);
  font-size: 14px;
}

.mode-notice span {
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  line-height: 1.25;
}

.mode-notice--unavailable {
  background: var(--primary);
}

.mode-notice--page {
  min-height: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript-note {
  padding: 16px;
  text-align: center;
}

/* ------------------------------------------------------------- map shell */

.map-shell {
  position: relative;
  /* Fill the viewport below the brand header. dvh tracks the real visible
     viewport on mobile; vh is the fallback for browsers without dvh. */
  height: calc(100vh - var(--header-height) - var(--notice-height));
  height: calc(100dvh - var(--header-height) - var(--notice-height) - env(safe-area-inset-top, 0px));
}

#map {
  height: 100%;
}

/* Legend + "Updated N min ago", bottom-left over the map (attribution is
   bottom-right). */
#map-info {
  position: absolute;
  left: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  background: rgba(239, 248, 252, 0.96);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--ink);
  box-shadow: var(--panel-shadow);
}

#map-info p {
  margin: 0 0 4px;
}

#map-info p:last-child {
  margin-bottom: 0;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(8, 72, 100, 0.32);
}

.legend-dot--open {
  background: var(--pin-open);
}

.legend-dot--covered {
  background: var(--pin-covered);
}

/* Freshness footer line stays readable over the map. */
#updated-line {
  margin-top: 6px;
  padding: 5px 8px;
  background: var(--nav);
  color: var(--surface);
  font-weight: 700;
  border-radius: 6px;
  text-align: center;
}

/* Empty state banner: only over a successful zero-opportunity response. */
#empty-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  margin: 0;
  width: min(380px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--panel-shadow);
}

#empty-banner h2 {
  margin: 0 0 8px;
  font-size: 19px;
  line-height: 1.25;
}

#empty-banner p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

#empty-case-request {
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

/* Non-blocking failed-refetch notice. */
#refresh-notice {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  min-height: 44px;
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: var(--surface);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--panel-shadow);
}

/* ------------------------------------------------------------ map actions */

#map-actions {
  position: fixed;
  top: calc(var(--header-height) + var(--notice-height) + env(safe-area-inset-top, 0px) + 10px);
  left: 50%;
  z-index: 1100;
  width: min(430px, calc(100vw - 20px));
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

#map-actions > * {
  pointer-events: auto;
}

#case-request-panel {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  --case-request-card-width: min(360px, calc(100vw - 32px));
}

#list-toggle,
#case-request-toggle {
  min-height: 44px;
  padding: 9px 14px;
  border: 2px solid var(--nav);
  border-radius: 999px;
  background: var(--surface);
  color: var(--deep);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--panel-shadow);
  white-space: nowrap;
}

#list-toggle:hover,
#case-request-toggle:hover {
  background: var(--surface-tint);
}

#case-request-toggle[aria-expanded="true"] {
  background: var(--nav);
  color: var(--surface);
}

#case-request-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle-arrow {
  font-size: 13px;
  line-height: 1;
}

#case-request-toggle[aria-expanded="true"] .toggle-arrow {
  transform: rotate(180deg);
}

#case-request-help {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  width: var(--case-request-card-width);
  margin: 0;
  padding: 10px 12px 8px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  justify-content: center;
  text-align: center;
  box-shadow: 0 6px 18px rgba(8, 72, 100, 0.12);
  transform: translateX(-50%);
}

#case-request-toggle[aria-expanded="true"] + #case-request-form,
#case-request-panel:has(#case-request-toggle[aria-expanded="true"]) #case-request-help {
  display: flex;
}

#case-request-form {
  position: absolute;
  top: calc(100% + 42px);
  left: 50%;
  width: var(--case-request-card-width);
  margin: 0;
  padding: 10px 12px 12px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line-strong);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  box-shadow: var(--panel-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100dvh - var(--header-height) - var(--notice-height) - 74px);
  overflow-y: auto;
  transform: translateX(-50%);
}

#case-request-form .field-label {
  font-size: 13px;
}

#case-request-submit {
  width: 100%;
}

.case-request-success {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  width: var(--case-request-card-width);
  margin-top: 0;
  box-shadow: var(--panel-shadow);
  text-align: center;
  transform: translateX(-50%);
}

.case-request-success .interest-success-lead {
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.35;
}

/* ------------------------------------------------------------------ pins */

/* divIcon: a 44x44 invisible tap target around a smaller visible dot */
.pin {
  display: grid;
  place-items: center;
  background: none;
  border: none;
}

.pin-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--pin-open);
  /* White stroke + halo so pins pop on the light CARTO basemap */
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(8, 72, 100, 0.38), 0 1px 4px rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.pin--covered .pin-dot {
  background: var(--surface);
  border: 4px solid var(--pin-covered);
  color: var(--deep);
}

.pin:focus-visible {
  outline: none;
}

.pin:focus-visible .pin-dot {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.pin--selected .pin-dot {
  transform: scale(1.32);
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px rgba(17, 138, 191, 0.68),
    0 0 0 7px rgba(8, 72, 100, 0.2),
    0 3px 10px rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------------ list */

/* Tinted list panel reads as a deliberate alternative to the map. */
#list-section {
  padding: calc(var(--header-height) + var(--notice-height) + 72px) 16px
    calc(24px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  background: var(--surface-tint);
}

#list-section > * {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

#list-heading {
  margin: 0 0 16px;
  font-size: 20px;
}

#list-heading:focus {
  outline: none;
}

#list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ----------------------------------------------------------------- cards */

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(8, 72, 100, 0.08);
}

.card-school {
  margin: 0 0 2px;
  font-size: 17px;
  line-height: 1.3;
  color: var(--deep);
  font-weight: 700;
}

.card-borough {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 14px;
}

/* Unmappable rows retain a clear location-status rail. */
.card:has(.tag-unmapped) {
  border-left: 4px solid var(--accent);
}

.tag-unmapped {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--deep);
  font-weight: 700;
}

.badges {
  margin: 0 0 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

/* Coverage remains a boolean status, never a person or raw source value. */
.badge--covered {
  background: var(--surface-tint);
  color: var(--deep);
  border: 1px solid var(--accent);
}

.card-details {
  margin: 0 0 12px;
}

.card-detail-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
  font-size: 14px;
  margin-bottom: 4px;
}

.card-detail-row dt {
  color: var(--muted);
}

.card-detail-row dd {
  margin: 0;
}

/* --------------------------------------------------------- interest form */

/* Primary actions use a contrast-safe dark blue with white text. */
.interest-toggle,
.interest-submit,
.back-to-map,
#load-retry {
  min-height: 44px;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: var(--surface);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.12s ease, filter 0.12s ease;
}

.interest-toggle:hover,
.interest-submit:hover,
.back-to-map:hover,
#load-retry:hover {
  filter: brightness(1.05);
}

.interest-toggle:active,
.interest-submit:active,
.back-to-map:active,
#load-retry:active {
  filter: brightness(0.94);
}

.interest-submit:disabled,
.field input:disabled,
.field select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

/* Expanded toggle acts as a clear secondary close action. */
.interest-toggle[aria-expanded="true"] {
  background: var(--surface);
  color: var(--deep);
  border: 2px solid var(--nav);
}

.interest-toggle[aria-expanded="true"]:hover {
  background: var(--surface-tint);
  filter: none;
}

.interest-form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.name-row .field {
  min-width: 0;
}

.field-label {
  font-size: 14px;
  font-weight: 600;
}

.field input,
.field select {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px; /* 16px+ prevents iOS focus zoom */
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 138, 191, 0.22);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"] {
  border-color: #9a3412;
}

@media (max-width: 340px) {
  .name-row {
    grid-template-columns: 1fr;
  }
}

/* Honeypot: offscreen but NOT display:none, so bots still fill it */
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.form-status {
  margin: 0;
  font-size: 14px;
  color: #9a3412;
  min-height: 1em;
}

.form-availability {
  margin: 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-tint);
  color: var(--deep);
  font-size: 13px;
  line-height: 1.4;
}

.form-availability:focus {
  outline: 3px solid rgba(17, 138, 191, 0.3);
  outline-offset: 2px;
}

.interest-success {
  margin-top: 12px;
  border: 1px solid var(--accent);
  background: var(--surface-tint);
  border-radius: 10px;
  padding: 12px 14px;
}

.interest-success p {
  margin: 0 0 8px;
}

.interest-success-lead {
  font-weight: 700;
  color: var(--deep);
}

.interest-success-note {
  font-size: 14px;
  color: var(--ink-soft);
}

/* ----------------------------------------------------------- bottom sheet */

#sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.4);
}

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1300;
  margin: 0 auto;
  max-width: 560px;
  max-height: 80vh;   /* fallback */
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--surface-soft);
  border-top: 4px solid var(--primary);
  border-radius: 16px 16px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 28px rgba(8, 72, 100, 0.24);
}

#sheet:focus {
  outline: none;
}

#sheet-title {
  margin: 6px 44px 12px 0;
  font-size: 18px;
}

/* Secondary close action. */
#sheet-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: 2px solid var(--nav);
  border-radius: 50%;
  background: var(--surface);
  color: var(--deep);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#sheet-close:hover {
  background: var(--surface-tint);
}

#sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ------------------------------------------------------- load-error state */

/* Opaque full-screen overlay: with nothing rendered yet the user must never
   see an empty map that reads as "no opportunities". */
#load-error {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: var(--surface-tint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

#load-error p {
  margin: 0;
  font-size: 18px;
  color: var(--deep);
  font-weight: 700;
}

/* --------------------------------------------------------------- desktop */

@media (min-width: 720px) {
  .has-mode-notice {
    --notice-height: 58px;
  }

  .mode-notice {
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 12px;
    padding-left: max(22px, calc((100vw - 1120px) / 2));
  }

  #list-section {
    padding-top: calc(var(--header-height) + var(--notice-height) + 44px);
  }

  .card {
    padding: 16px 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
