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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --scenic: #22c55e;
  --culture: #a855f7;
  --food: #f97316;
  --hotel: #3b82f6;
  --shopping: #ec4899;
  --transport: #64748b;
  --other: #8b5cf6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

#header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  gap: 4px;
}

.badge {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.icon-btn.active {
  background: #eff6ff;
  color: var(--primary);
}

#map {
  flex: 1;
  z-index: 1;
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 100vw;
  height: 100%;
  background: var(--bg);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.visible {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#sidebar-search {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

#search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus {
  border-color: var(--primary);
}

#spot-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

#spot-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

#spot-list li:hover {
  background: var(--bg-secondary);
}

.spot-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.spot-info {
  flex: 1;
  min-width: 0;
}

.spot-info .name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spot-info .meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.spot-info .stars {
  color: #fbbf24;
  font-size: 12px;
  letter-spacing: 1px;
}

.spot-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

#spot-list li:hover .spot-actions {
  opacity: 1;
}

.spot-actions button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.spot-actions button:hover {
  background: var(--border);
}

.spot-actions button.delete:hover {
  color: var(--danger);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  margin-top: 12px;
  font-size: 15px;
  font-weight: 500;
}

.empty-state .hint {
  font-size: 13px;
  margin-top: 4px;
  font-weight: 400;
}

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#modal-overlay.visible .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

#spot-form {
  padding: 20px 24px 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.star-rating {
  display: flex;
  gap: 4px;
}

.star-rating .star {
  font-size: 24px;
  color: #e2e8f0;
  cursor: pointer;
  transition: color 0.15s, transform 0.15s;
  user-select: none;
}

.star-rating .star:hover,
.star-rating .star.active {
  color: #fbbf24;
}

.star-rating .star:hover {
  transform: scale(1.2);
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  gap: 8px;
}

.form-actions-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
}

.btn-danger:hover {
  background: #fef2f2;
}

/* Route info bar */
#route-info {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 24px;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#route-info.visible {
  transform: translateX(-50%) translateY(0);
}

.route-info-content {
  display: flex;
  gap: 24px;
  font-size: 14px;
  font-weight: 600;
}

#route-distance {
  color: var(--primary);
}

#route-spots {
  color: var(--text-secondary);
}

/* Toast */
#toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.5s forwards;
  max-width: 320px;
}

.toast.success {
  background: #059669;
}

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

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* Custom markers */
.custom-marker {
  width: 32px;
  height: 40px;
  position: relative;
}

.marker-pin {
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 2px solid white;
}

.marker-pin .marker-icon {
  transform: rotate(45deg);
  font-size: 14px;
  line-height: 1;
}

.marker-pin::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: inherit;
  opacity: 0.3;
}

.route-number {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Popup styles */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  min-width: 240px;
  max-width: 300px;
}

.leaflet-popup-tip {
  box-shadow: none !important;
}

.popup-content {
  padding: 16px;
}

.popup-image {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius) var(--radius) 0 0;
  display: block;
}

.popup-content h4 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.popup-category {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.popup-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.popup-stars {
  color: #fbbf24;
  font-size: 14px;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.popup-coords {
  font-size: 11px;
  color: #94a3b8;
  font-family: "SF Mono", Monaco, monospace;
}

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

.popup-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  color: var(--text);
}

.popup-btn:hover {
  background: var(--bg-secondary);
}

.popup-btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.popup-btn.primary:hover {
  background: var(--primary-dark);
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 480px) {
  #sidebar {
    width: 100vw;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 85vh;
  }

  #modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  #route-info {
    left: 16px;
    right: 16px;
    transform: translateX(0) translateY(100px);
    width: auto;
  }

  #route-info.visible {
    transform: translateX(0) translateY(0);
  }
}

/* Leaflet overrides */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-sm) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
  color: var(--text) !important;
  border: none !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-secondary) !important;
}
