/* =========================================================
   PAWTRACE — OMAG Pet ID & Rescue System
   Design System v5 — "Cobalt Slate" light theme
   Palette: #1D4ED8 · #3B82F6 · #60A5FA · #0F172A · #64748B
   A modern SaaS-console aesthetic: white surfaces, hairline
   borders, indigo accents, generous spacing, soft depth.
   Preserves 100% of existing class contracts & functionality.
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Surfaces — cool neutral slate scale */
  --background: #f6f7f9;
  --sidebar-bg: #ffffff;
  --topbar-bg: #ffffff;
  --card: #ffffff;
  --card-hover: #ffffff;
  --surface-2: #f1f3f7;
  --surface-3: #e6e9f0;
  --foreground: #0f172a;
  --muted: #475569;
  --faint: #64748b;
  --ghost-text: #94a3b8;

  /* Brand — cobalt indigo */
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eef2ff;
  --primary-glow: rgba(59, 130, 246, 0.28);
  --secondary: #3b82f6;
  --secondary-soft: #eff6ff;
  --secondary-glow: rgba(59, 130, 246, 0.22);

  /* Status — calm, accessible tones */
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #0284c7;
  --info-soft: #f0f9ff;

  /* Lines */
  --border: #e5e8ee;
  --border-subtle: #eef0f4;
  --border-strong: #d5dae3;

  /* Shape & depth */
  --radius: 10px;
  --radius-sm: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);

  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --speed: 0.16s;
}

/* ============ Reset & Base ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  max-width: 100%;
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}

::selection { background: rgba(59, 130, 246, 0.20); }

:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.28);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(100, 116, 139, 0.45); }

/* Typography */
.font-display { font-family: var(--font-display); }
.font-mono { font-family: var(--font-mono); }

h1, h2, h3 { letter-spacing: -0.015em; }

/* ============ Layout Structure ============ */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* ============ Sidebar ============ */
.sidebar {
  width: 264px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  transition: transform 0.26s var(--ease), width 0.26s var(--ease);
}

.sidebar-logo {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo .logo-brand { flex: 1; min-width: 0; }

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.logo-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--foreground);
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--primary);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.logo-text {
  font-family: var(--font-display);
  font-size: 18.5px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--foreground);
}

.logo-tagline {
  font-size: 10.5px;
  color: var(--faint);
  font-weight: 600;
  margin-top: 1px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Nav group labels */
.nav-section {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ghost-text);
  padding: 18px 10px 6px;
}

.nav-section:first-child { padding-top: 6px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 500;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
  position: relative;
}

.sidebar-link:hover {
  background: var(--surface-2);
  color: var(--foreground);
}

.sidebar-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.sidebar-link.active .nav-icon { filter: none; }

.sidebar-link .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--faint);
  transition: color var(--speed) var(--ease);
}

.sidebar-link:hover .nav-icon { color: var(--muted); }
.sidebar-link.active .nav-icon { color: var(--primary); }

.sidebar-link .nav-badge {
  margin-left: auto;
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-weight: 600;
  background: var(--danger);
  color: #fff;
  min-width: 20px;
  text-align: center;
}

/* System Status Box */
.sidebar-status {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
}

.status-title {
  font-size: 10.5px;
  color: var(--ghost-text);
  font-family: var(--font-mono);
  margin-bottom: 8px;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 13px;
  color: var(--muted);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--success);
  font-family: var(--font-mono);
}

.status-indicator > span:last-child { text-transform: capitalize; }

/* User Profile in Sidebar */
.sidebar-user {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface-2);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-sub {
  font-size: 11.5px;
  color: var(--faint);
}

/* ============ Main Area ============ */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ============ Topbar Header ============ */
.topbar {
  height: 60px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 40px;
  flex-shrink: 0;
  z-index: 40;
}

.mobile-menu-btn {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
  line-height: 1;
  flex-shrink: 0;
  touch-action: manipulation;
}

.mobile-menu-btn:hover { background: var(--surface-3); }

.topbar-title { min-width: 0; }

.topbar-title h2 {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title .subtitle {
  font-size: 12.5px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* "Systems operational" live pill */
.system-live-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid #a7f3d0;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 600;
}

@media (max-width: 860px) {
  .system-live-badge { display: none; }
}
@media (min-width: 640px) and (max-width: 1080px) {
  .live-badge-text { display: none; }
  .system-live-badge { padding: 6px 8px; }
}

.icon-button {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--speed) var(--ease);
  font-size: 16px;
}

