/* The campus map ("Карта"): the plan of a floor is an SVG that map.js moves and zooms. Colours come from the theme of the app (the plan is tinted with
   the colour of the kind of a room), so it reads in the light and in the dark theme and with the colours of the theme of Telegram. */

html:has(.map-page) { scrollbar-gutter: stable; }
.map-page { --map-height: var(--tg-viewport-stable-height, var(--map-stable-height, 100dvh)); --map-top-inset: calc(max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, var(--map-telegram-safe-top, 0px))) + var(--tg-content-safe-area-inset-top, var(--map-telegram-content-top, 0px))); padding-top: var(--map-top-inset); overflow-anchor: none; }
.map-card[aria-busy="true"] .map-view { cursor: default; }
.map-plan-error { position: absolute; inset: 0; display: grid; align-content: center; gap: 12px; padding: 16px; }

.map-search { position: relative; margin: 10px 0 8px; }
.map-search-input { width: 100%; min-height: 48px; padding: 0 44px 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); font-size: 16px; }
.map-search-input::-webkit-search-cancel-button { display: none; }
.map-search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.map-search-clear { position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; border: 0; border-radius: 12px; background: none; color: var(--hint); font-size: 16px; cursor: pointer; }
.map-quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.map-quick .chip-btn { padding: 6px 12px; font-size: 14px; }

