/* ===== Design Tokens ===== */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Light theme palette */
  --bg-primary: #f5f7fa;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-glass-hover: rgba(255, 255, 255, 0.92);
  --border-glass: rgba(0, 0, 0, 0.08);
  --border-glass-hover: rgba(0, 0, 0, 0.15);

  --text-primary: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;

  /* Status colours */
  --status-to-visit: #9ca3af;
  --status-visited: #22c55e;
  --status-priority: #ef4444;
  --status-needs-photo: #eab308;

  /* Accents */
  --accent: #3b82f6;
  --accent-hover: #2563eb;

  /* Spacing & radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-glass: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Generic utility */
.hidden {
  display: none !important;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ===== Map ===== */
#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ===== Floating Header ===== */
#app-header {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  transition: var(--transition);
}

#app-header:hover {
  border-color: var(--border-glass-hover);
}

#app-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ===== Mode Toggle ===== */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--text-muted);
  border-radius: 12px;
  transition: var(--transition);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.mode-toggle input:checked ~ .toggle-slider {
  background: var(--accent);
}

.mode-toggle input:checked ~ .toggle-slider::after {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 32px;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 72px;
  right: 12px;
  width: 340px;
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  z-index: 90;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  transition: transform var(--transition), opacity var(--transition);
}

.sidebar.hidden {
  transform: translateX(380px);
  opacity: 0;
  pointer-events: none;
}

.sidebar-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1;
  z-index: 1;
}

.sidebar-close:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

/* Sidebar content styles */
.tower-photo {
  width: 100%;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  object-fit: contain;
  max-height: none;
  transition: height 0.3s ease;
}

.tower-name {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.tower-coords {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
  margin-bottom: 10px;
}

.tower-comments {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
}

.tower-no-photo {
  width: 100%;
  height: 140px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 14px;
  border: 1px dashed var(--border-glass-hover);
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.status-badge.to_visit { background: var(--status-to-visit); color: #fff; }
.status-badge.visited { background: var(--status-visited); color: #fff; }
.status-badge.priority { background: var(--status-priority); color: #fff; }
.status-badge.needs_photo { background: var(--status-needs-photo); color: #422006; }

/* ===== Edit Form ===== */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group select,
.form-group textarea {
  background: #fff;
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.88rem;
  padding: 9px 12px;
  transition: border-color var(--transition);
  outline: none;
}

.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.form-group textarea {
  resize: vertical;
  min-height: 72px;
}

.autosave-hint {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  margin-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  color: var(--status-priority);
  border: 1px solid rgba(239, 68, 68, 0.25);
  width: 100%;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: var(--status-priority);
  color: #fff;
}

.btn-danger-confirm {
  background: var(--status-priority) !important;
  color: #fff !important;
  border-color: var(--status-priority) !important;
  animation: pulse-danger 0.6s ease-in-out infinite alternate;
}

@keyframes pulse-danger {
  from { opacity: 0.85; }
  to { opacity: 1; }
}

/* ===== Undo/Redo Buttons ===== */
.undo-redo-container {
  position: fixed;
  bottom: 230px;
  left: 12px;
  z-index: 95;
  display: flex;
  gap: 4px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-glass);
  padding: 4px;
  transition: opacity var(--transition);
}

.undo-redo-container.hidden {
  display: none;
}

.undo-redo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.undo-redo-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.06);
  border-color: var(--border-glass-hover);
}

.undo-redo-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ===== Photo Inbox Panel ===== */
.inbox-panel {
  position: fixed;
  bottom: 12px;
  left: 12px;
  right: 12px;
  z-index: 90;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 14px 18px;
  transition: transform var(--transition), opacity var(--transition);
  max-height: 200px;
  overflow-y: auto;
}

.inbox-panel.hidden {
  transform: translateY(240px);
  opacity: 0;
  pointer-events: none;
}

.inbox-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.inbox-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.inbox-thumb {
  height: 72px;
  width: auto;
  border-radius: var(--radius-sm);
  object-fit: contain;
  cursor: grab;
  border: 2px solid transparent;
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.inbox-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.inbox-thumb.dragging {
  opacity: 0.4;
}

.inbox-empty {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ===== No-Location Badge on Inbox Thumbnails ===== */
.inbox-thumb-wrap {
  position: relative;
  display: inline-block;
  cursor: grab;
}

.inbox-thumb-wrap.dragging .inbox-thumb {
  opacity: 0.4;
}

.no-location-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  pointer-events: none;
}

.no-location-badge svg {
  width: 12px;
  height: 12px;
  color: #fff;
}

/* ===== Header Voronoi Toggle Button ===== */
.header-voronoi-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.header-voronoi-btn:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
}

.header-voronoi-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== Header Export Button ===== */
.header-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.header-export-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.header-export-btn.hidden {
  display: none;
}

/* ===== New Tower Button ===== */
.new-tower-btn {
  position: fixed;
  top: 72px;
  left: 12px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glass);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: grab;
  transition: var(--transition);
}

.new-tower-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.new-tower-btn:active {
  cursor: grabbing;
}

.new-tower-btn.hidden {
  display: none;
}

/* ===== Photo Container & Unlink Button ===== */
.photo-container {
  position: relative;
  margin-bottom: 14px;
}

.photo-container .tower-photo {
  margin-bottom: 0;
}

.unlink-photo-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: var(--transition);
}

.unlink-photo-btn:hover {
  background: var(--status-priority);
}

/* Drop zone highlight */
.photo-drop-zone,
.tower-no-photo {
  transition: var(--transition);
}

.drop-highlight {
  border-color: var(--accent) !important;
  border-style: solid !important;
  background: rgba(59, 130, 246, 0.08) !important;
}

/* ===== Photo Preview Modal ===== */
.photo-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-preview-modal.hidden {
  display: none;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.preview-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 80vw;
  height: 80vh;
}

.preview-image-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80vw;
  height: 72vh;
  flex-shrink: 0;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  object-fit: contain;
  box-shadow: var(--shadow-lg);
}