.icon-button:hover {
  background: var(--surface-3);
  color: var(--foreground);
  border-color: var(--border-strong);
}

.icon-button .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}

/* ============ Page Content Viewport ============ */
.content-area {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 30px 40px 60px;
  scroll-behavior: smooth;
}

.page-container {
  max-width: min(1320px, 100%);
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.stat-card { max-width: 100%; min-width: 0; }

/* Page heading helper (works with existing inline headers) */
.page-container > div:first-child h1 { font-size: 24px; }
.page-container > div:first-child p { font-size: 14.5px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head-copy { min-width: 0; flex: 1 1 240px; }
.page-kicker {
  font-size: 11.5px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-head h1 {
  margin: 2px 0 4px;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--foreground);
}
.page-head-sub {
  margin: 0;
  color: var(--faint);
  font-size: 14.5px;
  line-height: 1.45;
}
.page-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ============ Cards & Containers ============ */
.glass {
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ============ Badges ============ */
.urgency-badge, .safe-badge, .warning-badge, .info-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  line-height: 1.7;
  white-space: nowrap;
}

.urgency-badge {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
}

.safe-badge {
  background: var(--success-soft);
  border: 1px solid #a7f3d0;
  color: var(--success);
}

.warning-badge {
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  color: var(--warning);
}

.info-badge {
  background: var(--info-soft);
  border: 1px solid #bae6fd;
  color: var(--info);
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  font-family: var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--speed) var(--ease);
  line-height: 1.35;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(29, 78, 216, 0.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 3px 10px var(--primary-glow);
}

.btn-secondary {
  background: var(--secondary-soft);
  border-color: #bfdbfe;
  color: var(--primary);
}
.btn-secondary:hover:not(:disabled) {
  background: #dbeafe;
  border-color: #93c5fd;
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn-ghost {
  background: var(--card);
  border-color: var(--border-strong);
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--foreground);
  border-color: #b6c0cf;
}

/* ============ Inputs & Form Elements ============ */
input, select, textarea {
  background: #ffffff;
  border: 1px solid var(--border-strong);
  color: var(--foreground);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 14.5px;
  transition: border-color var(--speed), background var(--speed), box-shadow var(--speed);
}

input:hover:not(:focus):not(:disabled), select:hover:not(:focus):not(:disabled), textarea:hover:not(:focus):not(:disabled) {
  border-color: #9aa7ba;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
  background: #ffffff;
}

input::placeholder, textarea::placeholder { color: #94a3b8; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; background: var(--surface-2); }

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.42);
  cursor: pointer;
}

select option { background: #ffffff; color: var(--foreground); }

textarea { resize: vertical; min-height: 72px; }

input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Validation states */
input.field-error, select.field-error, textarea.field-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.10);
}
.field-message { font-size: 13px; margin-top: 4px; }
.field-message.error { color: var(--danger); }
.field-message.success { color: var(--success); }
.field-message.hint { color: var(--faint); }

.required-mark::after { content: " *"; color: var(--danger); font-weight: 600; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 13.5px;
  color: var(--foreground);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

/* ============ Animations ============ */
@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.45); }
  70% { transform: scale(1); box-shadow: 0 0 0 12px rgba(59, 130, 246, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
@keyframes slide-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes modal-pop {
  from { transform: translateY(14px) scale(0.985); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes scan-line {
  0% { top: 0; }
  100% { top: 100%; }
}
@keyframes scan-laser-sweep {
  0% { top: 6%; }
  100% { top: 88%; }
}
@keyframes scan-corner-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(96, 165, 250, 0); filter: brightness(1); }
  50% { box-shadow: 0 0 10px 2px rgba(96, 165, 250, 0.95); filter: brightness(1.35); }
}
@keyframes scan-dot {
  0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}
@keyframes pulse-border {
  0% { transform: scale(0.8); opacity: 0.85; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.8); opacity: 0; }
}
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.animate-pulse-ring { animation: pulse-ring 2s infinite; }
.animate-pulse-red { animation: pulse-red 2s infinite; }
.animate-pulse-border { animation: pulse-border 1.6s infinite ease-out; }
.animate-blink { animation: blink 1.5s ease-in-out infinite; }
.animate-slide-in { animation: slide-in 0.25s ease forwards; }
.animate-scan { animation: scan-line 2s linear infinite; }

/* Live collar-tag scanner: laser inside the scan square, pulsing corners. */
.scan-anim-frame {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 6;
  overflow: hidden;
}
.scan-anim-frame.is-on { display: block; }

.scan-laser {
  position: absolute;
  left: 7%;
  width: 86%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0), #93c5fd 18%, #ffffff 50%, #93c5fd 82%, rgba(59, 130, 246, 0));
  box-shadow: 0 0 14px 3px rgba(96, 165, 250, 0.9);
  animation: scan-laser-sweep 1.7s ease-in-out infinite alternate;
}
.scan-laser::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -22px;
  height: 46px;
  background: linear-gradient(to bottom, transparent, rgba(96, 165, 250, 0.38), transparent);
}

