/* /start: the visa application as one chat (src/components/StartPage.astro).
   Mobile first: the page is the chat. From 641px it sits in the home page's
   bordered sheet, with the chat as a centred column. */

:root {
  --s-ink: #111;
  --s-muted: #71717a;
  --s-line: #e4e4e7;
  --s-sheet: #fbfbfa;
  --s-column: 640px;
  --s-height: 100dvh;
}

/* Everything is scoped to the app: the home page carries it too
   (StartOverlay.astro). Its own page marks <html class="s-document"> */
.s-page,
.s-page *,
.s-page *::before,
.s-page *::after {
  box-sizing: border-box;
}

.s-page [hidden] {
  display: none !important;
}

html.s-document,
html.s-document body {
  height: 100%;
}

html.s-document body {
  margin: 0;
  background: #fff;
  overflow: hidden;
}

:where(.s-page) button,
:where(.s-page) input {
  font: inherit;
  color: inherit;
}

:where(.s-page) button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:where(.s-page) :is(h1, h2, h3, p, ul) {
  letter-spacing: normal;
}

/* ---------- The sheet ---------- */

.s-page {
  position: relative;
  color: var(--s-ink);
  font-family: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  text-align: left;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  height: var(--s-height);
  background: var(--s-sheet);
  overflow: hidden;
  isolation: isolate;
}

/* How far the application has got: a hairline along the top */
.s-progress {
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  z-index: 3;
}

.s-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--s-ink);
  transition: width 0.5s ease;
}

/* A landmark engraving, faint and grey behind the chat, fading out on every
   side; the two layers cross-fade when the country is picked */
.s-art {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* Not in the page now (commented out in StartApp.astro): the home page's
   visa stamps, drifting, until a country with a landmark is picked */
.s-stamps {
  position: absolute;
  inset: 0;
  background: url('/images/visa-stamps-bg.webp') center / 300px repeat;
  filter: grayscale(100%);
  opacity: 0.07;
  animation: s-drift 80s linear infinite;
  transition: opacity 0.9s ease;
}

.s-page.has-art .s-stamps {
  opacity: 0;
}

@keyframes s-drift {
  from {
    background-position: 0 0;
  }

  to {
    background-position: -300px 0;
  }
}

.s-art-layer {
  position: absolute;
  inset: 0;
  background: var(--s-art) center 62% / min(170%, 760px) auto no-repeat;
  mix-blend-mode: multiply;
  opacity: 0;
  /* Slow, and the same both ways: one landmark leaves as the next arrives */
  transition: opacity 2.4s ease-in-out;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 20%, #000 80%, transparent), linear-gradient(to bottom, transparent 8%, #000 30%, #000 78%, transparent 96%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent, #000 20%, #000 80%, transparent), linear-gradient(to bottom, transparent 8%, #000 30%, #000 78%, transparent 96%);
  mask-composite: intersect;
}

.s-art-layer.is-on {
  opacity: 0.15;
}

/* ---------- Top bar ---------- */

.s-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  flex: none;
}

.s-brand {
  display: inline-flex;
  font-size: 1rem;
  align-items: center;
  gap: 6px;
  color: var(--s-ink);
  text-decoration: none;
  font-weight: 600;
}

.s-brand img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.s-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Where the application stands: the country's flag, its name and how far
   along; opens what is saved */
.s-status-wrap {
  position: relative;
}

.s-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 8px 0 9px;
  border: 1px solid rgba(17, 17, 17, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.78rem;
  font-weight: 600;
}

.s-status-flag {
  width: 18px;
  height: 13px;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.08);
}

