* {
  box-sizing: border-box;
}

:root {
  --water-deep: #0d3b4c;
  --water-mid: #1a6b7a;
  --water-light: #4db8c4;
  --sand: #e8dcc4;
  --leaf: #2d5a3d;
  --white: #f8fafb;
  --shadow: rgba(13, 59, 76, 0.15);
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--white);
  color: var(--water-deep);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, var(--water-deep) 0%, var(--water-mid) 100%);
  color: white;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 2px;
}

.tab {
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

.tab:hover {
  color: white;
}

.tab.active {
  background: white;
  color: var(--water-deep);
}

.map-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}
.map-search input {
  flex: 1;
  padding: 0.45rem 0.75rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  background: rgba(255,255,255,0.95);
  color: var(--water-deep);
}
.map-search input::placeholder {
  color: #888;
}
.map-search input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--water-light);
}
.btn-search {
  padding: 0.45rem 0.9rem;
  background: var(--water-light);
  color: var(--water-deep);
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-search:hover {
  background: #5fc9d1;
}
.map-search-msg {
  font-size: 0.8rem;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.subtitle {
  margin: 0;
  opacity: 0.9;
  font-size: 0.9rem;
  flex: 1;
  min-width: 200px;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 500;
}

.btn-add {
  background: var(--water-light);
  color: var(--water-deep);
}

.btn-add:hover {
  background: #5fc9d1;
}

.btn-pin {
  background: rgba(255,255,255,0.25);
  color: white;
  border: 1px solid rgba(255,255,255,0.5);
}
.btn-pin:hover {
  background: rgba(255,255,255,0.4);
}

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 320px;
  min-width: 280px;
  background: white;
  border-right: 1px solid #e0e8eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #e0e8eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--water-deep);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
  padding: 0 4px;
}

.btn-close:hover {
  color: var(--water-mid);
}

.spot-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 0 0 auto;
  max-height: 40%;
}

.spot-list li {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.spot-list li:hover,
.spot-list li.active {
  background: #e6f4f6;
}

.spot-list li .name {
  font-weight: 600;
  color: var(--water-deep);
}

.spot-list li .brief,
.route-list li .brief {
  font-size: 0.8rem;
  color: #666;
  margin-top: 2px;
}

.route-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  max-height: 35%;
}

.route-list li {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.route-list li:hover,
.route-list li.active {
  background: #fff5e6;
}

.route-list li .name {
  font-weight: 600;
  color: var(--water-deep);
}

.draw-hint {
  margin: 0;
  padding: 0.6rem 1rem;
  background: #fff8e6;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #8b6914;
  display: none;
}

.detail-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  border-top: 1px solid #e0e8eb;
  background: #fafcfc;
}

.detail-content {
  font-size: 0.9rem;
}

.detail-content h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--water-deep);
}

.detail-section {
  margin-bottom: 1rem;
}

.detail-section .label {
  font-weight: 600;
  color: var(--water-mid);
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.detail-section .value {
  color: #444;
  white-space: pre-wrap;
  line-height: 1.5;
}

.detail-section .value.empty {
  color: #999;
  font-style: italic;
}

.detail-actions {
  margin-top: 1rem;
}

.detail-actions a {
  display: inline-block;
  margin-right: 0.75rem;
  color: var(--water-mid);
  text-decoration: none;
  font-size: 0.9rem;
}

.detail-actions a:hover {
  text-decoration: underline;
}

.map {
  flex: 1;
  min-width: 0;
  min-height: 400px;
}

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow);
}

.leaflet-popup-content {
  margin: 0.75rem 1rem;
  min-width: 180px;
  font-size: 0.9rem;
}

.popup-title {
  font-weight: 700;
  color: var(--water-deep);
  margin-bottom: 6px;
}

.popup-meta {
  font-size: 0.8rem;
  color: #666;
}

.popup-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  max-width: 240px;
}
.popup-photos img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e0e8eb;
}
.leaflet-popup-content-wrapper.popup-spot-wrapper .leaflet-popup-content {
  min-width: 140px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 59, 76, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
  pointer-events: auto;
}
.modal[hidden] {
  display: none !important;
}

.modal-box {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box h2 {
  margin: 0;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e0e8eb;
  font-size: 1.2rem;
  color: var(--water-deep);
}

#formSpot {
  padding: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-section {
  font-weight: 600;
  color: var(--water-mid);
  font-size: 0.95rem;
  margin: 1rem 0 0.5rem;
  padding-bottom: 4px;
  border-bottom: 1px solid #e0e8eb;
}

.form-section:first-of-type {
  margin-top: 0;
}

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--water-deep);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #c5d8dc;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--water-mid);
  box-shadow: 0 0 0 2px rgba(26, 107, 122, 0.2);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-group-checkbox label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.form-group-checkbox input[type="checkbox"] {
  width: auto;
}

.route-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 500;
  margin-left: 0.5rem;
}
.route-badge-highlight {
  background: #27ae60;
  color: #fff;
}

.form-hint {
  font-size: 0.8rem;
  color: #666;
  margin: 0 0 0.5rem;
}

