/* =========================================================================
   RiskRun — panel.css
   Single stylesheet for the public site panel (login + dashboard).
   ========================================================================= */

/* -------------------------------------------------------------------------
   Design tokens
   ------------------------------------------------------------------------- */
:root {
  /* Surfaces */
  --bg: #0F2123;
  --surface: #162A2D;
  --surface-hi: #1E3639;
  --card: #1A2C2E;

  /* Brand */
  --primary: #00E5FF;
  --primary-dark: #0AB5C9;

  /* Text */
  --text: #ffffff;
  --muted: #8DC8CE;
  --gray: #B0B0B0;

  /* Lines */
  --line: rgba(255, 255, 255, 0.10);
  --line-primary: rgba(0, 229, 255, 0.30);

  /* Semantic */
  --success: #00E676;
  --error: #FF1744;
  --info: #2979FF;
  --warning: #FFC107;

  /* Shape */
  --radius: 20px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  /* Typography */
  --font-head: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Layout */
  --shell-side: 264px;
  --topbar-h: 56px;
  --content-max: 1180px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* -------------------------------------------------------------------------
   Base
   ------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, ul, ol {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

img, svg, video, canvas {
  display: block;
  max-width: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input, select, textarea {
  font: inherit;
  color: inherit;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-head);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

[hidden] {
  display: none !important;
}

/* Focus visible (single source of truth) */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: 4px;
}

/* -------------------------------------------------------------------------
   Utilities
   ------------------------------------------------------------------------- */
.muted   { color: var(--muted); }
.small   { font-size: 13px; line-height: 1.5; }
.nowrap  { white-space: nowrap; }
.right   { margin-left: auto; }
.spacer  { flex: 1 1 auto; }

.divider {
  height: 1px;
  background: var(--line);
  border: 0;
  margin: 16px 0;
}

/* -------------------------------------------------------------------------
   Layout shell
   ------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--shell-side) minmax(0, 1fr);
  min-height: 100vh;
}

.main {
  padding: 32px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

/* Sidebar */
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 12px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--line);
}
.side-brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--bg);
  display: grid; place-items: center;
  font-weight: 900;
}

.side-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-hi);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.side-user-main {
  min-width: 0;
  flex: 1;
}
.side-user-nick {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-user-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 12px 0 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  position: relative;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.side-link:hover {
  background: var(--surface-hi);
  color: var(--text);
  text-decoration: none;
}
.side-link.is-active {
  background: var(--surface-hi);
  color: var(--primary);
  font-weight: 600;
}
.side-link.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--primary);
  border-radius: 2px;
}
.side-link svg {
  width: 20px; height: 20px;
  flex: 0 0 auto;
  color: currentColor;
}
.side-link-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  background: var(--error);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  min-width: 20px;
  text-align: center;
}

.side-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Topbar (mobile only) */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  align-items: center;
  gap: 12px;
}
.topbar-brand {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 16px;
}
.topbar-spacer { flex: 1; }
.btn-menu {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.btn-menu:hover { background: var(--surface-hi); }

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
}
.app.drawer-open .scrim { display: block; }

/* -------------------------------------------------------------------------
   Page header
   ------------------------------------------------------------------------- */
.page-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 {
  font-size: 26px;
  margin-right: auto;
}
.page-head .page-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section-title {
  font-family: var(--font-head);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
  font-weight: 700;
}

/* -------------------------------------------------------------------------
   Grids & stacks
   ------------------------------------------------------------------------- */
