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

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans JP',
    'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* モバイルブラウザのアドレスバー対策 */
  overflow: hidden;
}

/* Menu Toggle Button */
.menu-toggle {
  display: flex;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1001;
  width: 48px;
  height: 48px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 3px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.menu-toggle:hover {
  background: var(--bg-secondary);
}

.menu-toggle.active span:nth-child(1) {
  transform: translateY(9px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: translateY(-9px) rotate(-45deg);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 1000;
  transform: translateX(0);
}

.sidebar.closed {
  transform: translateX(-100%);
}

.sidebar-header {
  padding: 24px 24px 24px 80px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.meta-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.controls {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.control-group h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Stats */
.stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 14px;
}

.stat-item label {
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-item span {
  font-weight: 600;
  color: var(--text-primary);
}

/* Tile Selector */
.tile-selector {
  margin-top: 12px;
}

.tile-selector label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.tile-buttons {
  display: flex;
  gap: 8px;
}

.tile-button {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.tile-button:hover {
  background: var(--bg-secondary);
  border-color: var(--primary);
}

.tile-button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.tile-button:active {
  transform: scale(0.98);
}

/* Buttons */
.button {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: center;
}

.icon-button {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-button:hover {
  background: var(--primary-hover);
}

.icon-button:active {
  transform: scale(0.95);
}

.gpx-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

.button--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button--secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.button--secondary:hover:not(:disabled) {
  background: var(--bg-secondary);
}

.button--danger {
  background: var(--danger);
  color: white;
}

.button--danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Select */
.select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
}

.select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* GPX List */
.gpx-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.gpx-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 12px;
}

.gpx-item:hover {
  background: var(--bg-secondary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.gpx-item-color-indicator {
  width: 4px;
  height: 48px;
  border-radius: 2px;
  flex-shrink: 0;
}

.gpx-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  margin-right: 8px;
}

.gpx-item-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpx-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gpx-item-meta span {
  display: inline-block;
}

.gpx-item-remove {
  padding: 4px 8px;
  font-size: 12px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.gpx-item-remove:hover {
  background: var(--danger-hover);
}

/* GPX API List */
.gpx-api-list {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.gpx-api-file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.gpx-api-file-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.close-btn {
  padding: 4px 8px;
  font-size: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
}

.close-btn:hover {
  color: var(--text-primary);
}

.gpx-api-file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 500px;
  overflow-y: auto;
}

.gpx-api-file-item {
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gpx-api-file-item:hover {
  background: var(--bg-secondary);
  border-color: var(--primary);
}

.gpx-api-file-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}

.gpx-api-file-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.gpx-api-file-item-meta span {
  display: inline-block;
}

.gpx-api-file-item-date {
  font-size: 11px;
  color: var(--text-secondary);
}

.loading-text,
.no-files {
  padding: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Main */
.main {
  flex: 1;
  position: relative;
  margin-left: 320px;
  transition: margin-left 0.3s ease;
}

.main.sidebar-closed {
  margin-left: 0;
}

.map {
  width: 100%;
  height: 100%;
  background: var(--bg-tertiary);
}

/* Current Location Button */
.current-location-btn {
  position: absolute;
  bottom: 24px;
  right: 24px;
  z-index: 1001;
  width: 48px;
  height: 48px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
  color: var(--primary);
  pointer-events: auto;
}

.current-location-btn:hover {
  background: var(--bg-secondary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.current-location-btn:active {
  transform: scale(0.95);
}

.current-location-btn.tracking {
  background: var(--primary);
  color: white;
  animation: trackingPulse 2s infinite;
}

@keyframes trackingPulse {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  }
  50% {
    box-shadow: 0 2px 16px rgba(59, 130, 246, 0.6);
  }
}

/* Loading */
.loading {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  display: none;
  z-index: 1000;
}

.loading.visible {
  display: block;
}

/* Current Location Marker */
.current-location-marker {
  position: relative;
}

.current-location-marker .dot {
  width: 12px;
  height: 12px;
  background: #4285F4;
  border: 2px solid white;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.current-location-marker .pulse {
  width: 20px;
  height: 20px;
  border: 2px solid #4285F4;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2);
  }
}

/* Heading Marker */
.heading-marker {
  position: relative;
}

.heading-arrow {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

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

.leaflet-popup-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* モバイルでのタップ領域を改善 */
.leaflet-interactive {
  cursor: pointer;
  touch-action: manipulation;
}

/* ポップアップのタップを改善 */
.leaflet-popup {
  pointer-events: auto !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  pointer-events: auto !important;
}

/* 数字付きマーカーのタップ領域を改善 */
.multi-corporation-marker {
  cursor: pointer !important;
  touch-action: manipulation !important;
  pointer-events: auto !important;
}

.multi-corporation-marker > div {
  cursor: pointer !important;
  pointer-events: auto !important;
}

/* Marker cluster customization */
.marker-cluster-small {
  background-color: rgba(59, 130, 246, 0.6);
}

.marker-cluster-small div {
  background-color: rgba(59, 130, 246, 0.8);
  color: white;
  font-weight: 600;
}

.marker-cluster-medium {
  background-color: rgba(251, 146, 60, 0.6);
}

.marker-cluster-medium div {
  background-color: rgba(251, 146, 60, 0.8);
  color: white;
  font-weight: 600;
}

.marker-cluster-large {
  background-color: rgba(239, 68, 68, 0.6);
}

.marker-cluster-large div {
  background-color: rgba(239, 68, 68, 0.8);
  color: white;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 85%;
    max-width: 320px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  }

  .sidebar:not(.open) {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .sidebar-header {
    padding: 20px 16px 16px 80px;
  }

  .sidebar-header h1 {
    font-size: 16px;
  }

  .controls {
    padding: 16px;
    gap: 20px;
  }

  .control-group h2 {
    font-size: 15px;
  }

  /* Buttons with better touch targets */
  .button {
    padding: 12px 16px;
    font-size: 15px;
    min-height: 44px;
  }

  /* Stats items with better spacing */
  .stat-item {
    padding: 10px 12px;
    font-size: 15px;
  }

  /* GPX items with better touch targets */
  .gpx-item {
    padding: 10px 12px;
    font-size: 14px;
  }

  .gpx-item-remove {
    padding: 6px 12px;
    font-size: 13px;
    min-width: 60px;
  }

  .gpx-api-file-item {
    padding: 12px;
    font-size: 14px;
  }

  .gpx-api-file-item-name {
    font-size: 15px;
  }

  /* Map takes full width */
  .main {
    width: 100%;
  }

  /* Loading indicator position adjustment */
  .loading {
    top: 80px;
    right: 16px;
    left: 16px;
    text-align: center;
  }

  /* Current location button for mobile */
  .current-location-btn {
    bottom: 24px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  /* Leaflet controls positioning for mobile */
  .leaflet-bottom.leaflet-left {
    bottom: 100px; /* 現在地ボタンと重ならないように調整 */
  }
}

/* Very small screens */
@media (max-width: 480px) {
  .sidebar {
    width: 90%;
  }

  .sidebar-header h1 {
    font-size: 18px;
  }

  .meta-info {
    font-size: 12px;
  }

  .control-group h2 {
    font-size: 14px;
  }

  .button {
    font-size: 14px;
  }

  .menu-toggle {
    width: 44px;
    height: 44px;
  }
}
