/*
 * لوين؟ — «ارسم خطًا» (/add) and its thank-you page (/thanks). Loaded after
 * app.css and shell.css (the 'page_styles' stack). No inline styles (CSP).
 *
 * /add is a shell page (pattern A): the map fills the stage, the form is in
 * the sheet. The sheet head holds the title, the step bar and, on step 3,
 * the three parts, a status line and back / next. collector.js puts the
 * current step on <body data-add-step>; without it (no JS yet) step 1 rules
 * apply. The step bar is the brand's motif: a line between stops, the
 * current stop yellow as in the logo.
 */

.page--add { --add-display: var(--shell-display, var(--font)); }

/* ── The map fills the stage ─────────────────────────────────── */

.page--add .shell-stage__map > .map-wrap:not(.is-fullscreen) { position: absolute; inset: 0; }
.page--add .map-wrap:not(.is-fullscreen) > .map { width: 100%; height: 100%; min-height: 0; max-height: none; border-radius: 0; }

/* The map's tools belong to step 3 (from 900px the map is shown on every step). */
body.page--add:not([data-add-step="3"]) .map-wrap .map-fab,
body.page--add:not([data-add-step="3"]) .map-wrap .gps-bar,
body.page--add:not([data-add-step="3"]) .map-wrap .map-hud,
body.page--add:not([data-add-step="3"]) .map-wrap .here-prompt { display: none !important; }

/* Map buttons ride above the sheet (--sheet-visible comes from js/sheet.js; 0 on wide screens). */
.page--add .map-wrap:not(.is-fullscreen) .map-fab:not(.map-fab--fullscreen):not(.map-fab--reverse):not(.map-fab--here) {
  bottom: calc(var(--sheet-visible, 0px) + 28px);
  transition: bottom 0.28s var(--shell-ease, ease);
}
.page--add .map-wrap:not(.is-fullscreen) .gps-bar { bottom: calc(var(--sheet-visible, 0px) + 10px); transition: bottom 0.28s var(--shell-ease, ease); }
.page--add .shell-stage.is-dragging .map-fab,
.page--add .shell-stage.is-dragging .gps-bar { transition: none; }
/* The crosshair (keyboard: Enter adds a point there) marks the middle of the part above the sheet. */
.page--add .map-wrap:not(.is-fullscreen) .map-crosshair { top: calc((100% - var(--sheet-visible, 0px)) / 2); }
/* Stops outside step 3 (wide screens show the map on every step): drawn, not movable. */
.page--add .stop-icon.is-static { cursor: default; }
/* Fullscreen covers the sheet: Leaflet's bottom controls go back to the bottom edge. */
.page--add .shell-stage .map-wrap.is-fullscreen .leaflet-bottom { bottom: env(safe-area-inset-bottom, 0px); }

/* «ضع نقطة في موقعي» on the map with the «من موقعي» method (app.css shows it in fullscreen for every method). */
body.page--add[data-add-step="3"][data-add-method="here"] .map-wrap:not(.is-fullscreen) .map-fab--here {
  display: inline-flex;
  left: 50%;
  right: auto;
  bottom: calc(var(--sheet-visible, 0px) + 84px);
  min-height: 56px;
  padding: 0 22px;
  background: var(--navy);
  color: var(--white);
  font-size: 1.0625rem;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: bottom 0.28s var(--shell-ease, ease);
}
body.page--add[data-add-step="3"][data-add-method="here"] .map-wrap:not(.is-fullscreen) .map-fab--here:disabled { opacity: 0.75; cursor: progress; }
.page--add .map-wrap:not(.is-fullscreen) .here-prompt.is-floating { bottom: calc(var(--sheet-visible, 0px) + 150px); }

/* Notices over the map, under its top controls (the status line in the sheet has the stats). */
body.page--add[data-add-step="3"] .map-wrap:not(.is-fullscreen) .map-hud {
  position: absolute;
  top: 72px;
  left: 50%;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 128px);
  transform: translateX(-50%);
  pointer-events: none;
}
.page--add .map-wrap:not(.is-fullscreen) .map-hud__stats { display: none; }

/* ── Sheet head: title, step bar, step 3 status ──────────────── */