.page {
  display: block;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

/* -------------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.card-title {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 700;
  margin-right: auto;
}

/* Stat */
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-value {
  font-family: var(--font-head);
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}
.stat-sub {
  color: var(--muted);
  font-size: 13px;
}
.stat-accent {
  border-color: var(--line-primary);
}

/* -------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border-color: var(--line-primary);
}
.btn-ghost:hover { background: var(--surface-hi); border-color: var(--primary); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: rgba(255, 23, 68, 0.45);
}
.btn-danger:hover { background: rgba(255, 23, 68, 0.10); border-color: var(--error); }

.btn-sm {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13px;
}

.btn-icon {
  width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
}
.btn-icon:hover {
  background: var(--surface-hi);
  color: var(--text);
}

/* -------------------------------------------------------------------------
   Form fields
   ------------------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.field .hint {
  font-size: 12px;
  color: var(--muted);
}
.field .error-text {
  font-size: 12px;
  color: var(--error);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.4;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.textarea {
  min-height: 110px;
  resize: vertical;
  font-family: var(--font-body);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--gray);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--line-primary);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 22px,
    calc(100% - 13px) 22px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--error);
}

/* Switch (toggle) */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
  color: var(--text);
  font-weight: 500;
}
.switch input[type="checkbox"] {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}
.switch input + span {
  flex: none;
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background: var(--surface-hi);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.switch input + span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.switch input:checked + span {
  background: rgba(0, 229, 255, 0.20);
  border-color: var(--primary);
}
.switch input:checked + span::after {
  transform: translateX(20px);
  background: var(--primary);
}
.switch input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

/* Segmented control */
.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
  flex-wrap: wrap;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  min-height: 36px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.seg button:hover {
  color: var(--text);
}
.seg button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--bg);
}

/* -------------------------------------------------------------------------
   Chips
   ------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background: var(--surface-hi);
  color: var(--text);
  border: 1px solid var(--line);
}
.chip-success { background: rgba(0, 230, 118, 0.12); color: var(--success); border-color: rgba(0, 230, 118, 0.35); }
.chip-error   { background: rgba(255, 23, 68, 0.12); color: var(--error); border-color: rgba(255, 23, 68, 0.35); }
.chip-info    { background: rgba(41, 121, 255, 0.12); color: var(--info); border-color: rgba(41, 121, 255, 0.35); }
.chip-warn    { background: rgba(255, 193, 7, 0.12); color: var(--warning); border-color: rgba(255, 193, 7, 0.35); }

/* -------------------------------------------------------------------------
   Tables & lists
   ------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th,
.table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table thead th {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-hi);
}
.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-main {
  flex: 1;
  min-width: 0;
  font-weight: 600;
}
.list-sub {
  color: var(--muted);
  font-size: 13px;
}

.rank-num {
  display: inline-grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--surface-hi);
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  flex: 0 0 auto;
}
.rank-num.rank-1 { background: rgba(0, 229, 255, 0.12); color: var(--primary); }
.rank-num.rank-2 { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.rank-num.rank-3 { background: rgba(255, 193, 7, 0.14); color: var(--warning); }

/* Progress bar */
.bar {
  display: block;
  width: 100%;
  height: 6px;
  background: var(--surface-hi);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: var(--radius-pill);
  transition: width 0.2s ease;
}

/* -------------------------------------------------------------------------
   Avatar
   ------------------------------------------------------------------------- */
.avatar {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface-hi);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid var(--line);
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }

/* Swatch (territory colour dot) */
.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 4px;
  background: var(--c, var(--muted));
  border: 1px solid rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

/* -------------------------------------------------------------------------
   Badges (achievements)
   ------------------------------------------------------------------------- */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.badge {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}
.badge-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--surface-hi);
  color: var(--primary);
  display: grid; place-items: center;
  margin-bottom: 4px;
}
.badge-icon svg {
  width: 28px; height: 28px;
  color: currentColor;
}
.badge-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}
.badge-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.badge.is-locked {
  opacity: 0.55;
}
.badge.is-locked .badge-icon {
  background: var(--surface);
  color: var(--muted);
}
.badge.is-locked .bar {
  margin-top: 4px;
}

/* -------------------------------------------------------------------------
   Skeleton
   ------------------------------------------------------------------------- */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skeleton-line {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--surface-hi) 0%,
    rgba(255, 255, 255, 0.06) 50%,
    var(--surface-hi) 100%
  );
  background-size: 200% 100%;
  animation: rr-shimmer 1.6s ease-in-out infinite;
}
.skeleton-line.is-short  { width: 30%; }
.skeleton-line.is-medium { width: 60%; }
.skeleton-line.is-long   { width: 90%; }
@keyframes rr-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* -------------------------------------------------------------------------
   Empty & error states
   ------------------------------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px 20px;
  gap: 8px;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty h3 {
  color: var(--text);
  font-size: 16px;
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  gap: 12px;
  background: rgba(255, 23, 68, 0.06);
  border: 1px solid rgba(255, 23, 68, 0.35);
  border-radius: var(--radius);
  color: var(--text);
}
.error-state p {
  color: var(--muted);
}

