/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif; overflow: hidden; }

/* Login screen */
.login-screen {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  z-index: 5000; display: flex; align-items: center; justify-content: center;
}
.login-screen.hidden { display: none; }
.login-card {
  background: white; border-radius: 12px; padding: 32px;
  width: 90%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.login-card h1 {
  text-align: center; color: #1a73e8; margin-bottom: 8px; font-size: 24px;
}
.login-subtitle {
  text-align: center; color: #666; margin-bottom: 24px; font-size: 14px;
}
.login-error {
  color: #dc3545; font-size: 13px; margin-bottom: 12px; display: none;
}
.login-error.show { display: block; }
.login-toggle {
  text-align: center; margin-top: 16px; font-size: 14px;
}
.login-toggle a { color: #1a73e8; text-decoration: none; }
.login-toggle a:hover { text-decoration: underline; }

/* Header buttons */
.header-buttons {
  position: fixed; top: 10px; left: 10px; right: 10px; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.header-buttons > * { pointer-events: auto; }

#map { width: 100vw; height: 100dvh; z-index: 1; position: absolute; top: 0; left: 0; }

/* Buttons */
.map-btn {
  background: #f5f5f5; border: 1px solid rgba(0,0,0,0.15); border-radius: 4px;
  padding: 8px 12px; cursor: pointer; font-size: 14px; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.map-btn:hover { background: #e8e8e8; }
.map-btn.active { background: #1a73e8; color: white; border-color: #1a73e8; }

.sidebar-toggle-btn {
  background: #f5f5f5; border: 1px solid rgba(0,0,0,0.15); border-radius: 4px;
  cursor: pointer; font-size: 20px;
  padding: 6px 10px; color: #333; flex-shrink: 0;
}

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: 0; width: 320px; height: 100vh;
  background: white; z-index: 1001; box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  transform: translateX(-100%); transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
  padding: 16px; background: #1a73e8; color: white;
  padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
  display: flex; justify-content: space-between; align-items: center;
}
.sidebar-header h2 { font-size: 16px; }
.sidebar-close { background: none; border: none; color: white; font-size: 20px; cursor: pointer; padding: 4px 8px; }
.sidebar-content { flex: 1; overflow-y: auto; padding: 16px; }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #555; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;
}
.form-group textarea { resize: vertical; min-height: 60px; }
.btn {
  padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;
  font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: #1a73e8; color: white; }
.btn-primary:hover { background: #1557b0; }
.btn-danger { background: #dc3545; color: white; }
.btn-danger:hover { background: #b02a37; }
.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #565e64; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 2000;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white; border-radius: 8px; padding: 24px;
  max-width: 450px; width: 90%; max-height: 85vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

/* Folder tree */
.folder-tree { list-style: none; padding-left: 0; }
.folder-tree ul { list-style: none; padding-left: 20px; }
.folder-item {
  padding: 6px 8px; cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; gap: 6px; font-size: 14px;
}
.folder-item:hover { background: #f0f0f0; }
.folder-item.selected { background: #e3f2fd; color: #1a73e8; }
.folder-actions { margin-left: auto; display: flex; gap: 4px; }
.folder-actions button {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  font-size: 12px; color: #999;
}
.folder-actions button:hover { color: #333; }

/* KML folder list */
.kml-folder-item {
  padding: 8px 10px; margin-bottom: 6px; border: 1px solid #eee;
  border-radius: 6px; background: #fafafa; cursor: grab;
}
.kml-folder-item[draggable="true"]:active { cursor: grabbing; }
.kml-folder-item.dragging { opacity: 0.5; }
.kml-folder-item.drag-over { border: 2px dashed #1a73e8; }

/* Folder name row - separate line above icon */
.folder-name-row {
  font-size: 13px; font-weight: 600; color: #333;
  padding-bottom: 4px; margin-bottom: 4px; border-bottom: 1px solid #eee;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.folder-icon { color: #f0ad4e; font-size: 18px; }

.kml-folder-header {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.kml-folder-header .toggle-icon { transition: transform 0.2s; font-size: 10px; color: #666; }
.kml-folder-header.expanded .toggle-icon { transform: rotate(90deg); }
.kml-folder-actions { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }

.folder-badges { display: flex; gap: 2px; flex-wrap: wrap; }
.folder-count { font-size: 11px; color: #999; }
.kml-folder-files { padding-left: 20px; margin-top: 6px; display: none; }
.kml-folder-files.open { display: block; }
.kml-file-item {
  padding: 4px 8px; font-size: 13px; display: flex; align-items: center; gap: 6px;
  border-radius: 4px;
}
.kml-file-item:hover { background: #f0f0f0; }
.kml-file-name {
  flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kml-file-name:hover { color: #1a73e8; text-decoration: underline; }
.kml-file-actions { display: flex; gap: 2px; }

/* Icon buttons */
.icon-btn {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  font-size: 12px; color: #999; border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: #e0e0e0; color: #333; }
.icon-btn.active { color: #1a73e8; }
.icon-btn.delete:hover { background: #fbe9eb; color: #dc3545; }

/* Pin list - pins inside folders */
.pin-folder-section {
  margin-bottom: 12px; padding: 8px; border: 1px solid #eee;
  border-radius: 6px; background: #fafafa;
}
.pin-folder-section[draggable="true"] { cursor: grab; }
.pin-folder-section[draggable="true"]:active { cursor: grabbing; }
.pin-folder-section.dragging { opacity: 0.5; }
.pin-folder-section.drag-over { border: 2px dashed #1a73e8; }

.pin-folder-header {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.pin-folder-header .toggle-icon { transition: transform 0.2s; font-size: 10px; color: #666; }
.pin-folder-header.expanded .toggle-icon { transform: rotate(90deg); }
.pin-folder-content { padding-left: 12px; display: none; margin-top: 8px; }
.pin-folder-content.open { display: block; }

.pin-item {
  padding: 10px; margin-bottom: 8px; border: 1px solid #eee;
  border-radius: 6px;
}
.pin-item:hover { border-color: #1a73e8; }
.pin-item-header { cursor: pointer; }
.pin-item h4 { font-size: 14px; margin-bottom: 4px; }
.pin-item p { font-size: 12px; color: #666; }
.pin-item .pin-meta { font-size: 11px; color: #999; display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* Pin detail images */
.pin-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pin-images img {
  width: 80px; height: 80px; object-fit: cover; border-radius: 4px;
  cursor: pointer; border: 1px solid #ddd;
}
.pin-images img:hover { border-color: #1a73e8; }

/* Image lightbox */
.lightbox {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9); z-index: 3000;
  display: none; align-items: center; justify-content: center;
}
.lightbox.active { display: flex; }
.lightbox img { max-width: 90%; max-height: 90%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 20px; right: 20px;
  color: white; font-size: 30px; cursor: pointer; background: none; border: none;
}

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid #eee; margin-bottom: 12px; }
.tab {
  padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -2px; color: #666;
}
.tab.active { color: #1a73e8; border-bottom-color: #1a73e8; }

/* Visibility badge */
.badge {
  display: inline-block; padding: 2px 6px; border-radius: 10px;
  font-size: 10px; font-weight: 600;
}
.badge-public { background: #d4edda; color: #155724; }
.badge-private { background: #f8d7da; color: #721c24; }
.badge-shared { background: #cce5ff; color: #004085; }

/* User info */
.user-info { padding: 12px; background: #f8f9fa; border-radius: 6px; margin-bottom: 12px; }
.user-info span { font-weight: 600; }

/* KML info */
.kml-info {
  padding: 10px; background: #fff3cd; border-radius: 6px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; font-size: 13px;
}

/* Checkbox style */
.checkbox-label {
  display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px;
}
.checkbox-label input { width: 16px; height: 16px; }

/* Toggle switch */
.toggle-switch {
  position: relative; width: 40px; height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc; transition: 0.3s; border-radius: 22px;
}
.toggle-slider:before {
  position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
  background-color: white; transition: 0.3s; border-radius: 50%;
}
.toggle-switch input:checked + .toggle-slider { background-color: #1a73e8; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* Delete image btn */
.img-wrapper { position: relative; display: inline-block; }
.img-delete {
  position: absolute; top: -6px; right: -6px;
  background: #dc3545; color: white; border: none; border-radius: 50%;
  width: 20px; height: 20px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Section divider */
.section-title {
  font-size: 12px; font-weight: 700; color: #999; text-transform: uppercase;
  letter-spacing: 1px; margin: 16px 0 8px;
}

/* Notification */
.notification {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 6px; z-index: 3000;
  font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: opacity 0.3s;
}
.notification-success { background: #d4edda; color: #155724; }
.notification-error { background: #f8d7da; color: #721c24; }

/* Pin mode: make ALL map layers click-through */
.pin-mode-active .leaflet-overlay-pane,
.pin-mode-active .leaflet-overlay-pane *,
.pin-mode-active .leaflet-marker-pane,
.pin-mode-active .leaflet-marker-pane * {
  pointer-events: none !important;
}

/* Sharing modal - user selection */
.user-select-list { max-height: 200px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px; }
.user-select-item {
  padding: 8px 12px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid #eee; cursor: pointer;
}
.user-select-item:last-child { border-bottom: none; }
.user-select-item:hover { background: #f5f5f5; }
.user-select-item.selected { background: #e3f2fd; }
.user-select-item input { width: 16px; height: 16px; }

/* Preview images during pin creation */
.image-preview-container {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
}
.image-preview {
  width: 60px; height: 60px; object-fit: cover; border-radius: 4px;
  border: 1px solid #ddd;
}

/* Reorder list */
.reorder-list {
  max-height: 300px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px;
}
.reorder-item {
  padding: 10px 12px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #eee; background: white;
}
.reorder-item:last-child { border-bottom: none; }
.reorder-item span { font-weight: 500; }
.reorder-buttons { display: flex; gap: 4px; }
.reorder-buttons .icon-btn {
  padding: 4px 8px; font-size: 12px;
}

/* Admin panel */
.admin-btn {
  position: relative;
}
.notification-badge {
  position: absolute; top: -5px; right: -5px;
  background: #dc3545; color: white; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.pending-user-item {
  padding: 12px; border-bottom: 1px solid #eee;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.pending-user-item:last-child { border-bottom: none; }
.pending-user-info {
  display: flex; flex-direction: column; gap: 2px;
}
.pending-user-actions {
  display: flex; gap: 6px; flex-shrink: 0;
}

/* Admin tabs */
.admin-tabs {
  display: flex; border-bottom: 1px solid #ddd; margin-bottom: 16px;
}
.admin-tabs .tab {
  padding: 10px 20px; cursor: pointer; border: none; background: none;
  font-size: 14px; color: #666; border-bottom: 2px solid transparent;
}
.admin-tabs .tab.active {
  color: #2196f3; border-bottom-color: #2196f3;
}
.admin-tabs .tab:hover { color: #1976d2; }

/* Security logs */
.security-log-filter {
  margin-bottom: 12px;
}
.security-log-filter select {
  padding: 6px 10px; border: 1px solid #ddd; border-radius: 4px;
  font-size: 14px;
}
.security-log-list {
  max-height: 400px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px;
}
.security-log-item {
  padding: 10px 12px; border-bottom: 1px solid #eee; font-size: 13px;
}
.security-log-item:last-child { border-bottom: none; }
.security-log-item:hover { background: #f9f9f9; }

/* Responsive */
@media (max-width: 600px) {
  .sidebar { width: 100%; }
  .map-btn { font-size: 13px; padding: 6px 8px; }
}