#qrReader.is-scanning #qr-shaded-region > div {
  animation: scan-corner-glow 1.5s ease-in-out infinite;
}

#scannerStatusBadge.is-live::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #2563eb;
  vertical-align: middle;
  animation: scan-dot 1.4s ease-out infinite;
}

.scan-guide-tip {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: none;
  max-width: calc(100% - 28px);
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.82);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}
.scan-guide-tip.is-on {
  display: block;
  animation: scan-tip-in 0.35s ease;
}
@keyframes scan-tip-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.scan-guide {
  padding: 16px;
  background: var(--secondary-soft);
  border-color: #bfdbfe;
}
.scan-guide-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
}
.scan-guide-body {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  align-items: center;
}
.scan-guide-demo { text-align: center; }
.scan-demo-frame {
  position: relative;
  width: 112px;
  height: 112px;
  margin: 0 auto;
  background: #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}
.scan-demo-frame > span {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid #2563eb;
  z-index: 2;
}
.scan-demo-frame > span:nth-child(1) { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.scan-demo-frame > span:nth-child(2) { top: 8px; right: 8px; border-left: 0; border-bottom: 0; }
.scan-demo-frame > span:nth-child(3) { bottom: 8px; left: 8px; border-right: 0; border-top: 0; }
.scan-demo-frame > span:nth-child(4) { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }
.scan-demo-tag {
  position: absolute;
  left: 32px;
  top: 32px;
  width: 48px;
  height: 48px;
  border-radius: 3px;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.25);
  animation: scan-demo-tag 3.2s ease-in-out infinite;
}
.scan-demo-laser {
  position: absolute;
  left: 16px;
  width: 80px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, #ffffff, #60a5fa, #ffffff, transparent);
  box-shadow: 0 0 8px 2px rgba(37, 99, 235, 0.85);
  animation: scan-demo-laser 3.2s ease-in-out infinite;
  z-index: 3;
}
.scan-demo-caption {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--faint);
}
.scan-guide-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.scan-guide-steps li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--muted);
}
.scan-guide-steps strong { color: var(--foreground); font-weight: 700; }
.scan-guide-steps .n {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan-guide-steps-compact { width: 100%; max-width: 340px; }
@keyframes scan-demo-tag {
  0% { transform: translate(26px, 16px) scale(0.7); opacity: 0.35; }
  28% { transform: translate(0, 0) scale(1); opacity: 1; }
  78% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(26px, 16px) scale(0.7); opacity: 0.35; }
}
@keyframes scan-demo-laser {
  0%, 32% { top: 18%; opacity: 0; }
  42% { top: 22%; opacity: 1; }
  72% { top: 74%; opacity: 1; }
  84%, 100% { top: 74%; opacity: 0; }
}
@media (max-width: 640px) {
  .scan-guide-body { grid-template-columns: 1fr; }
  .scan-guide-tip { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* The scanner guide and live line are the feature the page is for. */
  .scan-laser {
    animation-duration: 1.7s !important;
    animation-iteration-count: infinite !important;
  }
  .scan-demo-tag,
  .scan-demo-laser {
    animation-duration: 3.2s !important;
    animation-iteration-count: infinite !important;
  }
  #qrReader.is-scanning #qr-shaded-region > div {
    animation-duration: 1.5s !important;
    animation-iteration-count: infinite !important;
  }
  #scannerStatusBadge.is-live::before {
    animation-duration: 1.4s !important;
    animation-iteration-count: infinite !important;
  }
  .scan-guide-tip.is-on {
    animation-duration: 0.35s !important;
    animation-iteration-count: 1 !important;
  }
}