.s-status-percent {
  color: var(--s-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.s-status-chevron {
  color: var(--s-muted);
  transition: transform 0.15s ease;
}

.s-status[aria-expanded='true'] .s-status-chevron {
  transform: rotate(180deg);
}

.s-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  width: min(280px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--s-line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 36px rgba(17, 17, 17, 0.12);
  animation: s-in 0.18s ease both;
}

.s-menu p {
  margin: 0;
}

.s-menu-title {
  font-weight: 700;
}

.s-menu-line {
  color: var(--s-muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.s-menu-bar {
  height: 4px;
  margin: 12px 0 8px;
  border-radius: 999px;
  background: #f0f0f1;
  overflow: hidden;
}

.s-menu-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--s-ink);
  transition: width 0.5s ease;
}

.s-menu-saved {
  color: var(--s-muted);
  font-size: 0.78rem;
}

.s-restart {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  padding: 10px 0 0;
  border: 0;
  border-top: 1px solid #f0f0f1;
  background: none;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
}

.s-restart:hover {
  color: #000;
}

.s-restart.is-armed {
  color: #c2410c;
}

@media (max-width: 480px) {
  .s-status.has-flag .s-status-label {
    display: none;
  }
}

/* The line icons (lucide), drawn from the sprite */
.s-sprite {
  position: absolute;
}

.s-page svg:has(> use) {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.s-lang {
  /* Hidden for now: the switch stays in the page */
  display: none;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid rgba(17, 17, 17, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

.s-lang-option {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(17, 17, 17, 0.55);
}

.s-lang-option.is-active {
  background: var(--s-ink);
  color: #fff;
}

/* ---------- The chat ---------- */

.s-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Messages fade out under the top bar */
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28px);
  mask-image: linear-gradient(to bottom, transparent, #000 28px);
}

.s-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: var(--s-column);
  min-height: 100%;
  margin: 0 auto;
  padding: 28px 16px 16px;
  /* A short chat sits at the bottom, right above the text box */
  justify-content: flex-end;
}

.s-msg {
  display: flex;
  animation: s-in 0.28s ease both;
}

.s-msg.is-still {
  animation: none;
}

.s-msg--user {
  justify-content: flex-end;
  /* A little more air around the visitor's own answers */
  margin: 4px 0;
}

.s-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.s-msg--bot .s-bubble {
  border-radius: 18px 18px 18px 4px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--s-line);
}

.s-msg--user .s-bubble {
  border-radius: 18px 18px 4px 18px;
  background: var(--s-ink);
  color: #fff;
}

/* An answer still being given, part by part */
.s-msg--draft .s-bubble {
  opacity: 0.6;
}

.s-bubble b {
  font-weight: 600;
}

.s-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.s-bubble ul {
  margin: 0;
  padding-left: 1.15em;
}

.s-bubble li + li {
  margin-top: 4px;
}

/* A file sent in the chat */
.s-file {
  display: flex;
  align-items: center;
  gap: 10px;
}

.s-file svg {
  flex: none;
  opacity: 0.8;
}

.s-file-name {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.s-file-meta {
  display: block;
  font-size: 0.78rem;
  opacity: 0.7;
}

/* A quiet line across the chat: what the page itself says */
.s-msg--note {
  justify-content: center;
  padding: 2px 0;
  color: var(--s-muted);
  font-size: 0.78rem;
  text-align: center;
}

/* The bot is writing */
.s-typing {
  display: inline-flex;
  gap: 4px;
  padding: 14px;
}

.s-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a1a1aa;
  animation: s-typing 1.2s ease-in-out infinite;
}

.s-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.s-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

/* The answers to tap, right under the question and as wide as its bubble
   may be. Short ones sit side by side (showChoices in src/start/app.js) */
.s-choices {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: 86%;
  margin-top: 2px;
  animation: s-in 0.28s ease both;
}

.s-choices--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.s-choices--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.s-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 9px 14px;
  border: 1px solid var(--s-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 0.93rem;
  font-weight: 500;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.s-chip-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.s-chip-icon {
  display: grid;
  flex: none;
  color: #52525b;
}

.s-chip-flag {
  flex: none;
  width: 22px;
  height: 16px;
  border-radius: 3px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.08);
}

/* A number alone: centred */
.s-choices--three .s-chip {
  justify-content: center;
}

.s-chip:hover {
  border-color: var(--s-ink);
}

.s-chip:active {
  transform: scale(0.985);
}

.s-chip.is-picked {
  border-color: var(--s-ink);
  background: var(--s-ink);
  color: #fff;
}

.s-chip.is-picked .s-chip-icon {
  color: inherit;
}

.s-chip--primary {
  grid-column: 1 / -1;
  justify-content: center;
  border-color: var(--s-ink);
  background: var(--s-ink);
  color: #fff;
  font-weight: 600;
}

/* The steps of the hand-over, ticking off one by one */
.s-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.s-steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--s-muted);
  transition: color 0.3s ease;
}

.s-steps li::before {
  content: '';
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--s-line);
  border-radius: 50%;
}

.s-steps li.is-running::before {
  border-top-color: var(--s-ink);
  animation: s-spin 0.7s linear infinite;
}

.s-steps li.is-done {
  color: var(--s-ink);
}

.s-steps li.is-done::before {
  border-color: var(--s-ink);
  background: var(--s-ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / 10px no-repeat;
}

/* ---------- The summary ---------- */

.s-msg--wide .s-bubble {
  width: 100%;
  max-width: 100%;
  padding: 14px;
}

.s-summary h3 {
  margin: 16px 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--s-muted);
}

.s-summary h2 {
  margin: 20px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.s-summary p {
  margin: 0;
}

.s-summary p + p {
  margin-top: 10px;
}

.s-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) 16px;
  align-items: start;
  gap: 10px;
  width: 100%;
  padding: 9px 0;
  border: 0;
  border-top: 1px solid #f0f0f1;
  background: none;
  font-size: 0.9rem;
  text-align: left;
}

.s-row-label {
  color: var(--s-muted);
}

