:root {
  --bg: #0c1222;
  --bg2: #141d33;
  --panel: rgba(12, 18, 34, 0.94);
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #94a3b8;
  --text-light: #e2e8f0;
  --blue: #3b82f6;
  --blue2: #2563eb;
  --green: #22c55e;
  --green2: #16a34a;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --panel-w: 420px;
  --mobile-nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-light);
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #dbeafe;
}

.app-shell {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* Panel */
.panel {
  pointer-events: auto;
  position: fixed;
  top: 12px;
  left: 12px;
  width: var(--panel-w);
  max-height: calc(100vh - 24px);
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 20;
}

.panel.collapsed {
  transform: translateX(calc(-100% - 24px));
  opacity: 0;
  pointer-events: none;
}

.panel-inner {
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

.userbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-ghost {
  background: transparent;
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-warning {
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 10px;
}

.done-btn {
  width: 100%;
  margin-top: 10px;
  background: linear-gradient(135deg, var(--green), var(--green2));
  color: white;
}

.undone-btn {
  width: 100%;
  margin-top: 10px;
  background: #e2e8f0;
  color: var(--text);
}

/* Notice */
.notice {
  display: none;
  padding: 12px;
  border-radius: 14px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fde68a;
  font-size: 13px;
  line-height: 1.4;
}

.notice.active { display: block; }

.notice-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 14px;
}

.tab {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

/* Search & filters */
.searchbox {
  position: relative;
}

.searchbox svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.searchbox input,
.field select,
.login-card input {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.07);
  color: white;
  border-radius: 14px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.searchbox input { padding-left: 42px; }

.searchbox input:focus,
.field select:focus,
.login-card input:focus {
  border-color: rgba(59, 130, 246, 0.5);
}

.field select option { color: #111; }

.filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.stat span {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-done strong { color: #86efac; }
.stat-pending strong { color: #fca5a5; }

.progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #86efac);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* Next peak suggestion */
.next-peak {
  display: none;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(34, 197, 94, 0.1));
  border: 1px solid rgba(59, 130, 246, 0.25);
  cursor: pointer;
  transition: transform 0.15s;
}

.next-peak.visible { display: block; }
.next-peak:hover { transform: translateY(-1px); }

.next-peak-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #93c5fd;
  margin-bottom: 4px;
}

.next-peak-name {
  font-size: 15px;
  font-weight: 800;
  color: white;
}

.next-peak-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* List */
.list-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
}

.results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 32vh;
  overflow: auto;
  scrollbar-width: thin;
}

.item {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

.item.done {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.25);
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.item h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: white;
  line-height: 1.25;
}

.done-tag {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.25);
  color: #86efac;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--text-muted);
}

.chip-date { color: #86efac; }

.empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
}

.empty-state svg {
  opacity: 0.4;
  margin-bottom: 8px;
}

.load-more { width: 100%; }

/* Stats dashboard */
.stats-dashboard {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat-card {
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}

.bar-row:last-child { margin-bottom: 0; }

.bar-label {
  flex: 0 0 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-light);
}

.bar-track {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.bar-value {
  flex: 0 0 42px;
  text-align: right;
  font-weight: 800;
  font-size: 11px;
  color: var(--text-muted);
}

.altitude-bands {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.alt-band {
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
}

.alt-band strong {
  display: block;
  font-size: 18px;
  font-weight: 800;
}

.alt-band span {
  font-size: 10px;
  color: var(--text-muted);
}

/* Tools */
.tools-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tools-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0;
}

/* Mobile nav */
.mobile-nav {
  display: none;
  pointer-events: auto;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--mobile-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(12, 18, 34, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 40;
}

.mobile-nav-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.15s;
}

.mobile-nav-btn.active { color: var(--green); }

/* Login */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, #1e293b, var(--bg));
}

.login-overlay.active { display: flex; }

.login-card {
  width: min(400px, 100%);
  padding: 28px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}

.login-brand h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.login-brand p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.login-card label {
  display: block;
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-card .btn { width: 100%; margin-top: 16px; }

.login-error {
  color: #fecaca;
  font-size: 13px;
  margin: 12px 0 0;
  min-height: 1.2em;
}

/* Leaflet overrides */
.leaflet-top.leaflet-right { top: 12px; }

.leaflet-popup-content-wrapper {
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 0;
  overflow: hidden;
  max-height: 85vh;
}

.leaflet-popup-content {
  margin: 0;
  width: min(380px, 88vw) !important;
  max-height: 85vh;
  overflow-y: auto;
}

.popup-card { background: white; color: var(--text); }

.popup-head {
  padding: 16px;
  background: linear-gradient(135deg, #1e293b, var(--bg));
  color: white;
}

.popup-head.done {
  background: linear-gradient(135deg, #166534, #14532d);
}

.popup-head h3 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 800;
}

.popup-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.popup-tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 11px;
  font-weight: 700;
}

.popup-body { padding: 14px 16px 16px; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.info-box {
  padding: 9px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.info-box span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  color: #64748b;
}

.info-box strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  color: var(--text);
}

.date-field {
  margin-top: 10px;
}

.date-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 4px;
}

.date-field input {
  width: 100%;
  height: 40px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0 10px;
  font-family: inherit;
}

.maps-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  margin-top: 10px;
  background: var(--blue);
  color: white !important;
  text-decoration: none;
  border-radius: 12px;
  font-weight: 800;
  font-size: 13px;
}

.routes-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
}

.routes-title {
  display: block;
  font-size: 13px;
  color: var(--text);
}

.btn-routes {
  width: 100%;
  margin-top: 10px;
  min-height: 44px;
  background: linear-gradient(135deg, #ea580c, #f97316);
  color: white;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.btn-routes:hover {
  filter: brightness(1.05);
}

.routes-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.routes-hint,
.routes-empty {
  margin: 0;
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
}

.route-item {
  width: 100%;
  text-align: left;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.route-item:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.route-item-user {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.route-item-name {
  display: block;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.route-item-meta {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: #64748b;
}

.route-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.route-link {
  flex: 1;
  min-width: 70px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e2e8f0;
  color: #0f172a !important;
  text-decoration: none;
  font-size: 11px;
  font-weight: 800;
}

.route-link:hover {
  background: #cbd5e1;
}

.marker-dot {
  border-radius: 999px;
  border: 3px solid white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  background: var(--red);
}

.marker-dot.done {
  background: var(--green);
}

.marker-dot.done::after {
  content: "✓";
  color: white;
  font-size: 11px;
  font-weight: 900;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

/* Responsive: tablet */
@media (max-width: 1024px) {
  :root { --panel-w: 360px; }
}

/* Responsive: mobile */
@media (max-width: 768px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
    width: 100%;
    max-height: 58vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
  }

  .panel.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .panel.collapsed {
    transform: translateY(110%);
    opacity: 0;
  }

  .panel-inner { padding: 14px; }

  .filters-grid { grid-template-columns: 1fr; }

  .results { max-height: 22vh; }

  .mobile-nav { display: flex; }

  h1 { font-size: 18px; }

  .hero-sub { display: none; }

  .leaflet-top.leaflet-right {
    top: 8px;
    right: 4px;
  }

  body.view-panel #map,
  body.view-stats #map { filter: brightness(0.6); }

  body.view-map .panel:not(.open) {
    transform: translateY(110%);
  }
}

@media (max-width: 480px) {
  .stats-row { gap: 6px; }

  .stat strong { font-size: 18px; }

  .bar-label { flex: 0 0 80px; font-size: 11px; }

  .altitude-bands { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 769px) {
  body.view-map .panel.collapsed {
    transform: translateX(calc(-100% - 24px));
  }
}