/* ============ Grid Systems ============ */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }

/* ============ Modals ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}

.modal-overlay.active,
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display:flex"] {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-pop 0.22s var(--ease);
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  background: #ffffff;
  z-index: 2;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--foreground);
}

.modal-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--speed);
  font-size: 14px;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============ Toast Notifications ============ */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  background: #ffffff;
  color: var(--foreground);
  padding: 12px 16px;
  padding-left: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slide-in 0.22s ease forwards;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-info { border-left-color: var(--info); }

/* ============ QR Code Display ============ */
.qr-container { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.qr-box {
  background: #ffffff;
  padding: 14px;
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.qr-box canvas, .qr-box img {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  border-radius: 4px;
}

.qr-scan-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  animation: slide-in 0.2s ease forwards;
}

/* ============ Shared UI Helpers ============ */
.section-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ghost-text);
  font-family: var(--font-mono);
}

.empty-state {
  text-align: center;
  padding: 38px 22px;
  color: var(--faint);
}

.empty-state .es-icon { font-size: 30px; margin-bottom: 8px; }
.empty-state .es-title { font-size: 16px; color: var(--foreground); font-weight: 700; }
.empty-state .es-sub { font-size: 14px; margin-top: 5px; line-height: 1.55; color: var(--muted); }

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(15,23,42,0.04) 25%, rgba(15,23,42,0.08) 50%, rgba(15,23,42,0.04) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s linear infinite;
  min-height: 14px;
}

.table-scroll { overflow-x: auto; }

.table-scroll table { width: 100%; border-collapse: collapse; font-size: 14.5px; }

.table-scroll th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ghost-text);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-scroll td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--foreground);
  vertical-align: middle;
}

.table-scroll tr:hover td { background: rgba(59, 130, 246, 0.035); }

/* ============ Page-specific responsive layouts ============ */
.rescue-layout {
  display: grid;
  grid-template-columns: 2fr 1.2fr;
  gap: 20px;
  margin-top: 18px;
  align-items: start;
}

@media (max-width: 1100px) {
  .rescue-layout { grid-template-columns: 1fr; }
}

.split-340 { display: grid; grid-template-columns: 340px 1fr; gap: 20px; margin-top: 16px; align-items: start; }
.split-scan { display: grid; grid-template-columns: 1fr 1.2fr; gap: 24px; margin-top: 20px; }
.split-6040 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-top: 16px; }

@media (max-width: 960px) {
  .split-340, .split-scan, .split-6040 { grid-template-columns: 1fr; }
}

/* Notification dropdown — sized in CSS so phones can override the panel */
.notif-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(380px, calc(100vw - 24px));
  max-height: min(460px, calc(100dvh - 88px));
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1200;
}
.notif-panel.is-open { display: block; }

/* Horizontal bar charts (dashboard + vaccination analytics) */
.hbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  width: 100%;
  min-width: 0;
}
.hbar-name {
  width: min(150px, 34%);
  flex-shrink: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hbar-name.hbar-name-end { text-align: right; }
.hbar-track {
  flex: 1;
  min-width: 36px;
  height: 16px;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}
.hbar-fill { height: 100%; border-radius: 8px; transition: width 0.4s; }
.hbar-meta {
  flex-shrink: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.scanner-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.report-kind-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* ============================================================
   AI Lost ↔ Found Matches Card & Layout
   ============================================================ */
.ai-matches-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: #faf5ff;
}
.ai-matches-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #7c3aed;
  font-size: 15px;
  min-width: 0;
  flex: 1;
}
.ai-matches-panel-title > span:first-child {
  white-space: nowrap;
}