.s-row-value {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.s-row svg {
  margin-top: 3px;
  color: #c4c4c8;
  transition: color 0.15s ease;
}

button.s-row:hover svg {
  color: var(--s-ink);
}

div.s-row {
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
}

/* An earlier summary: kept as it was, no longer to change */
.s-msg--stale .s-row {
  pointer-events: none;
}

.s-msg--stale .s-row svg {
  visibility: hidden;
}

/* ---------- The text box ---------- */

.s-dock {
  flex: none;
  width: 100%;
  max-width: var(--s-column);
  margin: 0 auto;
  padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
}

.s-box {
  border: 1px solid var(--s-line);
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 6px 24px rgba(17, 17, 17, 0.06);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.s-box:focus-within {
  border-color: #a1a1aa;
  box-shadow: 0 6px 28px rgba(17, 17, 17, 0.1);
}

.s-box.is-shaking {
  animation: s-shake 0.3s ease;
}

.s-box.is-over {
  border-color: var(--s-ink);
  border-style: dashed;
}

/* Which part of a longer answer is being asked for */
.s-caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 18px 0;
  font-size: 0.78rem;
  font-weight: 600;
}

.s-caption-count {
  flex: none;
  color: var(--s-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.s-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 18px;
}

.s-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  outline: 0;
  background: none;
  /* 16px: iOS zooms the page into anything smaller */
  font-size: 16px;
}

.s-input::placeholder {
  color: #a1a1aa;
}

.s-box--code .s-input {
  font-weight: 600;
  letter-spacing: 0.3em;
  font-variant-numeric: tabular-nums;
}

.s-box--code .s-input::placeholder {
  font-weight: 400;
  letter-spacing: 0;
}

.s-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--s-ink);
  color: #fff;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.s-send:active {
  transform: scale(0.94);
}

.s-box.is-empty .s-send {
  opacity: 0.25;
}

/* A document is asked for: the box takes a file instead of words */
.s-attach {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-height: 40px;
  color: var(--s-muted);
  font-size: 0.93rem;
  cursor: pointer;
}

.s-attach b {
  color: var(--s-ink);
  font-weight: 600;
}

.s-box--file .s-input,
.s-box--file .s-send {
  display: none;
}

.s-box--file .s-field {
  padding: 6px 18px;
}

.s-under {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
  min-height: 30px;
  padding-top: 6px;
}

.s-under button {
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--s-muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.s-under button:hover {
  color: var(--s-ink);
}

.s-error {
  margin: 0 0 6px;
  padding: 0 18px;
  color: #c2410c;
  font-size: 0.82rem;
  font-weight: 500;
}

.s-legal {
  display: none;
  margin: 8px 0 0;
  color: var(--s-muted);
  font-size: 0.75rem;
  text-align: center;
}

.s-legal a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.s-page.is-done .s-box,
.s-page.is-quiet .s-box,
.s-page.is-quiet .s-under {
  display: none;
}

/* ---------- Before the first answer ---------- */

.s-hero {
  display: none;
  width: 100%;
  max-width: var(--s-column);
  margin: 0 auto;
  padding: 0 24px 22px;
  text-align: center;
}

.s-hero h1 {
  margin: 0;
  font-size: clamp(1.6rem, 6.4vw, 2.3rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  text-wrap: balance;
}

.s-hero p {
  margin: 12px 0 0;
  color: var(--s-muted);
  font-size: 1.02rem;
  text-wrap: balance;
}

/* The greeting and the text box sit together in the middle of the sheet */
.s-page.is-hero {
  justify-content: center;
}

.s-page.is-hero .s-top {
  position: absolute;
  inset: 0 0 auto;
}

.s-page.is-hero .s-scroll,
.s-page.is-hero .s-under {
  display: none;
}

.s-page.is-hero .s-hero {
  display: block;
  animation: s-in 0.5s ease both;
}

.s-page.is-hero .s-legal {
  display: block;
}

.s-page.is-hero .s-dock {
  /* A little above the true middle reads as centred */
  margin-bottom: 9vh;
  animation: s-in 0.5s 0.08s ease both;
}

@keyframes s-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes s-typing {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes s-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes s-shake {
  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

/* ---------- Wider screens: the home page's sheet ---------- */

@media (min-width: 641px) {
  .s-page {
    height: calc(var(--s-height) - 20px);
    margin: 10px;
    border: 1px solid #e8eaed;
    border-radius: 10px;
  }

  .s-top {
    padding: 18px 22px 10px;
  }

  .s-art-layer {
    background-size: auto min(78%, 620px);
    background-position: center 58%;
  }

  /* The greeting's second line stays one line: wider than the chat column */
  .s-hero {
    max-width: 860px;
  }

  .s-bubble {
    max-width: 78%;
  }

  .s-choices {
    width: 78%;
  }

  .s-choices--two-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .s-dock {
    padding-bottom: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .s-msg,
  .s-choices,
  .s-page.is-hero .s-hero,
  .s-page.is-hero .s-dock {
    animation: none;
  }

  .s-progress span,
  .s-art-layer,
  .s-stamps {
    transition: none;
  }

  .s-stamps {
    animation: none;
  }
}

/* ---------- On the home page: the app opens over the hero ---------- */

.s-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #fff;
}

html.start-open .s-overlay {
  display: block;
  animation: s-fade 0.28s ease both;
}

html.start-open,
html.start-open body {
  overflow: hidden;
}

@keyframes s-fade {
  from {
    opacity: 0;
  }
}
