html { touch-action: manipulation; -ms-touch-action: manipulation; }
:root {
  --primary: #0047AB;
  --primary-light: #3373C4;
  --primary-dark: #003380;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface-secondary: #E8EDF2;
  --card-bg: #FFFFFF;
  --border: #D1D9E6;
  --text: #1A1A2E;
  --text-secondary: #6B7B8D;
  --accent: #4A90D9;
  --danger: #DC3545;
  --success: #28A745;
  --warning: #E67E22;
  --white: #FFFFFF;
  --overlay: rgba(0,0,0,0.5);
  --input-bg: #F0F4F8;
  --sidebar-w: 380px;
  --tab-h: 56px;
  --radius-card: 14px;
  --radius-chip: 16px;
  --radius-input: 10px;
  --shadow-card: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-elevated: 0 8px 32px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; height: 100vh; width: 100vw; -webkit-font-smoothing: antialiased; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

#app { display: flex; height: 100vh; width: 100vw; }

.onboarding-overlay {
  position: fixed; inset: 0; background: linear-gradient(135deg, var(--primary-dark), var(--primary), var(--primary-light)); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.onboarding-card {
  background: var(--white); border-radius: 20px; padding: 40px; width: 90%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-height: 90vh; overflow-y: auto;
}
.onboarding-card h1 { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.onboarding-card .onboarding-subtitle { color: var(--primary); font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.onboarding-card p { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; line-height: 1.5; }
.onboarding-card label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.onboarding-card input, .onboarding-card select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-input);
  font-size: 15px; margin-bottom: 16px; background: var(--input-bg); color: var(--text); outline: none;
  transition: border-color .2s;
}
.onboarding-card input:focus, .onboarding-card select:focus { border-color: var(--primary); }
.onboarding-card .profile-name-row { display: flex; gap: 12px; margin-bottom: 4px; }
.onboarding-card .shift-row { display: flex; gap: 8px; margin-bottom: 8px; }
.onboarding-card .shift-row > div { flex: 1; min-width: 0; }
.onboarding-card .shift-row input { margin-bottom: 4px; width: 100%; box-sizing: border-box; }
.onboarding-card .days-row { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: nowrap; }
.onboarding-card .day-btn {
  padding: 10px 0; border-radius: var(--radius-chip); border: 1.5px solid var(--border);
  background: var(--input-bg); font-size: 13px; font-weight: 600; color: var(--text-secondary);
  transition: all .2s; flex: 1; min-width: 0; text-align: center;
}
.onboarding-card .day-btn.active { background: var(--primary); color: var(--white); border-color: var(--primary); }

.btn-primary {
  background: var(--primary); color: var(--white); border: none; padding: 14px 24px;
  border-radius: 12px; font-size: 16px; font-weight: 600; width: 100%;
  transition: all .2s; position: relative; overflow: hidden;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,71,171,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary {
  background: var(--surface-secondary); color: var(--text); border: none; padding: 14px 24px;
  border-radius: var(--radius-input); font-size: 16px; font-weight: 600; width: 100%;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: var(--danger); color: var(--white); border: none; padding: 12px 20px;
  border-radius: var(--radius-input); font-size: 14px; font-weight: 600;
  transition: background .15s;
}
.btn-danger:hover { background: #c82333; }

.sidebar {
  width: var(--sidebar-w); background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100vh; flex-shrink: 0; z-index: 10;
}
.sidebar-header {
  padding: 20px 20px 16px; background: var(--white); border-bottom: 1px solid var(--border);
}
.sidebar-header h1 { color: var(--text); font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.sidebar-header .sidebar-header-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sidebar-header .office-badge {
  display: inline-flex; align-items: center; gap: 6px; background: var(--primary);
  padding: 4px 12px; border-radius: var(--radius-chip); margin-top: 8px; font-size: 11px;
  color: var(--white); font-weight: 600;
}
.sidebar-header .office-badge svg { width: 12px; height: 12px; }

/* Realtime SSE connection status badge — hidden while connected, then
   escalates as the outage drags on:
     reconnecting (~5s)  — subtle gray "Reconnecting…"
     degraded     (~30s) — amber "Reconnecting…" (still trying)
     offline      (~3m)  — red "Offline · data may be stale" + page-wide
                           top stripe so users see cached data is suspect. */
.realtime-status-badge {
  display: none; align-items: center; gap: 5px;
  background: var(--text-secondary, #6B7B8D); color: var(--white);
  padding: 3px 9px; border-radius: 10px;
  font-size: 11px; font-weight: 600; line-height: 1;
  white-space: nowrap; max-width: 280px;
  transition: background-color .2s ease;
}
.realtime-status-badge[data-realtime-status="reconnecting"],
.realtime-status-badge[data-realtime-status="degraded"],
.realtime-status-badge[data-realtime-status="offline"] { display: inline-flex; }
.realtime-status-badge[data-realtime-status="reconnecting"] { background: var(--text-secondary, #6B7B8D); }
.realtime-status-badge[data-realtime-status="degraded"] { background: var(--warning, #E67E22); }
.realtime-status-badge[data-realtime-status="offline"] { background: var(--danger, #DC3545); }
.realtime-status-badge svg { width: 11px; height: 11px; flex-shrink: 0; }
/* Retry affordance: only the degraded/offline tiers expose a click target,
   so only those tiers get the cursor pointer + focus ring. The hover/focus
   styles intentionally apply just to the retryable variants. */
.realtime-status-badge[data-realtime-retryable="true"] {
  cursor: pointer;
  user-select: none;
}
.realtime-status-badge[data-realtime-retryable="true"]:hover { filter: brightness(1.08); }
.realtime-status-badge[data-realtime-retryable="true"]:active { filter: brightness(0.94); }
.realtime-status-badge[data-realtime-retryable="true"]:focus-visible {
  outline: 2px solid var(--primary, #1f6feb);
  outline-offset: 2px;
}
.realtime-status-badge-map {
  position: absolute; top: 12px; right: 12px; z-index: 16;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
@media (max-width: 768px) {
  .realtime-status-badge-map {
    top: max(calc(env(safe-area-inset-top, 12px) + 4px), 16px);
  }
}

/* Cached-data stale marker: when the stream has been offline for ~3 minutes,
   draw a thin red stripe across the very top of the viewport so any data
   currently rendered (pins, alerts, lists) reads as "potentially stale" at
   a glance, not just inside the badge. */
body[data-realtime-status="offline"]::before {
  content: "";
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--danger, #DC3545);
  z-index: 9999;
  pointer-events: none;
}
.mobile-panel-header-right {
  display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap;
}

.sidebar-nav { display: flex; background: var(--white); border-bottom: 1px solid var(--border); padding: 0 8px; }
.sidebar-nav button {
  flex: 1; padding: 12px 4px 10px; border: none; background: none; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); display: flex; flex-direction: column; align-items: center; gap: 4px;
  border-bottom: 2.5px solid transparent; transition: all .2s; position: relative;
}
.sidebar-nav button.active { color: var(--primary); border-bottom-color: var(--primary); }
.sidebar-nav button svg { width: 22px; height: 22px; }

.sidebar-content { flex: 1; overflow-y: auto; background: var(--bg); }
.sidebar-panel { padding: 16px; display: none; }
.sidebar-panel.active { display: block; }

.panel-header {
  font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 16px;
  letter-spacing: -0.5px; display: flex; align-items: center; justify-content: space-between;
}
.panel-header .header-count {
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
}

.search-bar { position: relative; margin-bottom: 12px; }
.search-bar input {
  width: 100%; padding: 10px 12px 10px 38px; border: 1.5px solid transparent; border-radius: var(--radius-input);
  background: var(--white); font-size: 14px; outline: none; color: var(--text);
  box-shadow: var(--shadow-card); transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-secondary); width: 16px; height: 16px;
}

.filter-row {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.filter-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px;
  border-radius: var(--radius-chip); border: 1.5px solid var(--border);
  background: var(--white); font-size: 12px; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.filter-chip:hover { border-color: var(--primary-light); }
.filter-chip.active {
  background: var(--primary); color: var(--white); border-color: var(--primary);
}
.filter-chip svg { width: 14px; height: 14px; flex-shrink: 0; }

.pin-list, .alert-list, .vault-list { display: flex; flex-direction: column; gap: 10px; }

.pin-item {
  padding: 14px 16px; background: var(--white); border-radius: var(--radius-card);
  cursor: pointer; transition: all .2s; box-shadow: var(--shadow-card);
}
.pin-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); transform: translateY(-1px); }
.pin-item h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.pin-item p { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.pin-item .pin-alert-dot {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10px;
  background: #fde8ea; color: var(--danger); padding: 2px 6px; border-radius: 8px; font-weight: 700;
}

.alert-item {
  padding: 14px 16px; background: var(--white); border-radius: var(--radius-card);
  cursor: pointer; transition: all .2s; box-shadow: var(--shadow-card);
}
.alert-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); transform: translateY(-1px); }
.alert-item.critical { border-left: 4px solid var(--danger); }
.alert-item h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); line-height: 1.3; }
.alert-item p { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.alert-item .alert-meta {
  display: flex; align-items: center; justify-content: space-between; margin-top: 8px;
  font-size: 12px; color: var(--text-secondary);
}

.badge-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.priority-badge {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
}
.priority-badge.critical { background: #fde8ea; color: var(--danger); }
.priority-badge.high { background: #fef3e6; color: var(--warning); }
.priority-badge.normal { background: #e8f0fe; color: var(--primary); }
.category-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.category-badge svg { width: 14px; height: 14px; flex-shrink: 0; }

.vault-item {
  padding: 14px 16px; background: var(--white); border-radius: var(--radius-card);
  cursor: pointer; transition: all .2s; box-shadow: var(--shadow-card);
}
.vault-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); transform: translateY(-1px); }
.vault-item.just-created, .alert-item.just-created {
  animation: justCreatedFlash 1.6s ease-out;
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
@keyframes justCreatedFlash {
  0% { background: rgba(0, 71, 171, 0.18); }
  100% { background: var(--white); }
}
.vault-item h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.vault-item p { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.vault-item .vault-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.vault-item .vault-footer {
  display: flex; align-items: center; justify-content: space-between; margin-top: 8px;
  font-size: 12px; color: var(--text-secondary);
}

.tag-chip {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: var(--radius-chip);
  font-size: 11px; font-weight: 600; background: var(--surface-secondary); color: var(--primary);
  cursor: pointer; border: 1.5px solid transparent; transition: all .2s; white-space: nowrap;
}
.tag-chip:hover { background: #dce5f0; }
.tag-chip.active { background: var(--primary); color: var(--white); border-color: var(--primary); }

.map-area {
  flex: 1; position: relative;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: pan-x pan-y;
}
#map { width: 100%; height: 100%; -webkit-user-select: none; user-select: none; }

.context-menu {
  position: fixed; background: var(--white); border-radius: 14px; box-shadow: var(--shadow-elevated);
  padding: 6px; min-width: 200px; z-index: 1000; display: none;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.context-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border: none; background: none;
  font-size: 14px; font-weight: 500; color: var(--text); border-radius: 10px; transition: background .15s; text-align: left;
}
.context-menu button:hover { background: var(--input-bg); }
.context-menu button svg { width: 18px; height: 18px; color: var(--primary); flex-shrink: 0; }

.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 500;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--white); border-radius: 20px 20px 0 0; padding: 24px 24px 32px;
  width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
  animation: slideUp .3s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes scaleIn {
  from { transform: translateY(8px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-card .modal-handle {
  width: 36px; height: 4px; background: var(--border); border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.3px; }
.modal-card label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 6px; margin-top: 14px; text-transform: uppercase; letter-spacing: 0.3px;
}
.modal-card label:first-of-type { margin-top: 0; }
.modal-card input, .modal-card textarea, .modal-card select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-input);
  background: var(--input-bg); font-size: 14px; outline: none; color: var(--text);
  transition: border-color .2s;
}
.modal-card input:focus, .modal-card textarea:focus, .modal-card select:focus { border-color: var(--primary); }
.modal-card textarea { resize: vertical; min-height: 80px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; }

.detail-panel {
  position: absolute; top: 0; right: 0; width: 400px; max-width: 90vw; height: 100%;
  background: var(--white); box-shadow: -4px 0 24px rgba(0,0,0,0.1); z-index: 20;
  display: flex; flex-direction: column; animation: slideInRight .25s ease-out;
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }

.detail-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; background: var(--white);
}
.detail-header h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.detail-close {
  background: var(--input-bg); border: none; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary);
  font-size: 18px; transition: background .15s;
}
.detail-close:hover { background: var(--border); }
.detail-body { padding: 20px; flex: 1; overflow-y: auto; }
.detail-body .field { margin-bottom: 16px; }
.detail-body .field-label {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;
}
.detail-body .field-value { font-size: 15px; color: var(--text); line-height: 1.5; }

.office-badge-map {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 15;
  background: rgba(0,71,171,0.92); color: var(--white); padding: 6px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2); backdrop-filter: blur(8px);
  cursor: pointer;
}
.map-area .gm-style a[href*="keyboard"],
.map-area .gm-style .gmnoprint:not(.gm-bundled-control) {
  display: none !important;
}
.pin-label {
  background: rgba(255,255,255,0.92);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.office-pin-label {
  background: rgba(255,255,255,0.95);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px !important;
}

.no-office-banner {
  position: absolute; bottom: 16px; left: 16px; right: 16px; z-index: 20;
  background: rgba(0,71,171,0.92); border-radius: 14px; padding: 14px 18px;
  display: flex; align-items: center; gap: 12px; color: var(--white);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); backdrop-filter: blur(8px);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.no-office-banner svg { width: 24px; height: 24px; flex-shrink: 0; opacity: .9; }
.no-office-banner .banner-title { font-weight: 700; font-size: 14px; }
.no-office-banner .banner-sub { opacity: .85; font-size: 13px; margin-top: 2px; }

.sos-fab {
  position: absolute; bottom: 14px; right: 14px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--danger); color: var(--white); border: none; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(220,53,69,0.4); transition: all .2s;
}
.sos-fab svg { width: 56px; height: 56px; }
.sos-fab:hover { background: #c82333; transform: scale(1.08); }
.sos-fab:active { transform: scale(0.95); background: #B02A37; }

/* Task #254: desktop variant — pill button with visible label, sits left of
   the legend / reload FAB column at the bottom-right of the map area. */
.sos-fab-desktop {
  width: auto; height: 52px; border-radius: 26px;
  padding: 0 20px 0 14px; gap: 10px;
  bottom: 16px; right: 80px;
  font-family: inherit;
}
.sos-fab-desktop:hover { transform: scale(1.04); }
.sos-fab-desktop:active { transform: scale(0.97); }
.sos-fab-desktop svg { width: 28px; height: 28px; }
.sos-fab-desktop .sos-fab-desktop-label {
  font-size: 14px; font-weight: 600; letter-spacing: 0.2px; color: var(--white);
  white-space: nowrap;
}

.legend-fab {
  position: absolute; right: 18px;
  /* Task #246: on desktop the legend stacks ABOVE the Force Reload FAB
     (which now occupies the bottom-right corner). Reload is 44px tall
     with a 10px gap, matching the mobile stacking math. The
     `@media (max-width: 768px)` override below restores the mobile
     position (above the SOS FAB). */
  bottom: calc(16px + 44px + 10px + env(safe-area-inset-bottom, 0));
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--white); color: var(--primary); border: none; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18); transition: background .15s, transform .15s;
}
.legend-fab svg { width: 24px; height: 24px; color: var(--primary); }
.legend-fab:hover { background: var(--surface-secondary); }
.legend-fab:active { transform: scale(0.95); }
@media (max-width: 768px) {
  /* Sit above the SOS FAB (56px tall, bottom: 14px + safe-area) */
  .legend-fab { bottom: calc(14px + 56px + 12px + env(safe-area-inset-bottom, 0)); }
}

/*
 * Task #229 (visible affordance follow-up): break-glass map reload FAB,
 * stacked just above the legend FAB so admins see a clear refresh
 * affordance on the map. Mirrors the legend FAB's circular shape and
 * shadow so the two read as a single control cluster.
 */
.force-reload-fab {
  position: absolute; right: 18px;
  /* Task #246: desktop puts Reload at the bottom-right corner (the
     spot the legend used to occupy); the legend is shifted up. The
     `@media (max-width: 768px)` override below restores the mobile
     stacking (above the legend, above the SOS FAB). */
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--white); color: var(--primary); border: none; z-index: 15;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18); transition: background .15s, transform .15s;
}
.force-reload-fab svg { width: 22px; height: 22px; color: var(--primary); }
.force-reload-fab:hover { background: var(--surface-secondary); }
.force-reload-fab:active { transform: scale(0.95); }
.force-reload-fab.is-busy svg { animation: force-reload-spin 0.9s linear infinite; }
.force-reload-fab[disabled] { opacity: 0.7; cursor: progress; }
@keyframes force-reload-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@media (max-width: 768px) {
  /* Stack above the mobile-positioned legend FAB which itself sits
     above the SOS FAB (legend at bottom: 14 + 56 + 12 + safe-area). */
  .force-reload-fab { bottom: calc(14px + 56px + 12px + 44px + 10px + env(safe-area-inset-bottom, 0)); }
}

.legend-modal-card { padding-top: 12px; }
.legend-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.legend-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.2px; margin: 0; }
.legend-close {
  background: var(--input-bg); border: none; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary);
  transition: background .15s;
}
.legend-close:hover { background: var(--border); }
.legend-close svg { width: 18px; height: 18px; }
.legend-list { display: flex; flex-direction: column; }
.legend-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 4px;
}
.legend-swatch {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.legend-swatch svg { display: block; }
.legend-label { font-size: 14px; color: var(--text); }
.sos-banner {
  background: var(--danger); border: 1.5px solid #c82333; border-radius: var(--radius-card); padding: 14px;
  margin-bottom: 12px; box-shadow: var(--shadow-card);
}
.sos-banner h4 { color: var(--white); font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.sos-banner p { color: rgba(255,255,255,0.9); font-size: 13px; }
.sos-banner-expired { background: #6B7280; border-color: #4B5563; }

.sos-banner-wrap { position: absolute; z-index: 15; }
.sos-banner-wrap-mobile { bottom: 70px; left: 16px; right: 16px; max-height: calc(100vh - 200px); display: flex; flex-direction: column; }
.sos-banner-wrap-desktop { top: 16px; right: 16px; width: 360px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.sos-banner-wrap > .sos-banner { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

.sos-chat {
  margin-top: 12px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 8px;
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
.sos-chat-messages {
  flex: 1; min-height: 80px; max-height: 280px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding: 4px;
}
.sos-chat-empty {
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  padding: 16px 8px;
}
.sos-chat-bubble {
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--white);
}
.sos-chat-bubble-header {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 2px;
}
.sos-chat-sender { font-size: 12px; font-weight: 700; color: var(--white); }
.sos-chat-timestamp { font-size: 11px; color: rgba(255,255,255,0.65); }
.sos-chat-text { font-size: 13px; color: var(--white); line-height: 1.35; word-wrap: break-word; }
.sos-chat-input-row {
  margin-top: 8px;
  display: flex; gap: 6px; align-items: center;
}
.sos-chat-input {
  flex: 1;
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.sos-chat-input::placeholder { color: var(--text-secondary); }
.sos-chat-send {
  background: var(--white);
  color: var(--danger);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.sos-chat-send:hover { background: rgba(255,255,255,0.85); }
.sos-chat-send:active { transform: scale(0.97); }
.sos-chat-locked {
  margin-top: 8px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  font-style: italic;
  padding: 6px;
}

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .35; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13px; line-height: 1.5; }
.empty-state.error h3 { color: var(--danger); }
.empty-state .empty-retry {
  margin-top: 14px; padding: 8px 18px; border-radius: 8px;
  background: var(--white); color: var(--primary);
  border: 1.5px solid var(--primary-light); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.empty-state .empty-retry:hover { background: var(--input-bg); border-color: var(--primary); }
.list-spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(0, 71, 171, 0.15);
  border-top-color: var(--primary);
  margin: 0 auto 14px;
  animation: lightboxSpin 0.9s linear infinite;
}

.settings-group {
  background: var(--white); border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  margin-bottom: 16px; overflow: hidden;
}
.settings-group-title {
  font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 8px; padding: 0 4px;
}
.settings-row {
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
  min-height: 48px;
}
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row label { font-size: 14px; font-weight: 500; color: var(--text); }
.settings-row svg { width: 16px; height: 16px; flex-shrink: 0; }
.settings-row .row-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-row input {
  max-width: 200px; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--input-bg); outline: none;
}
.settings-row input:focus { border-color: var(--primary); }

.settings-btn {
  padding: 12px 16px; border-radius: var(--radius-input); border: 1.5px solid var(--border);
  background: var(--white); font-size: 14px; font-weight: 600; color: var(--primary);
  cursor: pointer; transition: all .2s; width: 100%; text-align: center;
}
.settings-btn:hover { background: var(--input-bg); border-color: var(--primary-light); }
.settings-btn.danger { color: var(--danger); border-color: rgba(220,53,69,0.3); }
.settings-btn.danger:hover { background: #fde8ea; border-color: var(--danger); }

.attachment-thumb {
  width: 64px; height: 64px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--border); margin: 4px; cursor: pointer;
  transition: transform .15s;
}
.attachment-thumb:hover { transform: scale(1.05); }
.attachment-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  background: var(--input-bg); border-radius: 10px; font-size: 12px; font-weight: 500;
  color: var(--primary); text-decoration: none; margin: 4px;
  transition: background .15s;
}
.attachment-link:hover { background: var(--surface-secondary); }

/* --- Image lightbox (full-screen attachment viewer) --- */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.95); z-index: 9500;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease-out;
  overscroll-behavior: contain;
}
.lightbox-stage {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  /* Disable browser default gestures (horizontal swipe back/forward AND
     pinch-zoom) so the lightbox can own pinch-zoom + pan itself (task #109). */
  touch-action: none;
}
.lightbox-image {
  max-width: 95vw; max-height: 95vh; object-fit: contain;
  user-select: none; -webkit-user-drag: none;
  transition: opacity .15s ease-out;
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
}
.lightbox-image.is-loading { opacity: 0; }
.lightbox-image.is-zoomed { cursor: grab; }
.lightbox-image.is-zoomed:active { cursor: grabbing; }
.lightbox-image.is-animating { transition: transform .2s ease-out, opacity .15s ease-out; }
.lightbox-spinner {
  position: absolute; width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.85);
  animation: lightboxSpin 0.9s linear infinite;
}
@keyframes lightboxSpin { to { transform: rotate(360deg); } }
.lightbox-error {
  position: absolute; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
  color: #fff; text-align: center; gap: 12px;
}
.lightbox-error-text { font-size: 14px; opacity: 0.9; margin: 0; }
.lightbox-retry {
  margin-top: 4px; padding: 9px 18px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35); font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.lightbox-retry:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px 8px;
  pointer-events: none;
}
.lightbox-topbar > * { pointer-events: auto; }
.lightbox-counter {
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 5px 12px; border-radius: 14px;
}
.lightbox-iconbtn {
  width: 44px; height: 44px; border-radius: 22px;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lightbox-iconbtn:hover { background: rgba(0, 0, 0, 0.75); }
.lightbox-iconbtn svg { width: 24px; height: 24px; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
}
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-nav.prev svg { transform: rotate(180deg); }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--white); padding: 12px 24px; border-radius: 14px;
  font-size: 14px; font-weight: 500; z-index: 9000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25); animation: toastIn .3s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Task #132 — flash highlight for the duplicate tag row in the Configure
   Tags modal so admins immediately spot the existing tag the server told
   us about (409 + existingTagId). */
.vault-tag-row-flash {
  animation: vaultTagRowFlash 1.6s ease-out;
}
@keyframes vaultTagRowFlash {
  0%   { background-color: rgba(255, 235, 130, 0.95); }
  60%  { background-color: rgba(255, 235, 130, 0.55); }
  100% { background-color: transparent; }
}

.fab {
  position: absolute; bottom: 24px; right: 20px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: var(--white); border: none; font-size: 28px;
  box-shadow: 0 4px 16px rgba(0,71,171,0.35); z-index: 15;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.fab svg { width: 26px; height: 26px; }
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,71,171,0.45); }
.fab:active { transform: scale(0.95); }
.alerts-fab, .vault-fab { position: fixed; right: 20px; bottom: 24px; z-index: 15; }
@media (min-width: 769px) {
  .sidebar-content { position: relative; }
  .alerts-fab, .vault-fab { position: absolute; right: 16px; bottom: 16px; }
}
@media (max-width: 768px) { .alerts-fab, .vault-fab { bottom: calc(var(--tab-h) + 20px); } }
.fab.fab-danger { background: var(--danger); box-shadow: 0 4px 16px rgba(220,53,69,0.35); }
.fab.fab-danger:hover { box-shadow: 0 6px 20px rgba(220,53,69,0.45); }

.config-btn {
  width: 40px; height: 40px; border-radius: var(--radius-input); background: var(--white);
  border: 1.5px solid var(--border); cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: all .15s;
  box-shadow: var(--shadow-card);
}
.config-btn:hover { border-color: var(--primary-light); background: var(--input-bg); }
.config-btn svg { width: 18px; height: 18px; color: var(--primary); }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-tabs {
    position: fixed; bottom: 0; left: 0; right: 0; height: var(--tab-h);
    background: rgba(255,255,255,0.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border); display: flex; z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-tabs button {
    flex: 1; border: none; background: none; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px; font-size: 10px; font-weight: 600;
    color: var(--text-secondary); padding: 6px 2px; transition: color .15s;
  }
  .mobile-tabs button.active { color: var(--primary); }
  .mobile-tabs button svg { width: 24px; height: 24px; }

  .mobile-panel {
    position: fixed; top: 0; left: 0; right: 0; bottom: var(--tab-h); background: var(--bg);
    z-index: 50; display: none; flex-direction: column; overflow: hidden;
  }
  .mobile-panel.active { display: flex; }
  .mobile-panel-header {
    padding: 16px 20px; padding-top: max(calc(env(safe-area-inset-top, 16px) + 8px), 20px);
    background: var(--white); border-bottom: 1px solid var(--border);
  }
  .mobile-panel-header h2 { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
  .mobile-panel-header .header-office {
    display: inline-flex; align-items: center; gap: 4px; background: var(--primary);
    padding: 3px 10px; border-radius: 10px; margin-top: 6px; font-size: 11px;
    color: var(--white); font-weight: 600;
  }
  .mobile-panel-content { flex: 1; overflow-y: auto; padding: 16px; }

  .onboarding-card { padding: 28px 20px; }
  .onboarding-card .profile-name-row { flex-direction: column; gap: 0; }
  .onboarding-card .shift-row { gap: 8px; }
  .onboarding-card .shift-row input[type="time"] { padding: 10px 8px; font-size: 14px; }
  .map-area { position: fixed; top: 0; left: 0; right: 0; bottom: var(--tab-h); }
  .detail-panel { width: 100%; max-width: 100%; }
  .office-badge-map { top: max(calc(env(safe-area-inset-top, 12px) + 4px), 16px); }
  .no-office-banner { bottom: 70px; }

  .modal-overlay { align-items: flex-end; }
  .modal-card { max-width: 100%; border-radius: 20px 20px 0 0; padding-bottom: calc(32px + env(safe-area-inset-bottom, 0)); }
}

.pin-info-card { padding-bottom: 16px; }
.pic-header { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 12px; gap: 12px; }
.pic-title { font-size: 20px; font-weight: 700; color: var(--text); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pic-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.pic-icon-btn {
  position: relative; width: 36px; height: 36px; border-radius: 18px; background: var(--surface-secondary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.pic-icon-btn:hover { background: var(--border); }
.pic-alert-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px;
  background: #DC3545; color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.pic-body { padding: 0 20px; }
.pic-field { margin-bottom: 14px; }
.pic-field-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 4px; }
.pic-field-value { font-size: 15px; color: var(--text); line-height: 1.4; white-space: pre-wrap; }
.pic-alert-section { margin-top: 8px; }
.pic-alert-row { padding: 10px; background: var(--surface-secondary); border-radius: 10px; margin-top: 8px; cursor: pointer; transition: background .15s; }
.pic-alert-row:hover { background: var(--border); }

.office-info-card { padding-bottom: 16px; }
.oic-header { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 12px; }
.oic-header-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.oic-icon-circle {
  width: 44px; height: 44px; border-radius: 22px; border: 2px solid var(--primary);
  background: rgba(0,71,171,0.08); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.oic-icon-circle svg { width: 22px; height: 22px; color: var(--primary); stroke: var(--primary); }
.oic-header-info { flex: 1; min-width: 0; }
.oic-name { font-size: 18px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oic-code-row { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.oic-code { font-size: 14px; font-weight: 600; color: var(--text-secondary); font-family: 'SF Mono', Menlo, monospace; letter-spacing: 1px; }
.oic-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.oic-nav-btn {
  width: 36px; height: 36px; border-radius: 18px; background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.oic-nav-btn:hover { background: var(--primary-dark); }
.oic-close-btn {
  width: 36px; height: 36px; border-radius: 18px; background: var(--surface-secondary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.oic-close-btn:hover { background: var(--border); }
.oic-divider { height: 1px; background: var(--border); margin: 0 20px; }
.oic-section-header { display: flex; align-items: center; gap: 6px; padding: 14px 20px 8px; }
.oic-section-title { font-size: 15px; font-weight: 700; color: var(--text); }
.oic-pin-list { max-height: 45vh; overflow-y: auto; padding: 0 20px; }
.oic-pin-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 4px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background .15s;
}
.oic-pin-row:hover { background: var(--surface-secondary); border-radius: 8px; }
.oic-pin-row:last-child { border-bottom: none; }
.oic-pin-dot { width: 10px; height: 10px; border-radius: 5px; background: var(--primary); flex-shrink: 0; }
.oic-pin-info { flex: 1; min-width: 0; }
.oic-pin-name { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oic-pin-meta { display: flex; gap: 10px; margin-top: 2px; }
.oic-pin-meta span { font-size: 12px; color: var(--text-secondary); }
.oic-empty { display: flex; flex-direction: column; align-items: center; padding: 32px 0; gap: 8px; }
.oic-empty-text { font-size: 16px; font-weight: 600; color: var(--text); }
.oic-empty-sub { font-size: 13px; color: var(--text-secondary); }

@media (min-width: 769px) {
  .mobile-tabs { display: none; }
  .mobile-panel { display: none !important; }
  .modal-overlay {
    align-items: center;
    padding: 24px;
    overflow-y: auto;
  }
  .modal-card {
    border-radius: 20px;
    max-width: 480px;
    max-height: calc(100vh - 48px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.22);
    animation: scaleIn .2s ease-out;
    margin: auto;
  }
  /* The handle is a bottom-sheet affordance — hide it for centered desktop modals. */
  .modal-card .modal-handle { display: none; }
}
