/* AYANA Navigator — mobile-first map UI */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { color: #f8fafc; background: #0f172a; }

#map { position: fixed; inset: 0; }

/* Top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(15,23,42,.85), rgba(15,23,42,0));
  pointer-events: none;
  z-index: 5;
}
.topbar .title { font-weight: 600; font-size: 14px; letter-spacing: .02em; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.topbar .status { display: flex; gap: 6px; pointer-events: auto; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 11px; font-weight: 600; letter-spacing: .04em; background: rgba(15,23,42,.7); border: 1px solid rgba(255,255,255,.1); }
.pill.online { background: rgba(34,197,94,.2); border-color: rgba(34,197,94,.5); color: #86efac; }
.pill.offline { background: rgba(245,158,11,.2); border-color: rgba(245,158,11,.5); color: #fcd34d; }
.pill.rec { background: rgba(239,68,68,.25); border-color: rgba(239,68,68,.7); color: #fecaca; animation: blink 1.2s ease-in-out infinite; }

@keyframes blink { 0%,60%,100%{opacity:1} 30%{opacity:.5} }

/* FAB stack */
.fab-stack {
  position: fixed; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  display: flex; flex-direction: column; gap: 10px;
  z-index: 5;
}
.fab {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(15,23,42,.92);
  color: #f1f5f9;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.fab:active { transform: scale(.95); }
.fab:hover { background: rgba(30,41,59,.95); }
.fab-rec { background: #ef4444; border-color: #fca5a5; color: #fff; }
.fab-rec:hover { background: #dc2626; }
.fab-rec.recording { background: #dc2626; }
.fab-rec.recording::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid #ef4444; animation: ring 1.6s ease-out infinite;
}
@keyframes ring { 0%{transform:scale(.9);opacity:.8} 100%{transform:scale(1.4);opacity:0} }
.fab-rec { position: relative; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: #fff; display: inline-block; }
.fab-rec.recording .rec-dot { width: 12px; height: 12px; border-radius: 3px; }

/* Recording panel */
.rec-panel {
  position: fixed;
  left: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: rgba(15,23,42,.95);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  padding: 12px 14px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-variant-numeric: tabular-nums;
  z-index: 5;
}
.rec-row { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: 13px; }
.rec-row span:first-child { color: #94a3b8; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.rec-row span:last-child { font-weight: 600; }
.rec-actions { margin-top: 8px; }
.btn { width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid transparent; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* Layers drawer */
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(360px, 92vw);
  background: #0f172a;
  border-left: 1px solid rgba(255,255,255,.1);
  z-index: 10;
  transform: translateX(0);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.hidden { transform: translateX(101%); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-body { padding: 8px 14px 24px; overflow-y: auto; flex: 1; }
.iconbtn { background: transparent; border: 0; color: #cbd5e1; font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.iconbtn:hover { background: rgba(255,255,255,.06); }

.group { margin-top: 14px; }
.group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #94a3b8; margin-bottom: 6px; padding: 0 4px; }
.layer-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-radius: 8px;
  cursor: pointer;
}
.layer-row:hover { background: rgba(255,255,255,.04); }
.layer-row input { accent-color: #60a5fa; width: 16px; height: 16px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.3); flex-shrink: 0; }
.swatch.line { height: 4px; border-radius: 2px; }
.swatch.point { border-radius: 50%; }
.layer-label { font-size: 14px; flex: 1; }
.layer-count { font-size: 11px; color: #94a3b8; }
.hint { font-size: 11px; color: #94a3b8; padding: 6px 8px; }
.hint a { color: #93c5fd; }

.hidden { display: none !important; }

/* Popup */
.maplibregl-popup-content {
  background: #0f172a; color: #f1f5f9;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; padding: 10px 12px;
  font-size: 12px; max-width: 260px;
}
.maplibregl-popup-tip { border-top-color: #0f172a !important; border-bottom-color: #0f172a !important; }
.maplibregl-popup-close-button { color: #cbd5e1; font-size: 18px; }
.popup-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.popup-props { color: #cbd5e1; line-height: 1.4; }
.popup-props .k { color: #94a3b8; margin-right: 4px; }

/* MapLibre controls dark theme */
.maplibregl-ctrl-group { background: rgba(15,23,42,.92) !important; border: 1px solid rgba(255,255,255,.1); }
.maplibregl-ctrl-group button { background: transparent !important; }
.maplibregl-ctrl-group button:hover { background: rgba(255,255,255,.06) !important; }
.maplibregl-ctrl-icon { filter: invert(.9); }

/* Pin & note FABs */
.fab-pin { background: #fbbf24; color: #1f2937; border-color: rgba(0,0,0,.1); }
.fab-pin:hover { background: #f59e0b; }
.fab-note { background: #38bdf8; color: #082f49; border-color: rgba(0,0,0,.1); }
.fab-note:hover { background: #0ea5e9; }
.fab[disabled] { opacity: .55; cursor: progress; }
.fab.flashing { animation: flash 0.45s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(250,204,21,.7), 0 6px 16px rgba(0,0,0,.4); }
  100% { box-shadow: 0 0 0 18px rgba(250,204,21,0), 0 6px 16px rgba(0,0,0,.4); }
}

/* Note modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  padding: env(safe-area-inset-top) 0 0;
}
.modal-sheet {
  width: 100%; max-width: 480px;
  background: #0f172a;
  border-radius: 16px 16px 0 0;
  border: 1px solid rgba(255,255,255,.08);
  border-bottom: 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  max-height: 90vh;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 16px; }
  .modal-sheet { border-radius: 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.modal-actions { padding: 12px 16px 16px; display: flex; gap: 8px; }
.note-coords {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px; color: #94a3b8;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.note-coords.ready { color: #86efac; }
.note-coords.error { color: #fca5a5; }
.note-label {
  display: block;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: #94a3b8; margin: 10px 4px 4px;
}
.modal-body textarea,
.modal-body input[type="text"] {
  width: 100%;
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.modal-body textarea:focus,
.modal-body input[type="text"]:focus {
  outline: 2px solid #60a5fa; outline-offset: 1px; border-color: transparent;
}
.btn-primary { background: #60a5fa; color: #0f172a; }
.btn-primary:hover { background: #3b82f6; color: #fff; }
.btn-primary:disabled { background: #334155; color: #64748b; cursor: not-allowed; }

/* Toast */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 48px);
  background: rgba(15,23,42,.95);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #f1f5f9;
  z-index: 30;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
  animation: toastIn .2s ease-out;
}
.toast.success { border-color: rgba(34,197,94,.5); }
.toast.error { border-color: rgba(239,68,68,.5); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translateX(-50%); } }

/* Waypoint popup */
.popup-note {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,.1);
  color: #f1f5f9;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
}
.popup-actions { margin-top: 8px; display: flex; gap: 6px; }
.popup-actions button {
  background: transparent; color: #fca5a5;
  border: 1px solid rgba(252,165,165,.4);
  border-radius: 6px; padding: 4px 8px;
  font-size: 11px; font-weight: 600; cursor: pointer;
}
.popup-actions button:hover { background: rgba(239,68,68,.15); }
.popup-actions .btn-edit { color: #93c5fd; border-color: rgba(147,197,253,.4); }
.popup-actions .btn-edit:hover { background: rgba(59,130,246,.15); }

/* User UI */
.user-pill { pointer-events: auto; cursor: pointer; background: rgba(96,165,250,.2); border-color: rgba(96,165,250,.4); color: #bfdbfe; }
.user-pill:hover { background: rgba(96,165,250,.3); }
.user-pill.user-set { background: rgba(34,197,94,.2); border-color: rgba(34,197,94,.5); color: #86efac; }
.user-pill::before { content: "👤 "; }

.user-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 8px; border-radius: 8px;
  background: rgba(255,255,255,.03);
  margin-bottom: 4px;
}
.user-info { display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.user-info .muted { color: #94a3b8; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.user-info strong { color: #f1f5f9; font-weight: 600; }
.btn-secondary {
  width: auto; padding: 6px 12px; font-size: 12px;
  background: rgba(255,255,255,.06); color: #f1f5f9;
  border: 1px solid rgba(255,255,255,.12);
}
.btn-secondary:hover { background: rgba(255,255,255,.12); }

/* Sign-in modal extras */
.muted { color: #94a3b8; }
.muted.small { font-size: 12px; line-height: 1.5; margin: 0 0 12px; }
.muted-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; margin: 0 4px 6px; }
.muted-label.or-new { text-align: center; text-transform: none; letter-spacing: 0; margin: 14px 0 6px; font-weight: 400; color: #64748b; }
.user-recent { margin-bottom: 12px; }
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-list button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.1);
  color: #f1f5f9;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.user-list button:hover { background: rgba(255,255,255,.08); border-color: rgba(96,165,250,.4); }
.user-list button .muted { font-size: 11px; }

/* Install toast */
.install-toast {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  background: rgba(15,23,42,.95);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  z-index: 6;
}