.add-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title count" "bar bar" "phases phases" "status status";
  align-items: center;
  column-gap: 8px;
}
.add-head__top { display: contents; }
.add-head__title { grid-area: title; margin: 0; font: 800 1.5rem/1.25 var(--add-display); }
.add-head__count {
  grid-area: count;
  margin: 0;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

/* The step bar: four stops on one line; the part travelled is teal. */
.stepbar {
  grid-area: bar;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.stepbar__stop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.3;
  text-align: center;
}
/* The rail from the previous stop (on the start side) to this one. */
.stepbar__stop::before {
  content: "";
  position: absolute;
  top: 9px;
  inset-inline-start: -50%;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.stepbar__stop:first-child::before { display: none; }
.stepbar__stop.is-done::before,
.stepbar__stop.is-current::before { background: var(--teal); }
.stepbar__dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-radius: 999px;
  background: var(--white);
}
.stepbar__name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Done: teal with a check (a shape, not colour only). */
.stepbar__stop.is-done { color: var(--navy); }
.stepbar__stop.is-done .stepbar__dot { border-color: var(--teal); background: var(--teal); }
.stepbar__stop.is-done .stepbar__dot::after {
  content: "";
  width: 9px;
  height: 5px;
  margin-top: -3px;
  border: solid var(--navy);
  border-width: 0 0 2.5px 2.5px;
  transform: rotate(-45deg);
}
/* Current: the logo's yellow stop with a navy ring, and the name in bold. */
.stepbar__stop.is-current { color: var(--navy); font-weight: 700; }
.stepbar__stop.is-current .stepbar__dot {
  border: 3px solid var(--navy);
  background: var(--yellow);
  box-shadow: 0 0 0 3px var(--white), 0 0 0 5px rgba(255, 200, 87, 0.55);
}

/* Step 3: its parts (الذهاب، العودة، المواقف), a status line, back / next. */
.phases { grid-area: phases; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
.phases__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}
.phases__item.is-done { border-color: var(--teal); color: var(--navy); }
/* Decoration only (the list item already has aria-current on the current part): empty alt text. */
.phases__item.is-done::before { content: "✓"; content: "✓" / ""; color: var(--shell-teal-deep, #0B6F64); font-weight: 700; }
.phases__item.is-current { border-color: var(--navy); background: var(--navy); color: var(--white); }

.map-status { grid-area: status; display: grid; gap: 8px; margin-top: 10px; }
.map-status .route-stats { min-height: 1.5em; margin: 0; font-size: 0.9375rem; line-height: 1.5; }
.map-status .route-stats:empty { display: block; }
.map-status__nav { display: flex; gap: 8px; }
.map-status__nav .btn { min-height: 48px; padding-inline: 14px; }
.map-status__nav [data-next] { flex: 1 1 auto; }
#phase-next { transition: box-shadow 0.2s; }
#phase-next.is-attention { box-shadow: 0 0 0 5px rgba(255, 200, 87, 0.75); }

/* Phones: steps 1, 2 and 4 are a full sheet (no grip); step 3 keeps the map in view. */
@media (max-width: 899.98px) {
  body.page--add:not([data-add-step="3"]) .shell-sheet__grip { display: none; }
  body.page--add:not([data-add-step="3"]) .shell-sheet__head { padding-top: 16px; cursor: auto; }
  /* The same title size as the other sheets on phones (/map). */
  .add-head__title { font-size: 1.3125rem; }
  body.page--add[data-add-step="3"] .add-head { grid-template-areas: "phases count" "status status"; }
  /* The room at the end of the body at «half» (so a new stop's name or an error link's field can
     scroll into view) comes from shell.css for every sheet. */
  body.page--add[data-add-step="3"] .stepbar { display: none; }
  body.page--add[data-add-step="3"] .phases { margin-top: 0; }
  /* Step 3 keeps the map in view: the two titles stay for screen readers only (as .sr-only,
     but only here and at this width, so not a class in the markup). */
  body.page--add[data-add-step="3"] .add-head__title,
  body.page--add[data-add-step="3"] #step-3-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* ── Sheet body: the steps ───────────────────────────────────── */

.page--add .wizard { padding-top: 4px; }
.page--add .step { padding: 12px 0 8px; }
.step__title { font-size: 1.3125rem; }
.step__help { color: var(--muted); }
.page--add .draft-bar { margin: 12px 0 0; }
.page--add .error-summary { margin: 12px 0 0; }

.phase__title { margin: 0 0 6px; font-size: 1.0625rem; }
.return-card:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }

/* Phase 2 slots (feature flag duplicate_hints): no box while empty. */
.similar-lines:empty,
.route-overlap:empty { display: none; }
.similar-lines { margin: -8px 0 20px; }
.route-overlap { margin: 0 0 12px; }

.error-summary,
.step__errors {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 2px solid var(--danger);
  border-radius: var(--radius-input);
  background: var(--danger-50);
}
.error-summary:focus,
.step__errors:focus { outline: 3px solid var(--navy); outline-offset: 2px; }
.error-summary__title { margin: 0 0 4px; font-size: 1rem; font-weight: 700; color: var(--danger); }
.error-summary__list,
.step__errors ul { margin: 0; padding-inline-start: 1.25rem; }
.error-summary a,
.step__errors a { color: var(--danger); font-weight: 600; display: inline-block; padding: 4px 0; }

/* ── Step 2: three large choices ─────────────────────────────── */

.methods { display: grid; gap: 12px; }
.method { position: relative; display: block; }
.method input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.method__card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 14px 16px;
  border: 1px solid var(--control-edge);
  border-radius: 16px;
  background: var(--white);
  transition: border-color 0.15s, background-color 0.15s;
}
/* The radio itself, at the end of the card. */
.method__card::after {
  content: "";
  flex: none;
  width: 22px;
  height: 22px;
  margin-inline-start: auto;
  border: 2px solid var(--navy);
  border-radius: 999px;
  background: var(--white);
}
.method__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--navy);
  transition: background-color 0.15s, color 0.15s;
}
.method__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.method__title { font-size: 1.0625rem; font-weight: 700; line-height: 1.4; }
.method__help { color: var(--muted); font-size: 0.875rem; line-height: 1.5; }
.method:hover .method__card { border-color: var(--border-strong); }
.method input:checked + .method__card { border-color: var(--teal); background: var(--teal-50); box-shadow: inset 0 0 0 1px var(--teal); }
.method input:checked + .method__card .method__icon { background: var(--teal); color: var(--navy); }
.method input:checked + .method__card::after { background: radial-gradient(circle, var(--navy) 0 5px, var(--white) 6px); }
.method input:focus-visible + .method__card { outline: 3px solid var(--navy); outline-offset: 2px; }