.preview-coords-overlay {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1;
}

.preview-coords-overlay.hidden {
  display: none;
}

.preview-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 600px; /* sensible limit so they don't stretch too crazy on big screens */
}

.preview-actions .btn {
  flex: 1; /* Make all buttons exactly the same width */
  text-align: center;
}

#preview-delete-btn {
  background: var(--status-priority);
  color: #fff;
  border-color: var(--status-priority);
  width: auto;
}

#preview-delete-btn:hover {
  background: #dc2626; /* darker red */
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-primary);
  border: 1px solid var(--border-glass-hover);
}

.btn-secondary:hover {
  background: #fff;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ===== Trash Float Button & Modal ===== */
.trash-float-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass-hover);
  border-radius: 50%;
  color: var(--status-priority);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 90;
  transition: var(--transition);
}

.trash-float-btn:hover {
  background: var(--status-priority);
  color: #fff;
  transform: scale(1.05);
}

.trash-float-btn.hidden {
  display: none !important;
}

.trash-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trash-modal.hidden {
  display: none !important;
}

.trash-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.trash-panel {
  position: relative;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 80vw;
  max-width: 800px;
  height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.trash-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-glass-hover);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trash-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.trash-close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.trash-close-btn:hover {
  background: var(--border-glass-hover);
  color: var(--text-primary);
}

.trash-grid {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-content: flex-start;
}

.trash-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

/* reused thumb class inside trash */
.trash-grid .inbox-thumb {
  width: 120px;
  height: 120px;
  object-fit: contain;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    width: calc(100vw - 24px);
    right: 12px;
    left: 12px;
  }

  #app-title {
    font-size: 0.95rem;
  }

  .inbox-panel {
    max-height: 150px;
  }

  .undo-redo-container {
    bottom: 180px;
  }

  .inbox-thumb {
    width: 56px;
    height: 56px;
  }
}

/* ===== Login Modal ===== */
.login-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-modal.hidden {
  display: none;
}

.login-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.login-panel {
  position: relative;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 340px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-panel h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
}

.login-panel input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.login-panel input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.login-error {
  color: var(--status-priority);
  font-size: 0.85rem;
  text-align: center;
  margin: 0;
}

.login-actions {
  display: flex;
  gap: 10px;
}

.login-actions .btn {
  flex: 1;
  text-align: center;
}
