/* QR Indoor AR — дизайн-система: швейцарский минимализм + язык аэропортовой навигации.
   Тёмно-синий — основной, сигнальный жёлтый — цель и маршрут, синий — «вы здесь». */

:root {
  color-scheme: light dark;

  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-press: #E2E8F0;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #475569;
  --line: #E2E8F0;
  --map-bg: #E8EDF3;
  --map-filter: none;

  --brand: #0F172A;
  --on-brand: #FFFFFF;
  --signal: #FACC15;
  --on-signal: #0F172A;
  --you: #2563EB;
  --focus: #2563EB;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --notice-bg: #FEF9C3;
  --notice-ink: #713F12;

  --tile-flight-bg: #0F172A; --tile-flight-fg: #FACC15;
  --tile-service-bg: #2563EB; --tile-service-fg: #FFFFFF;
  --tile-food-bg: #C2410C; --tile-food-fg: #FFFFFF;
  --tile-exit-bg: #15803D; --tile-exit-fg: #FFFFFF;
  --tile-other-bg: #475569; --tile-other-fg: #FFFFFF;

  --glass: rgb(15 23 42 / 0.72);
  --shadow-1: 0 1px 2px rgb(15 23 42 / 0.08), 0 4px 12px rgb(15 23 42 / 0.08);
  --shadow-2: 0 -2px 8px rgb(15 23 42 / 0.06), 0 -12px 32px rgb(15 23 42 / 0.12);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px;
  --tap: 48px;

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --t-fast: 120ms;
  --t-med: 240ms;

  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #020617;
    --surface: #0F172A;
    --surface-2: #1E293B;
    --surface-press: #334155;
    --ink: #F8FAFC;
    --ink-2: #CBD5E1;
    --muted: #94A3B8;
    --line: #334155;
    --map-bg: #0B1220;
    --map-filter: invert(0.9) hue-rotate(180deg) saturate(0.6) brightness(0.95);
    --you: #60A5FA;
    --focus: #60A5FA;
    --danger-bg: #450A0A;
    --notice-bg: #422006;
    --notice-ink: #FDE68A;
    --tile-flight-bg: #FACC15; --tile-flight-fg: #0F172A;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.35);
    --shadow-2: 0 -12px 32px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.icon { display: block; flex-shrink: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[data-icon] { display: inline-flex; }

/* --- Плитка категории ------------------------------------------------------ */
.tile {
  --tile-bg: var(--tile-other-bg); --tile-fg: var(--tile-other-fg);
  width: 40px; height: 40px; border-radius: var(--r-sm); flex-shrink: 0;
  display: inline-grid; place-items: center; background: var(--tile-bg); color: var(--tile-fg);
}
.tile--lg { width: 52px; height: 52px; border-radius: var(--r-md); }
.tile--flight { --tile-bg: var(--tile-flight-bg); --tile-fg: var(--tile-flight-fg); }
.tile--service { --tile-bg: var(--tile-service-bg); --tile-fg: var(--tile-service-fg); }
.tile--food { --tile-bg: var(--tile-food-bg); --tile-fg: var(--tile-food-fg); }
.tile--exit { --tile-bg: var(--tile-exit-bg); --tile-fg: var(--tile-exit-fg); }
.tile--you { --tile-bg: var(--you); --tile-fg: #fff; }

/* --- Кнопки -------------------------------------------------------------------- */
.round-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1);
  transition: background-color var(--t-fast) var(--ease-out);
}
.round-btn:active { background: var(--surface-press); }
.round-btn--flat { box-shadow: none; background: var(--surface-2); }
.round-btn--glass { background: var(--glass); color: #fff; box-shadow: none; backdrop-filter: blur(12px); }
.round-btn--glass:active { background: rgb(15 23 42 / 0.9); }

.btn {
  min-height: 52px; padding: 0 var(--s-5); border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  font-weight: 650; transition: filter var(--t-fast) var(--ease-out);
}
.btn:active { filter: brightness(0.92); }
.btn--signal { background: var(--signal); color: var(--on-signal); }
.btn--light { background: #fff; color: #0F172A; }
.btn--xl { min-height: 60px; font-size: 18px; width: 100%; }
.btn--ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); padding: 0 var(--s-3); white-space: nowrap; font-size: 15px; }

/* --- Первый экран после сканирования ------------------------------------------- */
.welcome { display: none; flex-direction: column; gap: var(--s-3); padding-bottom: var(--s-1); }
.app[data-sheet="welcome"] .welcome { display: flex; }
.app[data-sheet="welcome"] .sheet__search { display: none; }
.welcome__where { display: flex; align-items: center; gap: var(--s-3); }
.welcome__title { font-size: 20px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.welcome__sub { color: var(--muted); font-size: 14px; }
.welcome__hint { margin: 0; display: flex; gap: var(--s-2); align-items: flex-start; color: var(--muted); font-size: 14px; }
.welcome__hint [data-icon] { flex-shrink: 0; margin-top: 1px; }
.welcome__actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }

/* --- Стартовая --------------------------------------------------------------- */
.index { max-width: 560px; margin: 0 auto; padding: calc(var(--s-6) + env(safe-area-inset-top)) var(--s-4) var(--s-6); }
.index__brand { display: flex; align-items: center; gap: var(--s-3); font-weight: 700; letter-spacing: -0.01em; }
.index__brand .tile { --tile-bg: var(--brand); --tile-fg: var(--signal); }
@media (prefers-color-scheme: dark) { .index__brand .tile { --tile-bg: var(--signal); --tile-fg: #0F172A; } }
.index h1 { font-size: clamp(28px, 7vw, 40px); line-height: 1.1; letter-spacing: -0.02em; margin: var(--s-6) 0 var(--s-3); font-weight: 800; text-wrap: balance; }
.index__lead { color: var(--muted); margin: 0 0 var(--s-5); }
.steps { display: grid; gap: var(--s-2); margin: 0 0 var(--s-6); padding: 0; list-style: none; counter-reset: step; }
.steps li { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-4); background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.steps li::before { counter-increment: step; content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--signal); color: var(--on-signal); font-weight: 700; font-size: 14px; flex-shrink: 0; }
.index h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 var(--s-2); font-weight: 600; }
.anchor-list { padding: 0; margin: 0; list-style: none; display: grid; gap: var(--s-2); }
.anchor-list a {
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); min-height: 64px;
  background: var(--surface); border-radius: var(--r-md); color: inherit; text-decoration: none; box-shadow: var(--shadow-1);
  transition: background-color var(--t-fast) var(--ease-out);
}
.anchor-list a:active { background: var(--surface-press); }
.anchor-list .code { font-weight: 700; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 6px; background: var(--signal); color: var(--on-signal); font-size: 14px; }
.anchor-list .meta { flex: 1; min-width: 0; }
.anchor-list .meta b { display: block; font-weight: 600; }
.anchor-list .meta span { color: var(--muted); font-size: 14px; }
.anchor-list .chev { color: var(--muted); transform: rotate(90deg); }