/* -------------------------------------------------------------------------
   Toasts
   ------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--error); }
.toast-info    { border-left-color: var(--info); }

/* -------------------------------------------------------------------------
   Modal
   ------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 {
  font-size: 18px;
}
.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* -------------------------------------------------------------------------
   Map
   ------------------------------------------------------------------------- */
.map-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}

.map-filters {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 20px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.map-box {
  position: relative;
  min-height: 480px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}
.map-box .leaflet-container {
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
}

/* Leaflet dark theme polish */
.leaflet-bar {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
  box-shadow: none !important;
}
.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--line) !important;
}
.leaflet-bar a:hover {
  background: var(--surface-hi) !important;
}
.leaflet-bar a:last-child { border-bottom: 0 !important; }

.leaflet-control-attribution {
  background: rgba(22, 42, 45, 0.85) !important;
  color: var(--muted) !important;
  font-size: 11px !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
}
.leaflet-control-attribution a {
  color: var(--primary) !important;
}
.leaflet-control-zoom a {
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 18px !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--card) !important;
  color: var(--text) !important;
  border: 1px solid var(--line);
}
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm) !important;
}
.leaflet-popup-content {
  margin: 12px 14px !important;
  color: var(--text) !important;
  font-family: var(--font-body);
}
.leaflet-popup-tip {
  border: 1px solid var(--line);
}
.leaflet-popup-close-button {
  color: var(--muted) !important;
}

/* -------------------------------------------------------------------------
   Auth page
   ------------------------------------------------------------------------- */
.auth-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

