:root {
  --color-primary: #0f7a3c;
  --color-primary-dark: #09562a;
  --color-primary-light: #e6f4ec;
  --color-accent: #e8a020;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-muted: #6b7280;
  --color-border: #d1d5db;
  --color-danger: #dc2626;
  --shadow-card: 0 2px 12px rgba(15, 122, 60, 0.10);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body,
main,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--color-text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--color-primary-light);
}

button,
select,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

#header {
  position: fixed;
  z-index: 500;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 1fr 44px 44px;
  gap: 8px;
  pointer-events: none;
}

#header > * {
  pointer-events: auto;
}

.select-wrap,
.icon-btn,
#view-toggle {
  border: 1px solid rgba(15, 122, 60, 0.16);
  box-shadow: var(--shadow-card);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.select-wrap {
  height: 44px;
  border-radius: var(--radius);
  padding: 0 10px;
}

#city-select {
  width: 100%;
  height: 100%;
  border: 0;
  color: var(--color-text);
  font-weight: 700;
  background: transparent;
  outline: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
  color: var(--color-primary-dark);
  font-size: 22px;
  font-weight: 700;
}

#map {
  min-height: 100dvh;
}

.drawer {
  position: fixed;
  z-index: 510;
  right: 0;
  bottom: 0;
  left: 0;
  height: 42dvh;
  min-height: 260px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -14px 36px rgba(17, 24, 39, 0.18);
  background: var(--color-surface);
  transition: height 180ms ease;
  will-change: height;
}

.drawer.expanded {
  height: 86dvh;
}

.drawer.dragging {
  transition: none;
}

#drawer-handle {
  align-self: center;
  width: 54px;
  height: 22px;
  border: 0;
  background: transparent;
  position: relative;
  touch-action: none;
}

#drawer-handle::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 5px;
  border-radius: 999px;
  background: var(--color-border);
}

#drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 0 10px;
  touch-action: none;
  user-select: none;
}

#pharmacy-count {
  display: block;
  font-size: 15px;
}

#updated-at {
  display: block;
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: 11px;
}

#view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 122px;
  padding: 3px;
  border-radius: var(--radius);
}

#view-toggle button {
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--color-text-muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

#view-toggle .active {
  color: var(--color-surface);
  background: var(--color-primary);
}

#nearest-card,
#pharmacy-list {
  overflow: auto;
}

#nearest-card {
  flex: 0 0 auto;
}

#pharmacy-list {
  min-height: 0;
  padding-bottom: 10px;
}

.pharmacy-card {
  width: 100%;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 9px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: inherit;
  text-align: left;
  background: var(--color-surface);
  box-shadow: 0 1px 7px rgba(17, 24, 39, 0.06);
}

.pharmacy-card--nearest {
  border-color: rgba(232, 160, 32, 0.62);
  background: #fff8e6;
}

.pharmacy-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--color-surface);
  background: var(--color-primary);
  font-weight: 800;
}

.pharmacy-card--nearest .pharmacy-icon {
  background: var(--color-accent);
}

.pharmacy-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 800;
}

.pharmacy-name span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  padding: 3px 5px;
  border-radius: 5px;
  color: #593700;
  background: #ffe3a3;
  font-size: 9px;
  font-weight: 800;
}

.pharmacy-meta {
  color: var(--color-text-muted);
  font-size: 12px;
}

.pharmacy-arrow {
  color: var(--color-primary);
  font-size: 20px;
  font-weight: 700;
}

.notice {
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: #374151;
  background: #f3f4f6;
  font-size: 12px;
}

.notice-action {
  min-height: 32px;
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid rgba(15, 122, 60, 0.24);
  border-radius: 7px;
  color: var(--color-primary-dark);
  background: var(--color-surface);
  font-size: 12px;
  font-weight: 800;
}

.toast {
  position: fixed;
  z-index: 700;
  top: 68px;
  left: 14px;
  right: 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: var(--color-surface);
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-card);
  font-weight: 700;
}

.toast.error {
  background: var(--color-danger);
}

.loading {
  position: fixed;
  z-index: 520;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.loading span {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(15, 122, 60, 0.16);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.marker {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-surface);
  border-radius: 50% 50% 50% 8px;
  color: var(--color-surface);
  background: var(--color-primary);
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.28);
  transform: rotate(-45deg);
  font-size: 18px;
  font-weight: 800;
}

.marker span {
  transform: rotate(45deg);
}

.marker--nearest {
  background: var(--color-accent);
}

.user-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-surface);
  border-radius: 50%;
  background: #2563eb;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.42);
}

.user-marker::before {
  content: "";
  position: absolute;
  inset: -9px;
  border: 2px solid rgba(37, 99, 235, 0.32);
  border-radius: 50%;
  animation: pulse-location 1.8s ease-out infinite;
}

.user-marker span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-surface);
}

.modal {
  position: fixed;
  z-index: 800;
  inset: 0;
}

#modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(17, 24, 39, 0.48);
}

#modal-content {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  max-height: min(560px, 84dvh);
  overflow: auto;
  padding: 18px;
  border-radius: 12px;
  background: var(--color-surface);
  box-shadow: 0 22px 58px rgba(17, 24, 39, 0.26);
}

#modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  box-shadow: none;
  background: #f3f4f6;
}

#modal-name {
  margin: 8px 48px 4px 0;
  font-size: 22px;
}

#modal-region,
#modal-address,
#modal-note,
#modal-distance {
  margin: 9px 0;
  line-height: 1.45;
}

#modal-region,
#modal-note,
#modal-distance {
  color: var(--color-text-muted);
}

.call-btn,
#modal-map-btns a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: var(--radius);
  color: var(--color-surface);
  text-decoration: none;
  font-weight: 800;
}

.call-btn {
  width: 100%;
  margin: 8px 0;
  background: var(--color-danger);
}

#modal-map-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

#modal-map-btns a {
  background: var(--color-primary);
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse-location {
  0% {
    transform: scale(0.7);
    opacity: 0.9;
  }

  100% {
    transform: scale(1.45);
    opacity: 0;
  }
}

@media (min-width: 768px) {
  #header {
    right: auto;
    left: 378px;
    width: min(420px, calc(100vw - 404px));
  }

  .drawer {
    top: 0;
    right: auto;
    width: 360px;
    height: 100dvh;
    max-height: none;
    min-height: 0;
    border-radius: 0;
    padding: 16px;
    height: 100dvh !important;
  }

  #drawer-handle {
    display: none;
  }

  #map {
    margin-left: 360px;
    width: calc(100% - 360px);
  }

  #modal-content {
    top: 50%;
    bottom: auto;
    left: 50%;
    width: min(440px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
  }

  .toast {
    left: 376px;
    right: auto;
    width: 360px;
  }
}