.ai-match-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--card);
  transition: background 0.15s ease;
  position: relative;
}
.ai-match-card.is-linked {
  background: rgba(16, 185, 129, 0.04);
  border-left: 3px solid var(--success);
}
.ai-match-header-row {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.ai-match-pet-names {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--foreground);
  min-width: 0;
}
.ai-match-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-match-arrow {
  color: var(--faint);
  font-weight: normal;
  flex-shrink: 0;
}
.ai-match-score-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.ai-match-body {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}
.ai-match-photos {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.ai-match-photo-wrap {
  width: 82px;
  height: 70px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.ai-match-photo-wrap.is-lost {
  border-color: rgba(220, 38, 38, 0.45);
}
.ai-match-photo-wrap.is-found {
  border-color: rgba(16, 185, 129, 0.45);
}
.ai-match-photo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ai-match-photo-tag {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 10.5px;
  font-weight: 800;
  text-align: center;
  padding: 2px 0;
  letter-spacing: 0.04em;
  color: #fff;
}
.ai-match-photo-tag.is-lost {
  background: rgba(220, 38, 38, 0.88);
}
.ai-match-photo-tag.is-found {
  background: rgba(5, 150, 105, 0.88);
}
.ai-match-photo-vs {
  display: none;
}
.ai-match-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-match-desktop-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 2px;
}
.ai-match-loc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.45;
  word-break: break-word;
}
.ai-match-loc strong {
  color: var(--foreground);
  font-weight: 600;
}
.ai-loc-arrow {
  color: var(--faint);
  margin: 0 2px;
}
.ai-loc-km {
  color: var(--info);
  font-weight: 600;
  margin-left: 2px;
}
.ai-match-meta {
  font-size: 12px;
  color: var(--faint);
  line-height: 1.4;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}
.ai-match-meta strong {
  color: var(--muted);
}
.ai-meta-linked {
  color: #7c3aed;
  font-weight: 600;
}
.ai-match-side-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}
.ai-match-side-score {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
}
.ai-match-actions-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.ai-match-actions-bar.is-mobile-only {
  display: none;
}
.ai-match-status-badge {
  font-size: 11.5px;
  font-weight: 700;
  color: #059669;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 8px;
  padding: 4px 9px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}
.ai-match-reunite-btn {
  font-size: 12.5px;
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.15) !important;
  border: 1px solid rgba(16, 185, 129, 0.4) !important;
  color: var(--success) !important;
  white-space: nowrap;
}
.ai-match-link-btn {
  font-size: 12.5px;
  padding: 4px 12px;
  white-space: nowrap;
}
.ai-match-dismiss-btn {
  font-size: 12.5px;
  padding: 4px 9px;
}

/* ============ Responsive ============ */
/* Tablets and phones: sidebar becomes an off-canvas menu */
@media (max-width: 1023px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 45;
  }
  .mobile-overlay.active { display: block; }
  .content-area { padding: 24px; }
  .topbar { padding: 0 20px; }
  .sidebar-link { min-height: 44px; padding: 11px 12px; }
  #forecastStrip { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  #petLocationMap { height: 480px !important; }
  #rescueMap, #sightingsMap { height: 420px !important; }
  #petMapList { max-height: 320px !important; }
  .split-340 > .stat-card { position: static !important; }
}

