:root {
  color-scheme: light;
  --bg-a: #f4efe7;
  --bg-b: #d6ebff;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: rgba(255, 255, 255, 0.96);
  --line: rgba(20, 32, 51, 0.12);
  --line-strong: rgba(20, 32, 51, 0.18);
  --ink: #142033;
  --muted: #5b6f87;
  --accent: #0d6f69;
  --accent-strong: #0a524d;
  --accent-soft: #e2f4f1;
  --warm: #ef7f4d;
  --warm-strong: #d75b2b;
  --shadow: 0 18px 42px rgba(20, 32, 51, 0.18);
  --radius-xl: 1.5rem;
  --radius-lg: 1.2rem;
  --radius-md: 0.95rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  font-family: Aptos, "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(239, 127, 77, 0.22), transparent 34%),
    radial-gradient(circle at right center, rgba(13, 111, 105, 0.18), transparent 36%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

[hidden],
.is-hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
}

.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(20, 32, 51, 0.16), transparent 20%, transparent 72%, rgba(20, 32, 51, 0.22)),
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 28%);
}

.map-canvas {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(160deg, rgba(13, 111, 105, 0.18), rgba(239, 127, 77, 0.16)),
    linear-gradient(180deg, #f6efe6, #ceddf0);
}

.map-canvas.is-placeholder::after {
  content: "No se pudo cargar Mapbox. Revisa tu token o tu conexion.";
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  padding: 0.95rem 1rem;
  border-radius: 1rem;
  background: rgba(20, 32, 51, 0.82);
  color: #fff;
  text-align: center;
  line-height: 1.4;
}

.topbar,
.status-chip,
.drawer,
.toast {
  z-index: 2;
}

.topbar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.8rem);
  left: 0.8rem;
  right: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.brand-chip {
  min-width: 0;
  padding: 0.75rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(242, 248, 255, 0.82));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.brand-chip h1,
.drawer-header h2 {
  margin: 0;
  line-height: 1.1;
}