.map-results { margin: 0 0 10px; border-radius: 14px; background: var(--card); max-height: 46vh; overflow-y: auto; }
.map-result { display: grid; grid-template-columns: 1fr auto; gap: 1px 10px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); text-align: left; cursor: pointer; }
.map-result:last-child { border-bottom: 0; }
.map-result:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.map-result-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.map-result-meta { grid-column: 1; font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-result-where { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 13px; color: var(--hint); white-space: nowrap; }
.map-empty { padding: 12px 14px; margin: 0; }

.map-floors { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.map-floors::-webkit-scrollbar { display: none; }
.map-floors-label { flex: none; margin-right: 2px; font-size: 13px; color: var(--hint); }
.map-floor { flex: none; min-width: 42px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; }
.map-floor[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.map-card { position: relative; border-radius: 16px; overflow: hidden; background: var(--card); }
.map-view { height: clamp(300px, calc(var(--map-height) - 360px), 640px); touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; outline: none; }
.map-view.map-strip { height: clamp(230px, calc(var(--map-height) * .34), 300px); }
.map-card.map-strip .map-zoom { grid-auto-flow: column; }
.map-view:active { cursor: grabbing; }
.map-view:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.map-svg { display: block; touch-action: none; }

.map-zoom { position: absolute; right: 8px; top: 8px; display: grid; gap: 6px; }
.map-zoom-btn { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; backdrop-filter: blur(6px); }
.map-zoom-btn:active { background: color-mix(in srgb, var(--accent) 18%, var(--bg)); }
.map-fit { font-size: 18px; }

/* the plan itself: the floor of a building (its corridors) is lighter than the ground around it in both themes */
:root { --map-floor: var(--bg); }
@media (prefers-color-scheme: dark) { :root { --map-floor: color-mix(in srgb, var(--card) 90%, white); } }
.map-context { fill: none; stroke: color-mix(in srgb, var(--hint) 55%, transparent); stroke-width: 1px; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.map-wall { fill: var(--map-floor); stroke: color-mix(in srgb, var(--hint) 80%, var(--text)); stroke-width: 1.6px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.map-room { --k: var(--hint); fill: color-mix(in srgb, var(--k) 40%, var(--card)); stroke: color-mix(in srgb, var(--k) 70%, var(--text)); stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-linejoin: round; cursor: pointer; transition: opacity 160ms ease; }
.map-room.map-closed, .map-room[data-k="closed"] { fill: color-mix(in srgb, var(--hint) 22%, var(--card)); stroke: color-mix(in srgb, var(--hint) 50%, transparent); pointer-events: none; cursor: default; }
.map-room[data-k="stairs"], .map-room[data-k="lift"] { fill: color-mix(in srgb, var(--k) 55%, var(--card)); }
.map-room.sel { fill: color-mix(in srgb, var(--accent) 55%, var(--card)); stroke: var(--accent); stroke-width: 2.4px; }
.map-pulse { fill: none; stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; animation: map-pulse 1.4s ease-out infinite; }
@keyframes map-pulse { from { opacity: 1; stroke-width: 2px; } to { opacity: 0; stroke-width: 10px; } }
.map-label { fill: var(--text); font-weight: 650; pointer-events: none; paint-order: stroke; stroke: color-mix(in srgb, var(--card) 70%, transparent); stroke-width: .12em; font-family: inherit; }
.map-icon { color: var(--text); opacity: .72; pointer-events: none; }
.map-room.dim { opacity: .28; }
.map-label.dim, .map-icon.dim { opacity: .3; }

/* the colours of the kinds of rooms (the plan, the legend, the dots of the lists) */
[data-k="lecture"] { --k: #4f8fe8; }
[data-k="computer"] { --k: #2bb0d4; }
[data-k="lab"] { --k: #26b39b; }
[data-k="office"] { --k: #9b7fd1; }
[data-k="sport"] { --k: #f2a143; }
[data-k="food"] { --k: #ee7f5f; }
[data-k="wc"] { --k: #6cc060; }
[data-k="stairs"] { --k: #8590a8; }
[data-k="lift"] { --k: #6a7894; }
[data-k="service"] { --k: #b4ad9d; }
[data-k="entrance"] { --k: #e5534b; }
[data-k="cloak"] { --k: #d0a03c; }
[data-k="guard"] { --k: #c2677a; }
[data-k="other"] { --k: #a89fd0; }
[data-k="room"] { --k: #b4aedb; }
[data-k="closed"] { --k: #8f95a8; }

.map-dot { flex: none; display: inline-block; width: 11px; height: 11px; border-radius: 4px; background: var(--k, var(--hint)); }

.map-sheet { position: fixed; z-index: 8; left: max(12px, env(safe-area-inset-left), calc(50vw - 320px)); right: max(12px, env(safe-area-inset-right), calc(50vw - 320px)); bottom: max(var(--map-sheet-bottom, calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px)), calc(env(safe-area-inset-bottom) + 12px)); display: flex; flex-direction: column; max-height: var(--map-sheet-available, calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom) - 40px)); box-sizing: border-box; padding: 10px 14px 14px; border-radius: 22px 22px var(--radius) var(--radius); background: var(--bg); box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 10%, transparent), 0 -10px 30px rgb(0 0 0 / .18); animation: map-sheet-enter 220ms cubic-bezier(.16, 1, .3, 1); }
.map-sheet[hidden] { display: none; }
.map-sheet-head { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; align-items: start; gap: 4px; touch-action: pan-x; user-select: none; -webkit-user-select: none; }
.map-sheet-title { display: block; align-self: center; min-width: 0; font-size: 1.375rem; line-height: 1.2; font-weight: 750; overflow-wrap: anywhere; }
.map-sheet-icon { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 10px; background: none; color: var(--hint); cursor: pointer; }
.map-sheet-icon:active { background: var(--card); }
.map-sheet-more svg { stroke-width: 3.4; }
.map-sheet-icon:focus-visible, .map-sheet-menu button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-sheet-toggle svg { transition: transform 220ms ease-out; }
.map-sheet.expanded .map-sheet-toggle svg { transform: rotate(180deg); }
.map-sheet-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.map-sheet-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--hint); font-size: .9375rem; line-height: 1.4; overflow-wrap: anywhere; }
.map-sheet.expanded .map-sheet-name { display: block; -webkit-line-clamp: unset; overflow: visible; }
.map-sheet-unit { display: block; font-size: .875rem; line-height: 1.4; color: var(--hint); overflow-wrap: anywhere; }
.map-sheet-where { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: .8125rem; color: var(--hint); }
.map-sheet-details { display: grid; gap: 4px; margin-top: 10px; }
.map-sheet-menu { position: absolute; z-index: 2; right: 12px; width: min(230px, calc(100% - 24px)); max-height: max(88px, calc(var(--map-sheet-available, 65dvh) - 60px)); overflow-y: auto; overscroll-behavior: contain; padding: 4px; border-radius: 12px; background: var(--card); box-shadow: 0 4px 14px rgb(0 0 0 / .16); }
.map-sheet-menu[hidden], .map-sheet-details[hidden] { display: none; }
.map-sheet-menu button { position: static; display: block; width: 100%; min-height: 44px; height: auto; margin: 0; padding: 10px 12px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: .9375rem; text-align: left; overflow-wrap: anywhere; }
.map-sheet-menu button:hover { background: var(--bg); }
.map-sheet.editing > .map-sheet-close { position: absolute; right: 8px; top: 8px; }
.map-sheet.editing .map-sheet-title { padding-right: 44px; }
html.map-room-open .ai-launcher { visibility: hidden; pointer-events: none; }
@keyframes map-sheet-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .map-sheet { animation: none; } .map-sheet-toggle svg { transition: none; } }

.map-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.map-legend-item { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--text); font-size: 13px; cursor: pointer; }
.map-legend-item[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: var(--accent); }
.map-hint, .map-credit { margin: 8px 0 0; font-size: 13px; }
.map-credit a { color: var(--link); }

@media (prefers-reduced-motion: reduce) { .map-pulse { animation: none; opacity: .8; } .map-room { transition: none; } }

.map-sheet-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.map-sheet-actions .btn { min-width: 0; min-height: 44px; margin: 0; padding: 8px 10px; font-size: .875rem; line-height: 1.35; white-space: normal; }
.map-sheet-actions .btn.ghost { color: var(--accent); }
.map-sheet-note { margin-top: 4px; font-size: 13px; color: var(--hint); }

.map-route { display: grid; gap: 8px; margin: 0 0 10px; padding: 10px; border-radius: 14px; background: var(--card); }
.map-route-grid { display: grid; grid-template-columns: 1fr 44px; gap: 6px; }
.map-route-end { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 16px; text-align: left; cursor: pointer; min-width: 0; }
.map-route-end strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.map-route-end.picking { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent); }
.map-route-label { flex: none; min-width: 52px; font-size: 12px; color: var(--hint); }
.map-route-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: #2fb36b; box-shadow: 0 0 0 3px color-mix(in srgb, #2fb36b 25%, transparent); }
.map-route-dot.to { background: #e5484d; box-shadow: 0 0 0 3px color-mix(in srgb, #e5484d 25%, transparent); }
.map-route-icon { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 18px; cursor: pointer; }
.map-route-icon:disabled { opacity: .4; cursor: default; }
.map-route-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); }
.map-route-opt { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 14px; cursor: pointer; }
.map-route-opt input { width: 20px; height: 20px; accent-color: var(--accent); }
.map-route-error { margin: 0; font-size: 14px; color: var(--danger); }
.map-route-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.map-route-summary .chip { margin: 0; font-variant-numeric: tabular-nums; }
.map-route-steps summary { min-height: 32px; font-size: 14px; color: var(--link); cursor: pointer; }
.map-route-steps ol { display: grid; gap: 4px; margin: 4px 0 0; padding: 0; list-style: none; counter-reset: step; }
.map-step { counter-increment: step; display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px; background: color-mix(in srgb, var(--hint) 10%, transparent); color: var(--text); font-size: 14px; text-align: left; cursor: pointer; }
.map-step::before { content: counter(step); flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; }

.map-floor { position: relative; }
.map-floor.on-route::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--accent); }
.map-floor.on-route[aria-pressed="true"]::after { background: var(--accent-text); }

.map-next { position: absolute; left: 8px; top: 8px; max-width: calc(100% - 140px); min-height: 40px; padding: 0 14px; border: 0; border-radius: 20px; background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 650; box-shadow: 0 4px 14px rgb(0 0 0 / .25); cursor: pointer; }

.map-route-halo, .map-route-line, .map-route-flow { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.map-route-halo { stroke: color-mix(in srgb, var(--bg) 90%, transparent); stroke-width: 10px; }
.map-route-line { stroke: var(--accent); stroke-width: 6px; }
.map-route-flow { stroke: #fff; stroke-width: 2px; stroke-dasharray: 1 13; animation: map-flow 1s linear infinite; }
@keyframes map-flow { to { stroke-dashoffset: -14; } }
.map-pin .pin-ring { fill: #2fb36b; stroke: #fff; stroke-width: 3px; }
.map-pin-to .pin-ring { fill: #e5484d; }
.map-pin .pin-dot { fill: #fff; }
.map-pin-move { cursor: pointer; }
.map-pin-move .pin-bg { fill: var(--accent); stroke: #fff; stroke-width: 2px; }
.map-pin-move .pin-ic { color: var(--accent-text); }
.map-pin-move .pin-tx { fill: var(--accent-text); font-size: 13px; font-weight: 700; font-family: inherit; dominant-baseline: central; }
@media (prefers-reduced-motion: reduce) { .map-route-flow { animation: none; } }

/* ---- the whole screen ---- */
.map-expand svg { display: block; margin: auto; }
.map-top, .map-side, .map-bld, .map-collapse { display: none; }
html.map-full, html.map-full body { overflow: hidden; overscroll-behavior: none; }
body.map-full #toast { z-index: 45; bottom: calc(env(safe-area-inset-bottom) + 24px); }

/* the card of the map is fixed over the whole app (over the bar of the app and the button of Dimka too: its z-index is above theirs) */
.map-card.map-full { position: fixed; inset: 0; bottom: auto; height: var(--tg-viewport-height, var(--map-height)); z-index: 30; border-radius: 0; background: var(--bg); overscroll-behavior: none; }
.map-card.map-full .map-view, .map-card.map-full .map-view.map-strip { height: 100%; }
.map-card.map-full .map-expand { display: none; }
.map-card.map-full .map-zoom { top: 50%; right: 8px; transform: translateY(-50%); grid-auto-flow: row; }

/* the top: the way out, the building and the search in a row; the way, the chips and the results under it, one over another */
.map-card.map-full .map-top { display: flex; flex-direction: column; gap: 8px; position: absolute; left: 0; right: 0; top: 0; z-index: 3; padding: calc(var(--map-top-inset) + 8px) 8px 0; pointer-events: none; }
.map-card.map-full .map-top > * { pointer-events: auto; }
.map-card.map-full .map-topbar { display: flex; align-items: center; gap: 8px; }
.map-card.map-full .map-collapse, .map-card.map-full .map-bld { display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--bg) 92%, transparent); color: var(--text); font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 10px rgb(0 0 0 / .18); backdrop-filter: blur(6px); }
.map-card.map-full .map-bld { background: color-mix(in srgb, var(--accent) 22%, var(--bg)); }
.map-card.map-full .map-collapse svg { display: block; }
.map-card.map-full .map-topbar .map-search { flex: 1; min-width: 0; margin: 0; }
.map-card.map-full .map-search-input { box-shadow: 0 2px 10px rgb(0 0 0 / .18); }
.map-card.map-full .map-quick { display: none; margin: 0; }
.map-card.map-full .map-top:focus-within .map-quick { display: flex; } /* the words to search for show when the search is in use */
.map-card.map-full .map-results { margin: 0; max-height: 45vh; box-shadow: 0 6px 22px rgb(0 0 0 / .28); }
.map-card.map-full .map-route { margin: 0; padding: 8px; gap: 6px; max-height: 60vh; overflow-y: auto; background: color-mix(in srgb, var(--card) 96%, transparent); box-shadow: 0 6px 22px rgb(0 0 0 / .28); backdrop-filter: blur(8px); }
.map-card.map-full .map-route-grid { grid-template-columns: 1fr 1fr 40px 40px; }
.map-card.map-full .map-route-end { min-height: 40px; padding: 0 10px; gap: 6px; font-size: 14px; }
.map-card.map-full .map-route-label { display: none; }
.map-card.map-full .map-route-icon { width: 40px; height: 40px; }

/* the floors are a column at the left edge, the card of a room and the button of the way are at the bottom */
.map-card.map-full .map-side { display: flex; position: absolute; left: 8px; bottom: calc(env(safe-area-inset-bottom) + 16px); max-height: calc(100% - 230px); z-index: 2; pointer-events: none; }
.map-card.map-full .map-floors { flex-direction: column; align-items: stretch; gap: 6px; margin: 0; padding: 4px; overflow-x: hidden; overflow-y: auto; pointer-events: auto; border-radius: 14px; background: color-mix(in srgb, var(--bg) 84%, transparent); box-shadow: 0 2px 12px rgb(0 0 0 / .2); backdrop-filter: blur(6px); scrollbar-width: none; }
.map-card.map-full .map-floors::-webkit-scrollbar { display: none; }
.map-card.map-full .map-floors-label { display: none; }
.map-card.map-full .map-floor { min-width: 0; width: 42px; height: 40px; padding: 0; }
.map-card.map-full.has-sheet .map-side { bottom: calc(env(safe-area-inset-bottom) + var(--map-sheet-size, 190px) + 24px); max-height: max(44px, calc(100% - var(--map-sheet-size, 190px) - env(safe-area-inset-bottom) - 140px)); }
.map-card.map-full .map-next { top: auto; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 16px); transform: translateX(-50%); max-width: calc(100% - 150px); white-space: nowrap; }
.map-card.map-full.has-sheet .map-next { display: none; }
@media (max-height: 520px) { .map-card.map-full .map-route { max-height: 40vh; } .map-card.map-full .map-side { max-height: calc(100% - 120px); } }
@media (min-width: 720px) { .map-card.map-full .map-top { right: auto; width: min(460px, 100%); } } /* on a wide screen the search and the way are a column at the corner, not a bar over the whole plan */

/* corrections of the elder and admins: a room that does not work is dimmed and crossed out, and the form of a correction in the card */
.map-room.off { opacity: .4; }
.map-label.off { opacity: .5; text-decoration: line-through; }
.map-sheet-off { color: var(--danger, #d9534f); font-weight: 600; }
.map-edit-open { align-self: flex-start; margin-top: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.map-edit-field { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.map-edit-input { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; }
.map-edit-off { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-weight: 600; }
.map-edit-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