/* ── Step 3: the method switch and its panels ────────────────── */

.method-switch {
  display: flex;
  gap: 4px;
  margin: 4px 0 14px;
  padding: 4px;
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
}
.method-switch__btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--navy);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
}
.method-switch__btn:hover { background: var(--white); }
.method-switch__btn[aria-pressed="true"] { background: var(--navy); color: var(--white); }
.method-switch__btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }

.method-panel { margin-bottom: 12px; }
.gps-intro .btn { margin: 2px 0 12px; }
.page--add .tools { margin-top: 4px; }

/* ── Thanks / share ──────────────────────────────────────────── */

.thanks { text-align: center; }
.thanks__badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 8px auto 12px;
  border-radius: 999px;
  background: var(--teal);
  color: var(--navy);
}
.thanks__badge .icon { width: 36px; height: 36px; }
.share { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); text-align: start; }
.share__title { font-size: 1.125rem; }
.share__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.share__actions .btn { flex: 1 1 10rem; }

/* ── Motion, forced colours ──────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .page--add .map-fab,
  .page--add .gps-bar,
  #phase-next { transition: none; }
}

@media (forced-colors: active) {
  .stepbar__stop.is-current .stepbar__dot,
  .phases__item.is-current,
  .method input:checked + .method__card,
  .method-switch__btn[aria-pressed="true"] { outline: 3px solid CanvasText; }
}

/* ── Inside the store app ────────────────────────────────────────
   The app's own bar already says «ارسم خطًا»: the page title stays for screen readers only, the step
   pill takes its row, and the sheet under the bar has square corners (nothing rounded to peek past). */
.shell.in-app .add-head__title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
.shell.in-app .add-head { grid-template-areas: "count count" "bar bar" "phases phases" "status status"; }
.shell.in-app .add-head__count { justify-self: start; }
.shell.in-app.page--add:not([data-add-step="3"]) .shell-sheet { border-radius: 0; }