.auth-brand {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background-image:
    linear-gradient(rgba(15, 33, 35, 0.86), rgba(15, 33, 35, 0.94)),
    url("../img/hero-mapa.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: var(--text);
}
.auth-brand-inner {
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.auth-brand h1 {
  font-family: var(--font-head);
  font-weight: 900;
  font-size: clamp(32px, 4.5vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.5px;
}
.auth-brand h1 .accent { color: var(--primary); }
.auth-brand p {
  color: var(--muted);
  font-size: 16px;
  max-width: 440px;
}
.auth-brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 18px;
}
.auth-brand-mark .side-brand-mark {
  width: 32px; height: 32px;
  font-size: 16px;
}

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.auth-card h2 {
  font-size: 22px;
}
.auth-card .muted {
  font-size: 14px;
}

.auth-tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}
.auth-tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  min-height: 40px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.auth-tabs button:hover { color: var(--text); }
.auth-tabs button[aria-selected="true"] {
  background: var(--primary);
  color: var(--bg);
}

.btn-google {
  background: #ffffff;
  color: #202124;
  border: 1px solid var(--line);
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.btn-google:hover { background: #f1f3f4; }
.btn-google .g-icon {
  width: 20px; height: 20px;
}

.divider-or {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.divider-or::before,
.divider-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  text-decoration: underline;
  padding: 0;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover { color: var(--primary-dark); }

.auth-error {
  background: rgba(255, 23, 68, 0.10);
  border: 1px solid rgba(255, 23, 68, 0.45);
  color: var(--error);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
}

.auth-info {
  background: rgba(0, 230, 118, 0.08);
  border: 1px solid rgba(0, 230, 118, 0.40);
  color: var(--success);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
}

.auth-foot {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.auth-foot a { color: var(--primary); }

/* -------------------------------------------------------------------------
   Reduced motion
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton-line {
    animation: none;
    background: var(--surface-hi);
  }
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  /* Shell collapses to a topbar + drawer */
  .app {
    grid-template-columns: 1fr;
  }
  .topbar { display: flex; }

  .side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    border-right: 1px solid var(--line);
  }
  .app.drawer-open .side {
    transform: translateX(0);
  }

  .main {
    padding: 20px 16px calc(20px + var(--safe-bottom));
  }

  /* Auth collapses to single column */
  .auth-page {
    grid-template-columns: 1fr;
  }
  .auth-brand {
    padding: 32px 24px;
    min-height: 240px;
  }

  /* Map stacks */
  .map-layout {
    grid-template-columns: 1fr;
  }
  .map-filters {
    position: static;
  }
}

@media (max-width: 700px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .page-head h1 {
    font-size: 22px;
  }

  .card,
  .stat {
    padding: 16px;
  }

  .map-box {
    min-height: 60vh;
    min-height: max(360px, 60vh);
  }
}

/* Ensure no horizontal page scroll at 375px */
html, body {
  overflow-x: hidden;
}
/* -------------------------------------------------------------------------
   Reconciliation: classes used by templates/scripts (generated separately)
   ------------------------------------------------------------------------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* auth page */
.auth-brand-logo { display: inline-flex; align-items: center; gap: 12px; color: var(--primary); text-decoration: none; margin-bottom: 8px; }
.auth-brand-mark { color: var(--primary); }
.auth-brand-name { font: 800 18px/1 var(--font-head); letter-spacing: .12em; color: var(--text); }
.auth-brand-body { display: flex; flex-direction: column; gap: 20px; }
.auth-brand-title { font: 900 clamp(34px, 4.6vw, 56px)/1.05 var(--font-head); letter-spacing: -.01em; }
.auth-brand-text { color: #CFE6E9; font-size: 17px; max-width: 460px; }
.auth-brand-list { display: grid; gap: 10px; color: var(--muted); list-style: none; padding: 0; margin: 0; }
.auth-brand-list li { position: relative; padding-left: 26px; }
.auth-brand-list li::before { content: ""; position: absolute; left: 0; top: .55em; width: 12px; height: 2px; background: var(--primary); }
.auth-card-head { display: grid; gap: 6px; }
.auth-card-h { font: 800 24px/1.2 var(--font-head); }
.auth-card-sub { color: var(--muted); font-size: 15px; }
.auth-form { display: grid; gap: 16px; }
.auth-body { min-height: 100vh; }
.form-help { color: var(--muted); font-size: 13px; }
.btn-google-icon { flex: none; }
.seg-btn { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px 14px; min-height: 40px; border-radius: 999px; font: 600 15px/1 var(--font-body); cursor: pointer; }
.seg-btn[aria-selected="true"], .seg-btn[aria-pressed="true"] { background: var(--primary); color: var(--bg); }
@media (max-width: 900px) {
  .auth-brand-body, .auth-brand-list, .auth-brand-text { display: none; }
  .auth-brand { padding: 20px 20px 0; min-height: 0; }
  .auth-brand-inner { gap: 0; }
}

/* shell */
.view { min-width: 0; }
.topbar-title { font: 800 18px/1 var(--font-head); margin: 0; outline: none; }
.side-brand-text { font: 800 18px/1 var(--font-head); letter-spacing: .12em; }
.side-user-card { display: flex; gap: 12px; align-items: center; }
.side-user-avatar { flex: none; }
.side-user-info { min-width: 0; display: grid; gap: 2px; }
.side-user-email, .side-user-area { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-link-quiet { color: var(--muted); }
.side-logout { width: 100%; text-align: left; }

/* ui helpers */
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar-letter { display: grid; place-items: center; width: 100%; height: 100%; font: 700 1em/1 var(--font-head); }
.empty-title, .error-title, .modal-title { font: 700 18px/1.3 var(--font-head); margin: 0; }
.empty-text { color: var(--muted); }
.modal-body { color: #CFE6E9; margin: 8px 0 20px; }
.skeleton-list-row { height: 64px; border-radius: 14px; }

/* views */
.list-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface-hi); }
.list-right { flex: none; color: var(--muted); }
.row-self { background: rgba(0, 229, 255, .10); }
.seg-wrap { overflow-x: auto; }
.page-friends .seg { flex-wrap: wrap; }
.swatch-btn { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatch-btn[aria-checked="true"] { outline: 2px solid var(--primary); outline-offset: 3px; }
.bars rect, .bar-rect { fill: var(--primary); }
.bar-val, .x-labels text, .grid-labels text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }

.switch input + span ~ span { flex: 1; min-width: 0; line-height: 1.35; }
/* Map tiles: free OSM tiles are light, so they are inverted into a dark basemap */
.rr-tiles-dark { filter: invert(1) hue-rotate(180deg) saturate(.55) brightness(.82) contrast(.92); }
.leaflet-container { background: #0F2123; }
/* the global svg{max-width:100%} reset must not squash Leaflet's custom-pane renderers */
.leaflet-container svg, .leaflet-pane svg, .leaflet-container img { max-width: none !important; max-height: none !important; }
@media (max-width: 1180px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-layout > .map-box { order: -1; }
}
.seg { border-radius: 22px; }