.brand-chip h1 {
  font-size: 1rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.icon-btn,
.tab-btn,
.btn {
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    opacity 0.18s ease,
    box-shadow 0.18s ease;
}

.icon-btn:hover,
.tab-btn:hover,
.btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active,
.tab-btn:active,
.btn:active {
  transform: translateY(0);
}

.icon-btn:disabled,
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.icon-btn {
  min-height: 2.65rem;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 252, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.icon-btn--accent {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.icon-btn--ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  box-shadow: none;
}

.status-chip {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.status-chip.is-hidden-by-drawer {
  pointer-events: none;
}

.drawer {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0.8rem);
  width: min(96vw, 30rem);
  max-height: min(58dvh, 35rem);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 0.9rem;
  padding: 0.8rem;
  transform: translate(-50%, calc(100% + 1rem));
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(244, 248, 252, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.drawer.is-open {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.drawer-handle {
  width: 3rem;
  height: 0.3rem;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(20, 32, 51, 0.16);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.drawer-header h2 {
  font-size: 1.05rem;
}

.drawer-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.tab-btn {
  min-height: 2.8rem;
  padding: 0.7rem 0.85rem;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(20, 32, 51, 0.06);
  font-weight: 700;
  min-width: 0;
}

.tab-btn.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 10px 20px rgba(13, 111, 105, 0.22);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  min-height: 1.65rem;
  margin-left: 0.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.78rem;
}

.drawer-panel {
  display: grid;
  align-content: start;
  gap: 0.9rem;
  min-height: 0;
  overflow: auto;
  padding-bottom: 0.2rem;
  overscroll-behavior: contain;
}

.panel-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0;
}

.coordinate-card {
  padding: 0.8rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.coordinate-card dt {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.coordinate-card dd {
  margin: 0.3rem 0 0;
  font-size: 1rem;
  font-weight: 700;
}

.point-form {
  display: grid;
  gap: 0.8rem;
  margin-top: 0;
}

.field {
  display: grid;
  gap: 0.42rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.field span {
  color: var(--muted);
}

.field input {
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 0.9rem;
  border-radius: 1rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field input:focus {
  border-color: rgba(13, 111, 105, 0.45);
  box-shadow: 0 0 0 4px rgba(13, 111, 105, 0.1);
}

.field input:disabled {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

.action-row,
.saved-point__actions,
.saved-toolbar {
  display: grid;
  gap: 0.65rem;
}

.action-row,
.saved-point__actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.saved-toolbar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin-bottom: 0.9rem;
}

.btn {
  min-height: 2.85rem;
  padding: 0.72rem 1rem;
  border-radius: 999px;
  font-weight: 700;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 10px 20px rgba(13, 111, 105, 0.24);
}

.btn-ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
}

.btn-small {
  min-height: 2.55rem;
  padding: 0.6rem 0.9rem;
}

.saved-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.saved-point {
  display: grid;
  gap: 0.8rem;
  padding: 0.85rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 252, 0.88));
}

.saved-point__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  flex-wrap: wrap;
}

.saved-point__title {
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.saved-point__stamp,
.saved-point__coords {
  color: var(--muted);
  font-size: 0.88rem;
}

.saved-point__coords {
  display: grid;
  gap: 0.2rem;
}

.saved-point__tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.9rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.saved-points__empty {
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--line-strong);
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0.25rem);
  min-width: min(88vw, 19rem);
  max-width: min(88vw, 24rem);
  padding: 0.82rem 1rem;
  transform: translate(-50%, 1rem);
  border-radius: 999px;
  background: rgba(20, 32, 51, 0.88);
  color: #fff;
  text-align: center;
  box-shadow: 0 16px 30px rgba(20, 32, 51, 0.26);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.mapboxgl-ctrl-top-right {
  top: calc(env(safe-area-inset-top, 0px) + 0.85rem);
  right: 0.85rem;
}

.mapboxgl-ctrl-group {
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(20, 32, 51, 0.2);
}

.mapboxgl-popup-content {
  border-radius: 1rem;
  padding: 0.85rem 0.9rem;
  font-family: Aptos, "Trebuchet MS", "Segoe UI", sans-serif;
}

.popup-card {
  display: grid;
  gap: 0.35rem;
  min-width: 12rem;
}

.popup-card strong {
  font-size: 1rem;
  line-height: 1.2;
}

.popup-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.popup-eyebrow {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .drawer {
    width: calc(100vw - 1rem);
    max-height: min(56dvh, 34rem);
  }

  .mapboxgl-ctrl-top-right {
    top: calc(env(safe-area-inset-top, 0px) + 9.6rem);
    right: 0.75rem;
  }
}

@media (max-width: 640px) {
  .topbar {
    top: calc(env(safe-area-inset-top, 0px) + 0.65rem);
    left: 0.65rem;
    right: 0.65rem;
    gap: 0.55rem;
  }

  .brand-chip {
    width: 100%;
    padding: 0.7rem 0.9rem;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .icon-btn {
    min-height: 2.55rem;
    padding: 0.62rem 0.72rem;
    font-size: 0.88rem;
    text-align: center;
    white-space: normal;
    line-height: 1.15;
  }

  .drawer {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
    padding: 0.75rem;
    max-height: min(60dvh, 34rem);
  }

  .drawer-header h2 {
    font-size: 1rem;
  }

  .topbar-actions > .icon-btn:last-child {
    grid-column: 1 / -1;
  }

  .panel-copy,
  .saved-point__coords,
  .saved-point__stamp {
    font-size: 0.84rem;
  }

  .coordinate-grid,
  .action-row,
  .saved-point__actions,
  .saved-toolbar {
    grid-template-columns: 1fr;
  }

  .mapboxgl-ctrl-top-right {
    top: calc(env(safe-area-inset-top, 0px) + 9rem);
    right: 0.65rem;
  }
}

@media (max-width: 480px) {
  .drawer {
    width: calc(100vw - 0.75rem);
    padding: 0.7rem;
    gap: 0.75rem;
    max-height: min(62dvh, 35rem);
  }

  .drawer-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }

  .drawer-tabs {
    grid-template-columns: 1fr;
  }

  .tab-btn {
    min-height: 2.65rem;
    padding: 0.65rem 0.8rem;
  }

  .saved-point {
    gap: 0.7rem;
    padding: 0.8rem;
  }

  .saved-point__header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .saved-point__tag {
    align-self: flex-start;
  }
}

@media (max-width: 640px) and (max-height: 760px) {
  .drawer {
    max-height: min(52dvh, 28rem);
  }

  .mapboxgl-ctrl-top-right {
    top: calc(env(safe-area-inset-top, 0px) + 8.5rem);
  }
}

@media (min-width: 1024px) {
  .topbar {
    left: 1rem;
    right: auto;
  }

  .drawer {
    left: auto;
    right: 1rem;
    transform: translate(0, calc(100% + 1rem));
    width: min(28rem, calc(100vw - 2rem));
  }

  .drawer.is-open {
    transform: translate(0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
