/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4A90D9;
  --primary-dark: #357ABD;
  --danger: #E74C3C;
  --success: #27AE60;
  --warning: #F39C12;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #e1e8ed;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --toolbar-height: 56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

/* ===== Toolbar ===== */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  padding: 0 16px;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.toolbar-actions {
  display: flex;
  gap: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tool-btn:hover {
  background: #edf2f7;
  color: var(--text);
}

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

.tool-btn svg {
  flex-shrink: 0;
}

/* ===== Map ===== */
#map {
  flex: 1;
  z-index: 1;
}

.cursor-crosshair {
  cursor: crosshair !important;
}

/* ===== Custom Marker ===== */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.custom-marker .marker-inner {
  transform: rotate(45deg);
  color: white;
  font-size: 16px;
  line-height: 1;
}

.marker-scenic { background: #E74C3C; }
.marker-food { background: #F39C12; }
.marker-hotel { background: #9B59B6; }
.marker-transport { background: #3498DB; }
.marker-shopping { background: #1ABC9C; }
.marker-other { background: #95A5A6; }

/* ===== Panels ===== */
.panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 75vh;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
  z-index: 1001;
  transform: translateY(0);
  transition: transform 0.3s ease, opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel.hidden {
  transform: translateY(100%);
  pointer-events: none;
  opacity: 0;
}

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

.panel-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #edf2f7;
  color: var(--text-light);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.close-btn:hover {
  background: #e2e8f0;
  color: var(--text);
}

.panel-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

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

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

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.form-group input[type="file"] {
  padding: 8px 0;
  font-size: 13px;
}

/* ===== Star Rating ===== */
.star-rating {
  display: flex;
  gap: 4px;
}

.star-rating span {
  font-size: 28px;
  color: #ddd;
  cursor: pointer;
  transition: color 0.15s;
}

.star-rating span.active,
.star-rating span:hover {
  color: var(--warning);
}

/* ===== Photo Grid ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

/* ===== Buttons ===== */
.panel-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
}

.primary-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.danger-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  background: var(--danger);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.danger-btn:hover {
  opacity: 0.85;
}

.hidden {
  display: none !important;
}

/* ===== Spot List ===== */
.spot-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.spot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.spot-item:hover {
  background: #e8edf2;
}

.spot-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  flex-shrink: 0;
}

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

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

.spot-info p {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spot-stars {
  color: var(--warning);
  font-size: 12px;
}

.spot-distance {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}

/* ===== Route Panel ===== */
.route-hint {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
}

.route-stops {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 16px;
}

.route-stop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  position: relative;
}

.route-stop:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 15px;
  top: 38px;
  bottom: -10px;
  width: 2px;
  background: var(--primary);
  opacity: 0.3;
}

.route-stop-number {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.route-stop-name {
  flex: 1;
  font-size: 14px;
}

.route-stop-remove {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-light);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.route-stop-remove:hover {
  background: #fee;
  color: var(--danger);
}

.route-summary {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
}

.summary-item .label {
  font-size: 13px;
  color: var(--text-light);
}

.summary-item .value {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: rgba(44, 62, 80, 0.92);
  color: white;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 2000;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ===== Leaflet Popup Override ===== */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
}

.popup-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

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

.popup-desc {
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 6px;
}

.popup-rating {
  color: var(--warning);
}

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

.popup-actions button {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}

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

.popup-actions .route-btn {
  background: var(--success);
  color: white;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .tool-btn span {
    display: none;
  }

  .tool-btn {
    padding: 8px 10px;
  }

  #toolbar {
    padding: 0 8px;
  }
}
