/* ========================================
   移动端优化样式 (配合 Tailwind CSS)
   ======================================== */

/* 移动端检测 */
@media (max-width: 768px) {
  
  /* 整体布局改为垂直 */
  #app {
    flex-direction: column;
    position: relative;
  }

  /* 地图全屏显示 */
  .map-container {
    width: 100% !important;
    height: 100vh !important;
    position: relative;
    z-index: 1 !important;
  }

  /* 地图缩放控件位置调整 - 使用安全区域 */
  .leaflet-control-zoom {
    position: fixed !important;
    top: calc(env(safe-area-inset-top, 0px) + 60px) !important;
    right: 12px !important;
    z-index: 1500 !important;
  }

  .leaflet-control-zoom-in,
  .leaflet-control-zoom-out {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }

  /* 侧边栏改为底部抽屉 */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    height: auto;
    max-height: 75vh;
    border-right: none;
    border-top: 1px solid var(--border-color);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    transform: translateY(calc(100% - 120px));
    transition: transform 0.3s ease;
    z-index: 2000 !important;
  }

  .sidebar.expanded {
    transform: translateY(0);
  }

  /* 侧边栏头部 */
  .sidebar-header {
    padding: 4px 12px 8px;
    user-select: none;
    position: relative;
  }

  /* 三角形切换按钮 */
  .sidebar-toggle {
    padding: 6px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-bottom: 4px;
  }
  
  .sidebar-toggle:active {
    background-color: rgba(0, 0, 0, 0.03);
  }
  
  .toggle-arrow {
    display: inline-block;
  }
  
  .sidebar.expanded .toggle-arrow {
    transform: rotate(180deg);
  }

  /* 侧边栏内容 */
  .sidebar-content {
    max-height: calc(75vh - 100px);
    overflow-y: auto;
    padding: 8px 12px;
    gap: 8px;
  }

  /* 卡片紧凑化 */
  .card {
    padding: 8px 10px;
    margin-bottom: 8px;
  }

  /* 侧边栏底部 */
  .sidebar-footer {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-color);
  }
}

/* ========================================
   移动端特有组件
   ======================================== */

/* 快速操作按钮组 */
.mobile-fab-group {
  display: none;
  position: fixed;
  right: 12px;
  bottom: 140px;
  z-index: 1500;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 768px) {
  .mobile-fab-group {
    display: flex;
  }
}

.mobile-fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.mobile-fab:active {
  transform: scale(0.95);
}

.mobile-fab.secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.mobile-fab.danger {
  background: var(--danger);
}

/* ========================================
   触摸优化
   ======================================== */

@media (max-width: 768px) {
  button:active,
  .btn:active {
    opacity: 0.7;
  }

  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* ========================================
   短屏幕优化 (高度 < 700px)
   ======================================== */

@media (max-height: 700px) and (max-width: 768px) {
  .sidebar {
    max-height: 65vh;
    transform: translateY(calc(100% - 100px));
  }

  .sidebar-content {
    max-height: calc(65vh - 90px);
    padding: 6px 10px;
    gap: 6px;
  }

  .card {
    padding: 6px 8px;
    margin-bottom: 6px;
  }

  .mobile-fab-group {
    bottom: 120px;
  }

  .mobile-fab {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
}

/* ========================================
   横屏优化
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    max-height: 55vh;
    transform: translateY(calc(100% - 80px));
  }

  .sidebar-content {
    max-height: calc(55vh - 70px);
  }

  .mobile-fab-group {
    bottom: 100px;
    right: 8px;
  }
}

/* ========================================
   安全区域适配 (iPhone X+)
   ======================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .sidebar {
      padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-fab-group {
      bottom: calc(140px + env(safe-area-inset-bottom));
    }

    .map-search-container {
      top: calc(env(safe-area-inset-top) + 8px) !important;
    }
  }
}

/* ========================================
   十字准星标记模式 - 精简美观版
   ======================================== */

.mobile-crosshair {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
}

@media (max-width: 768px) {
  .mobile-crosshair {
    display: block;
  }
}

/* 简洁的十字线 */
.crosshair-vertical {
  position: absolute;
  left: 50%;
  top: -16px;
  width: 1.5px;
  height: 32px;
  background: linear-gradient(to bottom, 
    transparent 0%, 
    rgba(239, 68, 68, 0.9) 25%, 
    transparent 45%,
    transparent 55%,
    rgba(239, 68, 68, 0.9) 75%, 
    transparent 100%
  );
  transform: translateX(-50%);
}

.crosshair-horizontal {
  position: absolute;
  top: 50%;
  left: -16px;
  width: 32px;
  height: 1.5px;
  background: linear-gradient(to right, 
    transparent 0%, 
    rgba(239, 68, 68, 0.9) 25%, 
    transparent 45%,
    transparent 55%,
    rgba(239, 68, 68, 0.9) 75%, 
    transparent 100%
  );
  transform: translateY(-50%);
}

/* 中心点 - 小巧精致 */
.crosshair-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border: 1.5px solid #ef4444;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
}

/* 隐藏坐标显示，保持简洁 */
.crosshair-coords {
  display: none;
}

/* 添加点时的动画反馈 */
.mobile-crosshair.point-added .crosshair-center {
  animation: crosshair-pulse 0.25s ease-out;
}

.mobile-crosshair.point-added .crosshair-vertical,
.mobile-crosshair.point-added .crosshair-horizontal {
  animation: crosshair-flash 0.25s ease-out;
}

@keyframes crosshair-pulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    border-color: #ef4444;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.8);
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.3);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    border-color: #ef4444;
    background: transparent;
  }
}

@keyframes crosshair-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* 添加点按钮特殊样式 */
.mobile-fab.add-point {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.mobile-fab.add-point:active {
  background: #15803d;
}

/* 危险操作按钮 */
.mobile-fab.danger {
  background: #ef4444;
}

.mobile-fab.danger:active {
  background: #dc2626;
}

/* ========================================
   桌面端隐藏移动端组件
   ======================================== */

@media (min-width: 769px) {
  .sidebar-toggle {
    display: none !important;
  }

  .mobile-fab-group {
    display: none !important;
  }
  
  .mobile-crosshair {
    display: none !important;
  }
  
  .mobile-add-point-btn {
    display: none !important;
  }
}