/* --- Экран навигации ------------------------------------------------------------ */
.app { position: fixed; inset: 0; overflow: hidden; }

.map { position: absolute; inset: 0; background: var(--map-bg); touch-action: none; }
.map svg { width: 100%; height: 100%; display: block; user-select: none; }
.map .plan-image { filter: var(--map-filter); }

.locbar {
  position: absolute; z-index: 4; left: var(--s-3); right: var(--s-3); top: calc(var(--s-3) + env(safe-area-inset-top));
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2);
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  max-width: 560px; margin: 0 auto;
}
.locbar__text { flex: 1; min-width: 0; }
.locbar__title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.locbar__sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.floor-pill { padding: 4px 10px; border-radius: 999px; background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 14px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .floor-pill { background: var(--signal); color: var(--on-signal); } }

.map-controls { position: absolute; z-index: 3; right: var(--s-3); top: calc(84px + env(safe-area-inset-top)); display: grid; gap: var(--s-2); }

.fab {
  position: absolute; z-index: 4; right: var(--s-4); bottom: calc(var(--sheet-h, 200px) + var(--s-4));
  display: flex; align-items: center; gap: var(--s-2); height: 56px; padding: 0 var(--s-5) 0 var(--s-4);
  border-radius: 999px; background: var(--brand); color: var(--on-brand); font-weight: 650; box-shadow: var(--shadow-1);
  transition: filter var(--t-fast) var(--ease-out), opacity var(--t-med) var(--ease-out);
}
.fab:active { filter: brightness(1.25); }
@media (prefers-color-scheme: dark) { .fab { background: var(--signal); color: var(--on-signal); } }
.app[data-sheet="open"] .fab, .app[data-sheet="route"] .fab, .app[data-sheet="welcome"] .fab { opacity: 0; pointer-events: none; }

