/* App surfaces share the map's system typography and colour tokens. */
/* Launcher height + offset + gap; bottom-left map controls clear this much space. */
:root { --app-launcher-clearance: 84px; }
.app-launcher {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 1400;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 14px 6px 7px;
  border: 1px solid var(--color-panel-border);
  border-radius: 24px;
  background: var(--color-surface);
  color: var(--color-label);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  font: 600 14px/1.3 system-ui, sans-serif;
  cursor: pointer;
}
.app-launcher img { border-radius: 50%; }
.app-launcher.is-offline::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #be741c; }
.app-sheet {
  padding: 0;
  border: 1px solid var(--color-panel-border);
  border-radius: 28px;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  background: var(--color-bg, #f8fafc);
  color: var(--color-label);
  box-shadow: 0 24px 100px #0006;
  overflow: hidden;
  overscroll-behavior: contain;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-user-select: text;
  user-select: text;
}
.app-sheet::backdrop { background: #09121d70; backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.app-sheet[open] { animation: app-appear 180ms ease-out; }
.app-sheet-body { max-height: inherit; overflow-y: auto; overscroll-behavior: contain; }
.app-loading-mark { display: block; margin: 0 auto 16px; border-radius: 16px; }
.app-close {
  z-index: 2;
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #ffffff30;
  background: #182631c9;
  color: white;
  cursor: pointer;
}
.app-art { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; background: #30404a; }
.app-sheet-content { padding: 24px; }
.app-eyebrow { color: var(--color-label-secondary); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.app-sheet h1 { font-size: clamp(23px, 6vw, 29px); line-height: 1.25; letter-spacing: -.025em; margin: 10px 0; }
.app-sheet h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.app-sheet p { font-size: 13px; line-height: 1.7; color: var(--color-label-secondary); }
.app-sheet .app-intro { font-size: 14px; margin: 0 0 18px; }
.app-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.app-badges span { font-size: 11px; padding: 5px 9px; border: 1px solid var(--color-separator); border-radius: 20px; }
.app-badges .is-offline { color: var(--color-danger); }
.app-sheet button { font-family: inherit; font-size: 14px; touch-action: manipulation; }
.app-primary { display: block; width: 100%; min-height: 48px; padding: 12px 16px; border: 0; border-radius: 14px; background: #176f69; color: white; font-weight: 650; cursor: pointer; }
.app-card { padding: 18px; margin-top: 20px; border: 1px solid var(--color-separator); border-radius: 18px; background: var(--color-surface); }
.app-card strong { font-size: 13px; }
.app-card p:last-of-type { margin-bottom: 8px; }
.app-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.app-actions button { padding: 10px; min-height: 48px; border: 1px solid var(--color-separator); border-radius: 14px; color: var(--color-label); background: var(--color-surface); cursor: pointer; }
.app-text-button { min-height: 44px; padding: 8px 0; border: 0; background: transparent; color: var(--color-accent); cursor: pointer; }
.app-sheet .app-version { text-align: center; font-size: 11px; margin: 20px 0 0; }
.app-sheet button:active, .app-launcher:active { transform: scale(.97); }
.app-sheet button:disabled { opacity: .55; cursor: wait; }
.app-sheet :focus-visible, .app-launcher:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 3px; }
.app-feedback, .app-offline { position: fixed; z-index: 10000; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); padding: 10px 16px; box-sizing: border-box; border: 1px solid #ffffff30; border-radius: 14px; background: #263842f2; color: white; font: 13px/1.5 system-ui, sans-serif; text-align: center; pointer-events: none; }
.app-feedback { bottom: calc(86px + env(safe-area-inset-bottom)); }
.app-offline { top: calc(65px + env(safe-area-inset-top)); font-size: 11px; }
/* A modal's top layer also contains its own status feedback. */
.app-sheet .app-feedback { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); }
[hidden].app-primary, [hidden].app-update, [hidden].app-offline, [hidden].app-feedback { display: none; }
@keyframes app-appear { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@media (max-width: 768px) {
  .app-sheet { margin: auto 0 0; width: 100%; max-width: none; max-height: calc(100dvh - env(safe-area-inset-top) - 12px); border-radius: 28px 28px 0 0; border-bottom: 0; }
  .app-sheet-content { padding: 22px max(22px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left)); }
  .app-art { max-height: 210px; object-position: center 55%; }
  .control-panel { top: calc(8px + env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .toggle-panel.toggle-panel-mobile { top: calc(10px + env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); min-width: 44px; min-height: 44px; }
  .leaflet-top { top: env(safe-area-inset-top); }
  .leaflet-right { right: env(safe-area-inset-right); }
  .leaflet-bottom { bottom: env(safe-area-inset-bottom); }
  /* Leaflet.draw sits at bottomleft on mobile, exactly where the launcher is. */
  .leaflet-bottom.leaflet-left .leaflet-control { margin-bottom: var(--app-launcher-clearance, 84px); }
  .leaflet-control-zoom a { min-width: 44px; min-height: 44px; display: grid !important; place-items: center; }
  input, textarea, select { font-size: max(16px, 1rem); }
}
@media (prefers-color-scheme: dark) { .app-sheet { background: #17232d; } }
@media (prefers-reduced-motion: reduce) { .app-sheet[open] { animation: none; } .app-sheet button:active, .app-launcher:active { transform: none; } }
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .app-launcher, .app-card, .app-actions button { background: var(--color-surface-solid); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .app-sheet::backdrop { backdrop-filter: none; -webkit-backdrop-filter: none; background: #09121dcc; }
}