/* Phones: stack paired columns, full-width fields, reachable controls */
@media (max-width: 767px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row > .form-group { grid-column: auto !important; }
  .content-area { padding: 16px 16px 48px; }
  .topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .topbar-title h2 { font-size: 16px; line-height: 1.2; }
  .topbar-title .subtitle { display: none; }
  .page-head { align-items: stretch; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1 1 calc(50% - 10px); justify-content: center; }
  .page-container { gap: 14px; }
  .page-container > div:first-child h1,
  .page-container > div:first-child .font-display { font-size: 22px !important; }
  .page-container > div:first-child { align-items: flex-start !important; }
  .page-container > div:first-child > div:last-child { width: 100%; }
  .page-container > div:first-child > div:last-child .btn { flex: 1 1 auto; }
  .stat-card .form-group { flex: 1 1 100%; min-width: 0 !important; }
  .modal-overlay { padding: 10px; align-items: flex-end; }
  .modal-card {
    max-height: min(94dvh, 94vh);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-header > div { min-width: 0; }
  .modal-title { font-size: 16px; overflow-wrap: anywhere; }
  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
    flex-direction: column;
    align-items: stretch;
  }
  .modal-footer > div { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .modal-footer .btn { flex: 1 1 auto; width: 100%; min-height: 44px; }
  #toast-container { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: none; }
  .btn { min-height: 44px; white-space: normal; text-align: center; }
  .icon-button { width: 44px; height: 44px; }
  input, select, textarea { font-size: 16px; scroll-margin-bottom: 140px; }
  #forecastStrip { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .report-kind-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scanner-tabs .btn { flex: 1 1 calc(50% - 8px); }
  #manualLookupForm { flex-direction: column !important; }
  #manualLookupForm .btn { width: 100%; }
  .notif-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    top: 64px;
    width: auto;
  }
  #petVaxDialog { padding: 12px 10px !important; align-items: flex-end !important; }
  #petVaxCard input { width: 100% !important; }
  #rescueMap, #sightingsMap { height: min(62vh, 380px) !important; }
  #petLocationMap { height: min(68vh, 440px) !important; }
  /* Grids on phones: cards should take full readable width */
  .grid-3 { grid-template-columns: 1fr; }

  /* AI Matches Mobile Styling */
  .ai-match-card {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .ai-match-header-row {
    display: flex;
    margin-bottom: 6px;
  }
  .ai-match-desktop-header {
    display: none;
  }
  .ai-match-side-col {
    display: none;
  }
  .ai-match-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }
  .ai-match-photos {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
  }
  .ai-match-photo-wrap {
    flex: 1;
    width: auto;
    height: 105px;
    max-height: 115px;
    border-radius: 8px;
  }
  .ai-match-photo-vs {
    display: flex;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    align-items: center;
    justify-content: center;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--muted);
    flex-shrink: 0;
  }
  .ai-match-content {
    width: 100%;
  }
  .ai-match-actions-bar.is-mobile-only {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-subtle);
  }
  .ai-match-actions-bar.is-mobile-only .ai-match-status-badge {
    flex: 1;
    min-height: 40px;
    justify-content: center;
    font-size: 12px;
  }
  .ai-match-actions-bar.is-mobile-only .ai-match-reunite-btn {
    flex: 1.6;
    min-height: 40px;
    font-size: 13px;
    justify-content: center;
  }
  .ai-match-actions-bar.is-mobile-only .ai-match-link-btn {
    flex: 1;
    min-height: 40px;
    font-size: 13.5px;
    justify-content: center;
  }
  .ai-match-actions-bar.is-mobile-only .ai-match-dismiss-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
  }

  /* Segmented Filter bar horizontal scrolling on phone */
  .sightings-filter-bar {
    display: flex !important;
    gap: 6px !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sightings-filter-bar::-webkit-scrollbar {
    display: none;
  }
  .sightings-filter-bar .btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    min-height: 38px;
    font-size: 13px;
    padding: 6px 14px;
  }

  /* Flex wrapping on mobile: wrap layout containers safely, protecting dedicated components, photos, and pill rows */
  .content-area [style*="display: flex"]:not(.no-wrap):not([class*="ai-match-"]):not(.topbar-actions):not([style*="flex-wrap: nowrap"]):not([style*="flex-wrap:nowrap"]):not(.sightings-filter-bar),
  .content-area [style*="display:flex"]:not(.no-wrap):not([class*="ai-match-"]):not(.topbar-actions):not([style*="flex-wrap: nowrap"]):not([style*="flex-wrap:nowrap"]):not(.sightings-filter-bar) {
    flex-wrap: wrap;
  }

  /* Text overflow containment without crushing flex children to 0px */
  .content-area p,
  .content-area h1,
  .content-area h2,
  .content-area h3,
  .content-area h4 {
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .content-area [style*="grid-template-columns: repeat(4"],
  .content-area [style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Only wrap text that had white-space: nowrap, but PRESERVE badges, tags, buttons, and code pills */
  .content-area [style*="white-space: nowrap"]:not(.btn):not([class*="badge"]):not([class*="tag"]):not([class*="ai-match-"]):not(.nowrap):not([data-restrict]),
  .content-area [style*="white-space:nowrap"]:not(.btn):not([class*="badge"]):not([class*="tag"]):not([class*="ai-match-"]):not(.nowrap):not([data-restrict]) {
    white-space: normal;
  }

  #rescueMap + div { max-width: calc(100% - 16px); }
  .content-area [style*="grid-template-columns: 1fr 1fr"],
  .content-area [style*="grid-template-columns:1fr 1fr"],
  .modal-card [style*="grid-template-columns: 1fr 1fr"],
  .modal-card [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  .leaflet-popup-content-wrapper { max-width: calc(100vw - 48px); }
  .leaflet-popup-content { margin: 12px !important; }
  .pawg-map-toggle { max-width: calc(100vw - 20px); }
}

/* Narrow phones: single column cards and shorter chart labels */
@media (max-width: 479px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .content-area { padding: 14px 12px 40px; }
  .stat-card { padding: 16px; }
  .page-head-dot { display: none; }
  .page-head-date { display: block; margin-top: 2px; }
  .page-head-actions { flex-direction: column; }
  .page-head-actions .btn { width: 100%; }
  .hbar-name { width: min(96px, 32%); font-size: 12.5px; }
  .hbar-meta { font-size: 11.5px; }
  .page-container h1 { font-size: 22px !important; }
  #forecastStrip { grid-template-columns: 1fr 1fr !important; }
}

/* Short landscape phones: keep maps and dialogs inside the viewport */
@media (max-height: 500px) and (orientation: landscape) {
  .content-area { padding-top: 12px; padding-bottom: 20px; }
  #rescueMap, #sightingsMap, #petLocationMap { height: 68vh !important; min-height: 200px; }
  .modal-card { max-height: 92dvh; }
  .login-side { padding-top: 64px !important; padding-bottom: 16px !important; }
}

@media (pointer: coarse) {
  .btn, .sidebar-link, .pawg-toggle-btn, .pub-menu a { touch-action: manipulation; }
  .leaflet-bar a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }
  .pawg-toggle-btn { min-height: 40px; padding: 8px 12px; }
}

img:not(.leaflet-tile):not(.leaflet-marker-icon):not(.leaflet-marker-shadow) {
  max-width: 100%;
}

.table-scroll,
.stat-card [style*="overflow-x"] {
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* Phone app shell. Older installs draw the page under the blue PAWTRACE bar, so the
   first install needs a top offset. Version 2 lays the page out below that bar. */
html.is-native-app,
html.is-native-app body {
  height: 100%;
}
html.is-native-app .app-container {
  height: 100%;
  max-height: 100%;
}
html.is-native-app:not(.is-app-v2) .app-container,
html.is-native-app:not(.is-app-v2) .login-wrap {
  padding-top: 88px;
  background: #ffffff;
}

/* ============ Print (archive summaries + QR tag cards) ============ */
@media print {
  .sidebar, .topbar, .mobile-menu-btn, #toast-container,
  .modal-overlay { display: none !important; }
  .app-container { height: auto; overflow: visible; }
  .main-wrapper { overflow: visible; }
  .content-area { overflow: visible; padding: 0; }
  body { background: #fff; color: #111; }
  .stat-card { background: #fff; color: #111; border: 1px solid #ddd; box-shadow: none; }
  .stat-card * { color: #111 !important; }
  .table-scroll th { background: #f3f4f6 !important; position: static; }
}

/* ============================================================
   Shared Leaflet Map Styling (light Voyager base + popups)
   ============================================================ */

/* --- Map / Satellite / Street View toggle buttons --- */
.pawg-map-toggle {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    max-width: min(420px, calc(100vw - 28px));
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.14);
    z-index: 1000;
}
.pawg-streetview {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 800;
    background: #0f172a;
}
.pawg-streetview.is-open { display: block; }
.pawg-streetview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #0f172a;
}
.pawg-streetview-note {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(360px, calc(100% - 32px));
    margin: 0;
    padding: 14px 16px;
    background: #fff;
    color: #0f172a;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.45;
    text-align: center;
}
.pawg-toggle-btn {
    border: none;
    background: transparent;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.pawg-toggle-btn:hover { background: rgba(15, 23, 42, 0.07); }
.pawg-toggle-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 4px rgba(29, 78, 216, 0.4);
}

/* --- Leaflet popup theming (light cards matching the system) --- */
.leaflet-popup-content-wrapper {
    background: #ffffff !important;
    color: var(--foreground) !important;
    border-radius: 12px !important;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md) !important;
}
.leaflet-popup-content {
    margin: 14px 16px !important;
    font-family: inherit;
    line-height: 1.5;
    color: var(--foreground);
}
.leaflet-popup-tip { background: #ffffff !important; border: 1px solid var(--border); }
.leaflet-popup-close-button {
    color: var(--muted) !important;
    font-size: 18px !important;
    padding: 6px 8px 0 0 !important;
}
.leaflet-popup-close-button:hover { color: var(--foreground) !important; }

/* --- Zoom + attribution on light tiles --- */
.leaflet-bar a {
    background: rgba(255, 255, 255, 0.95) !important;
    color: #1e293b !important;
    border-color: rgba(15, 23, 42, 0.15) !important;
}
.leaflet-bar a:hover { background: #fff !important; }
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.75) !important;
    color: #475569 !important;
    font-size: 11.5px !important;
}
.leaflet-control-attribution a { color: var(--primary) !important; }

/* --- Softer marker drop shadows --- */
.pet-home-pin, .sighting-pin, .custom-picker-pin {
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.35));
    background: none !important;
    border: none !important;
}
.leaflet-container .leaflet-marker-pane {
    z-index: 650 !important;
}

input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}
.field-error {
    color: var(--danger);
    font-size: 12.5px;
    margin-top: 4px;
    line-height: 1.4;
}