/* --- Нижняя шторка ---------------------------------------------------------------- */
.sheet {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-2); padding: 0 var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  max-height: 72dvh;
}
.sheet__handle { align-self: center; width: 64px; height: 24px; position: relative; flex-shrink: 0; }
.sheet__handle::after { content: ""; position: absolute; left: 16px; right: 16px; top: 10px; height: 4px; border-radius: 2px; background: var(--line); }
.sheet__search { display: flex; flex-direction: column; gap: var(--s-3); min-height: 0; }

.search {
  display: flex; align-items: center; gap: var(--s-2); height: 52px; padding: 0 var(--s-4);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease-out);
}
.search:focus-within { border-color: var(--focus); }
.search__icon { color: var(--muted); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search input::placeholder { color: var(--muted); }

.chips { display: flex; gap: var(--s-2); overflow-x: auto; scrollbar-width: none; flex-shrink: 0; margin: 0 calc(-1 * var(--s-4)); padding: 0 var(--s-4); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 var(--s-3);
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 550; white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.results { list-style: none; margin: 0 calc(-1 * var(--s-2)); padding: 0; overflow-y: auto; min-height: 0; display: none; overscroll-behavior: contain; }
.app[data-sheet="open"] .results { display: block; }
.results button {
  width: 100%; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); min-height: 56px; text-align: left; border-radius: var(--r-md);
  transition: background-color var(--t-fast) var(--ease-out);
}
.results button:active { background: var(--surface-press); }
.results .name { flex: 1; min-width: 0; font-weight: 550; }
.results .name small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.results .floor { font-size: 13px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.results .empty { padding: var(--s-5) var(--s-2); color: var(--muted); text-align: center; }

/* --- Карточка маршрута -------------------------------------------------------------- */
.route-card { display: flex; flex-direction: column; gap: var(--s-3); }
.route-card__head { display: flex; align-items: center; gap: var(--s-3); }
.route-card__title { flex: 1; min-width: 0; }
.route-card__name { font-size: 20px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.route-card__cat { color: var(--muted); font-size: 14px; }
.route-card__stats { display: flex; gap: var(--s-2); }
.stat { flex: 1; display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3); border-radius: var(--r-md); background: var(--surface-2); color: var(--muted); }
.stat b { color: var(--ink); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.notice { display: flex; gap: var(--s-2); align-items: flex-start; padding: var(--s-3); border-radius: var(--r-md); background: var(--notice-bg); color: var(--notice-ink); font-weight: 550; font-size: 15px; }
.notice--error { background: var(--danger-bg); color: var(--danger); }
.route-card .btn { width: 100%; }

/* --- Маркеры на плане ------------------------------------------------------------------ */
.map .poi { cursor: pointer; }
.map .poi .bg { fill: var(--tile-bg); stroke: var(--surface); stroke-width: 2; }
.map .poi svg { color: var(--tile-fg); }
.map .poi .ring { fill: none; stroke: none; }
.map .poi.is-target .ring { fill: none; stroke: var(--signal); stroke-width: 4; }
.map .poi:focus-visible { outline: none; }
.map .poi:focus-visible .bg { stroke: var(--focus); stroke-width: 3; }
.map .poi--flight { --tile-bg: var(--tile-flight-bg); --tile-fg: var(--tile-flight-fg); }
.map .poi--service { --tile-bg: var(--tile-service-bg); --tile-fg: var(--tile-service-fg); }
.map .poi--food { --tile-bg: var(--tile-food-bg); --tile-fg: var(--tile-food-fg); }
.map .poi--exit { --tile-bg: var(--tile-exit-bg); --tile-fg: var(--tile-exit-fg); }
.map .poi--other { --tile-bg: var(--tile-other-bg); --tile-fg: var(--tile-other-fg); }
.map .route-casing { fill: none; stroke: var(--brand); stroke-linecap: round; stroke-linejoin: round; }
.map .route-line { fill: none; stroke: var(--signal); stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-color-scheme: dark) { .map .route-casing { stroke: #000; } }
.map .you-cone { fill: var(--you); opacity: 0.22; }
.map .you-halo { fill: var(--you); opacity: 0.25; transform-box: fill-box; transform-origin: center; animation: pulse 2.4s var(--ease-out) infinite; }
.map .you-dot { fill: var(--you); stroke: #fff; stroke-width: 3; }
@keyframes pulse { 0% { transform: scale(0.6); opacity: 0.45; } 100% { transform: scale(1.8); opacity: 0; } }

/* --- AR ------------------------------------------------------------------------------- */
.ar { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
.ar video, .ar canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ar video { object-fit: cover; }
.ar-ui { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none;
  padding: calc(var(--s-3) + env(safe-area-inset-top)) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom)); }
.ar-ui > * > * { pointer-events: auto; }
.ar-ui__top { display: flex; gap: var(--s-2); align-items: center; }
.ar-ui__bottom { display: flex; flex-direction: column; gap: var(--s-2); max-width: 560px; width: 100%; margin: 0 auto; }

.ar-status { flex: 1; display: flex; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: var(--s-2) var(--s-4);
  border-radius: var(--r-lg); background: var(--glass); backdrop-filter: blur(12px); font-size: 14px; font-weight: 550; line-height: 1.35; }
.ar-status__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: #FACC15; }
.ar[data-state="ok"] .ar-status__dot { background: #22C55E; }
.ar[data-state="gyro"] .ar-status__dot { background: #60A5FA; }
.ar[data-state="error"] .ar-status__dot { background: #EF4444; }
.ar[data-state="search"] .ar-status__dot { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.ar-reticle { position: absolute; left: 50%; top: 50%; width: min(60vw, 260px); aspect-ratio: 1; transform: translate(-50%, -50%);
  pointer-events: none; transition: opacity var(--t-med) var(--ease-out); }
.ar:not([data-state="search"]) .ar-reticle { opacity: 0; }
.ar-reticle i { position: absolute; width: 36px; height: 36px; border: 4px solid #FACC15; }
.ar-reticle i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.ar-reticle i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.ar-reticle i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.ar-reticle i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }

.ar-target { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); border-radius: var(--r-lg);
  background: var(--glass); backdrop-filter: blur(12px); }
.ar-target__text { flex: 1; min-width: 0; }
.ar-target__name { font-weight: 700; font-size: 17px; }
.ar-target__meta { font-size: 14px; color: #CBD5E1; }

/* Во время WebXR-сессии фон страницы прозрачный, видео не нужно */
.ar.is-xr { background: transparent; }
/* В WebXR страница на весь экран под системной строкой состояния, а Android при этом
   отдаёт safe-area-inset = 0 — отступаем на высоту строки (48 px) и полоски жестов сами */
.ar.is-xr .ar-ui {
  padding-top: calc(var(--s-2) + max(env(safe-area-inset-top), 48px));
  padding-bottom: calc(var(--s-3) + max(env(safe-area-inset-bottom), 24px));
}
.ar.is-xr video, .ar.is-xr canvas { display: none; }

/* --- Широкие экраны: шторка становится боковой панелью --------------------------------- */
@media (min-width: 900px) {
  .sheet { left: var(--s-4); right: auto; bottom: var(--s-4); top: calc(92px + env(safe-area-inset-top)); width: 400px; max-height: none;
    border-radius: var(--r-xl); padding-top: var(--s-4); }
  .sheet__handle { display: none; }
  .results { display: block; }
  .locbar { left: var(--s-4); right: auto; width: 400px; margin: 0; }
  .fab { bottom: var(--s-5); right: var(--s-5); }
  .app[data-sheet="open"] .fab { opacity: 1; pointer-events: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