.spot-photos-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.spot-photo-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e0e8eb;
}
.spot-photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.spot-photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.spot-photo-remove:hover {
  background: #c00;
}
.spot-photos-in-block {
  margin-bottom: 0.75rem;
}
.spot-photos-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.spot-photos-in-block .spot-photos-detail {
  margin-top: 0.25rem;
}
.spot-photo-detail-item {
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e0e8eb;
}
.spot-photo-detail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.btn-upload-photo {
  margin-top: 0.5rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  background: var(--water-mid);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.btn-upload-photo:hover {
  background: var(--water-deep);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #e0e8eb;
}

.btn-cancel {
  background: #e8eef0;
  color: #555;
}

.btn-cancel:hover {
  background: #dce4e6;
}

.btn-save {
  background: var(--water-mid);
  color: white;
}

.btn-save:hover {
  background: var(--water-deep);
}

.custom-marker .marker-pin {
  font-size: 24px;
  display: block;
  text-align: center;
  line-height: 1;
}

.route-marker .route-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: white;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.route-marker .route-pin.start {
  background: #27ae60;
}

.route-marker .route-pin.end {
  background: #e74c3c;
}

.detail-content .hint {
  color: #888;
  font-style: italic;
  margin: 0;
}

.btn-edit-inline {
  background: none;
  border: none;
  color: var(--water-mid);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.btn-edit-inline:hover {
  text-decoration: underline;
}

.detail-block {
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: white;
  border-radius: 8px;
  border: 1px solid #e0e8eb;
}

.detail-block-title {
  font-weight: 600;
  color: var(--water-deep);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.btn-delete-inline {
  background: none;
  border: none;
  color: #c44;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  margin-left: 0.5rem;
}

.btn-delete-inline:hover {
  text-decoration: underline;
}

/* 强制显示登录页：页面加载时 body 带 force-login，只有登录成功后才移除 */
body.force-login #loginScreen {
  display: flex !important;
}
body.force-login #appMain {
  display: none !important;
}

/* 登录界面 */
.login-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--water-deep) 0%, var(--water-mid) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.login-box {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px var(--shadow);
}

.login-box h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  color: var(--water-deep);
  text-align: center;
}

.login-desc {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: #666;
  text-align: center;
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem 1rem;
  border: 1px solid #c5d8dc;
  background: #f5f8f9;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: #555;
}

.auth-tab.active {
  background: var(--water-mid);
  color: white;
  border-color: var(--water-mid);
}

.auth-form .form-group:first-child {
  margin-top: 0;
}

.login-box .form-group {
  margin-bottom: 1rem;
}

.login-box .form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: var(--water-deep);
}

.login-box input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #c5d8dc;
  border-radius: 8px;
  font-size: 1rem;
}

.btn-login {
  width: 100%;
  padding: 0.65rem;
  margin-top: 0.5rem;
  background: var(--water-mid);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-login:hover {
  background: var(--water-deep);
}

.login-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #e0e8eb;
}

.login-message {
  color: #c44;
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
}

.login-tip {
  font-size: 0.8rem;
  color: #888;
  margin: 0;
  line-height: 1.4;
}

.user-info {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.95);
  margin-right: 0.5rem;
}

.btn-out {
  background: rgba(255,255,255,0.25);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}

.btn-out:hover {
  background: rgba(255,255,255,0.35);
}

.btn-admin {
  background: #e67e22;
  color: white;
}

.btn-admin:hover {
  background: #d35400;
}

/* 游客横幅 */
.visitor-banner {
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: #fff8e6;
  border-radius: 8px;
  border: 1px solid #f0e0b0;
  font-size: 0.9rem;
  color: #6b5a00;
}

.visitor-banner p {
  margin: 0 0 0.5rem;
}

.btn-apply {
  background: var(--water-mid);
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-apply:hover {
  background: var(--water-deep);
}

.btn-request-delete {
  color: #e67e22;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.btn-request-delete:hover {
  text-decoration: underline;
}

/* 管理员弹窗 */
.modal-admin .modal-box {
  max-width: 520px;
}
.modal-admin .form-actions {
  margin-top: 0.5rem;
}
.modal-admin #btnCloseAdmin {
  cursor: pointer;
  position: relative;
  z-index: 10;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
}

.admin-tab {
  padding: 0.5rem 1rem;
  border: 1px solid #e0e8eb;
  background: #f5f8f9;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.admin-tab.active {
  background: var(--water-mid);
  color: white;
  border-color: var(--water-mid);
}

.admin-list {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.admin-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem;
  border-bottom: 1px solid #e8ecee;
  font-size: 0.9rem;
}

.admin-item span:first-child {
  flex: 1;
  min-width: 120px;
}

.admin-meta {
  font-size: 0.8rem;
  color: #888;
}

.admin-user-list {
  padding: 0;
}
.admin-user-legend {
  font-size: 0.8rem;
  color: #666;
  margin: 0 0 0.5rem;
  padding: 0 0.25rem;
}
.admin-user-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e8ecee;
  font-size: 0.9rem;
}
.admin-user-item .user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.admin-user-item .user-dot-active { background: #27ae60; }
.admin-user-item .user-dot-normal { background: #f1c40f; }
.admin-user-item .user-dot-zombie { background: #e74c3c; }
.admin-user-legend .user-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 2px;
  vertical-align: middle;
}
.admin-user-legend .user-dot-active { background: #27ae60; }
.admin-user-legend .user-dot-normal { background: #f1c40f; }
.admin-user-legend .user-dot-zombie { background: #e74c3c; }
.admin-user-name {
  flex: 1;
  min-width: 80px;
}
.admin-user-count {
  color: #666;
  font-size: 0.85rem;
}
.admin-user-label {
  font-size: 0.8rem;
  color: #888;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.btn-approve {
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-reject {
  background: #e0e0e0;
  color: #555;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.empty-hint {
  color: #999;
  font-size: 0.9rem;
  margin: 0;
  padding: 1rem;
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-height: 45vh;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    border-right: none;
    border-top: 1px solid #e0e8eb;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px var(--shadow);
  }

  .spot-list {
    max-height: 120px;
  }
}