/* In-app confirm / prompt — sits above page modals */
.paw-dialog {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.18s ease;
}
.paw-dialog.is-open { opacity: 1; }
.paw-dialog-card {
    width: min(440px, 100%);
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
    padding: 22px 22px 18px;
    font-family: var(--font-display);
}
.paw-dialog-title {
    margin: 0 0 8px;
    font-size: 17px;
    font-weight: 700;
    color: var(--navy, #0f172a);
    letter-spacing: -0.01em;
}
.paw-dialog-message {
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--muted);
    white-space: pre-line;
}
.paw-dialog-input {
    width: 100%;
    margin: 0 0 16px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    color: var(--navy, #0f172a);
    background: #fff;
    outline: none;
}
.paw-dialog-input:focus {
    border-color: var(--teal, #0d9488);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}
.paw-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ============================================================
   OFFLINE-FIRST: sync status pill + panel (topbar)
   ============================================================ */
.pt-offline-status {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.pt-offline-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    white-space: nowrap;
}

.pt-offline-pill:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.pt-offline-pill .pt-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #64748b;
}

.pt-offline-pill.online .pt-dot {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, .7);
}

.pt-offline-pill.offline .pt-dot {
    background: #dc2626;
    box-shadow: 0 0 6px rgba(220, 38, 38, .7);
    animation: pt-pulse 1.6s infinite;
}

@keyframes pt-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

.pt-pending-badge {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 11.5px;
    font-weight: 800;
    text-align: center;
    line-height: 16px;
}

.pt-pending-badge.hot { background: #d97706; }

.pt-offline-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 330px;
    max-width: calc(100vw - 32px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg, 0 18px 46px rgba(0, 0, 0, .45));
    z-index: 90;
    padding: 14px;
    font-size: 13.5px;
    color: var(--muted);
    max-height: 70vh;
    overflow-y: auto;
}

.pt-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: var(--foreground);
}

.pt-panel-head strong { font-family: var(--font-display); font-size: 15px; }

.pt-panel-close {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
}

.pt-panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    margin-bottom: 10px;
}

.pt-kv-label {
    display: block;
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ghost-text, #64748b);
    font-weight: 700;
    margin-bottom: 2px;
}

.pt-kv-value { display: block; color: var(--foreground); font-size: 13.5px; font-weight: 600; }

.pt-panel-queue { margin-bottom: 8px; }

.pt-queue-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 4px;
    border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, .15));
}

.pt-queue-tx { flex-shrink: 0; width: 104px; color: var(--foreground); font-size: 12.5px; font-weight: 600; }
.pt-queue-code { flex: 1; font-family: var(--font-mono); font-size: 12px; color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-queue-time { flex-shrink: 0; font-size: 11.5px; color: var(--ghost-text, #64748b); }

.pt-queue-empty, .pt-panel-actions { padding: 6px 4px; }

.pt-history-counts {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-size: 12.5px;
    margin-bottom: 6px;
}

.pt-history-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    font-size: 12.5px;
}

.pt-history-row.synced > span:first-child { color: #22c55e; font-weight: 800; }
.pt-history-row.failed > span:first-child { color: #dc2626; font-weight: 800; }
.pt-history-detail { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12px; }
.pt-history-time { color: var(--ghost-text, #64748b); font-size: 11px; }

.pt-panel-actions {
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 8px;
}

.pt-btn-sync {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.pt-btn-ghost {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

/* Phones: the panel was absolutely anchored to the status pill inside the
   topbar, so its left half ran off the screen. Pin it to the viewport and
   let the buttons wrap instead. */
@media (max-width: 767px) {
    .pt-offline-panel {
        position: fixed;
        left: 10px;
        right: 10px;
        top: 64px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 84px);
        z-index: 1000;
        overscroll-behavior: contain;
    }

    .pt-panel-actions {
        flex-wrap: wrap;
    }

    .pt-panel-actions .pt-btn-sync,
    .pt-panel-actions .pt-btn-ghost {
        flex: 1 1 130px;
    }
}
