/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --eh-red: #c0392b;
  --eh-red-dark: #96281b;
  --eh-cream: #f5f0e8;
  --eh-stone: #d4c5a9;
  --eh-dark: #2c2c2c;
  --eh-mid: #5a5a5a;
  --eh-light: #8a8a8a;
  --visited-green: #27ae60;
  --visited-green-light: #2ecc71;
  --unvisited-grey: #95a5a6;
  --shadow: 0 2px 8px rgba(0,0,0,0.15);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.2);
  --radius: 8px;
  --header-h: 64px;
  --progress-h: 6px;
  --filter-h: 52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--eh-cream);
  color: var(--eh-dark);
  height: 100vh;
  overflow: hidden;
}

/* ========== LOGIN ========== */
#login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1a0a00 0%, #3d1a00 40%, #6b2c00 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.login-box {
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  max-width: 380px;
  width: 90%;
}
.login-logo { margin-bottom: 16px; }
.login-logo .castle-icon { width: 72px; height: 72px; display: inline-block; }
.login-box h1 {
  font-size: 1.5rem; color: var(--eh-red); margin-bottom: 8px;
  font-weight: 700; line-height: 1.2;
}
.login-box p { color: var(--eh-mid); margin-bottom: 32px; font-size: 0.9rem; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#username-input, #password-input {
  padding: 12px 16px; border: 2px solid var(--eh-stone);
  border-radius: var(--radius); font-size: 1rem;
  transition: border-color 0.2s;
}
#username-input:focus, #password-input:focus {
  outline: none; border-color: var(--eh-red);
}
#login-form button {
  padding: 12px; background: var(--eh-red); color: white;
  border: none; border-radius: var(--radius); font-size: 1rem;
  font-weight: 600; cursor: pointer; transition: background 0.2s;
}
#login-form button:hover { background: var(--eh-red-dark); }
.login-error { color: var(--eh-red); font-size: 0.85rem; }

/* ========== HEADER ========== */
#main-header {
  height: var(--header-h);
  background: var(--eh-red);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow);
  z-index: 100; position: relative;
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-icon { width: 32px; height: 32px; display: block; flex-shrink: 0; }
#main-header h1 { font-size: 1.1rem; font-weight: 700; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#progress-summary { font-size: 0.75rem; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coll-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.coll-sep { margin: 0 6px; opacity: 0.5; }
.header-right { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
#user-toggle {
  background: rgba(255,255,255,0.15); color: white; border: 2px solid rgba(255,255,255,0.4);
  border-radius: var(--radius); padding: 6px 8px; font-size: 0.8rem; cursor: pointer;
  max-width: 170px;
}
#user-toggle option { color: var(--eh-dark); }

.view-btn {
  background: rgba(255,255,255,0.15); color: white;
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 6px 12px; font-size: 0.8rem; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.view-btn:hover { background: rgba(255,255,255,0.25); }
.view-btn.active { background: white; color: var(--eh-red); border-color: white; font-weight: 600; }
.admin-btn {
  background: rgba(0,0,0,0.2); color: white; border: none;
  border-radius: var(--radius); padding: 6px 10px; cursor: pointer;
  font-size: 0.85rem; transition: background 0.2s;
}
.admin-btn:hover { background: rgba(0,0,0,0.35); }

/* ========== PROGRESS BAR ========== */
#progress-bar-container {
  height: var(--progress-h);
  background: #d4b8b8;
  position: relative; overflow: hidden;
}
#progress-bar {
  height: 100%; background: var(--visited-green);
  transition: width 0.8s ease;
  width: 0%;
}
#progress-text {
  position: absolute; right: 8px; top: -18px;
  font-size: 0.7rem; color: var(--eh-mid);
}

/* ========== FILTER BAR ========== */
#filter-bar {
  height: var(--filter-h);
  background: white;
  border-bottom: 1px solid var(--eh-stone);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; overflow-x: auto;
  flex-shrink: 0;
}
#filter-bar::-webkit-scrollbar { height: 0; }
.filter-group { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.filter-group label { font-size: 0.8rem; color: var(--eh-mid); font-weight: 500; }
.filter-group select, #search-input {
  padding: 5px 8px; border: 1px solid var(--eh-stone);
  border-radius: 6px; font-size: 0.8rem; background: white;
}
.filter-group select:focus, #search-input:focus {
  outline: none; border-color: var(--eh-red);
}
.search-group { flex: 1; min-width: 140px; max-width: 260px; }
#search-input { width: 100%; }
#filter-newly-added { accent-color: var(--eh-red); }

/* ========== MAP ========== */
#map-view {
  position: relative;
  height: calc(100vh - var(--header-h) - var(--progress-h) - var(--filter-h));
}
#map { width: 100%; height: 100%; }
#map-legend {
  position: absolute; bottom: 24px; left: 12px; z-index: 500;
  background: white; border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.2);
}
.legend-dot.visited { background: var(--visited-green); }
.legend-dot.unvisited { background: var(--unvisited-grey); }
.legend-dot.no-coords { background: #bdc3c7; }

/* Custom map markers */
.map-marker {
  width: 28px; height: 28px; border-radius: 50%;
  background: white;
  border: 2px solid rgba(0,0,0,0.12);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.1s;
}
.map-marker:hover { transform: scale(1.3); }
.map-marker img { width: 18px; height: 18px; display: block; }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
}
.map-popup { min-width: 180px; }
.map-popup h3 { font-size: 0.95rem; margin-bottom: 4px; color: var(--eh-dark); }
.map-popup .popup-type { font-size: 0.75rem; color: var(--eh-light); margin-bottom: 8px; }
.map-popup .popup-county { font-size: 0.75rem; color: var(--eh-mid); }
.map-popup .popup-visited {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 0.75rem; font-weight: 600; margin-top: 6px;
}
.map-popup .popup-visited.yes { background: #d5f5e3; color: #1e8449; }
.map-popup .popup-visited.no { background: #eaecee; color: #717d7e; }
.map-popup .popup-date { font-size: 0.75rem; color: var(--eh-mid); margin-top: 4px; }
.map-popup .popup-btn {
  display: block; margin-top: 10px; padding: 6px 12px;
  background: var(--eh-red); color: white; border: none;
  border-radius: 6px; font-size: 0.8rem; cursor: pointer;
  text-align: center; width: 100%;
}
.map-popup .popup-btn:hover { background: var(--eh-red-dark); }

/* ========== LIST VIEW ========== */
#list-view {
  height: calc(100vh - var(--header-h) - var(--progress-h) - var(--filter-h));
  overflow-y: auto; padding: 12px;
}
#sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  max-width: 1400px; margin: 0 auto;
}
.site-card {
  background: white; border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--unvisited-grey);
  position: relative;
}
.site-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.site-card.visited { border-left-color: var(--visited-green); }
.site-card.new-this-month::after {
  content: 'NEW';
  position: absolute; top: 8px; right: 8px;
  background: var(--eh-red); color: white;
  font-size: 0.6rem; font-weight: 700; padding: 2px 6px;
  border-radius: 10px; letter-spacing: 0.5px;
}
.card-body { padding: 14px 16px; }
.card-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.card-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.card-type { font-size: 0.7rem; background: var(--eh-cream); color: var(--eh-mid); padding: 2px 7px; border-radius: 10px; }
.card-county { font-size: 0.72rem; color: var(--eh-light); }
.card-status {
  font-size: 0.75rem; font-weight: 600; padding: 3px 10px;
  border-radius: 12px; display: inline-block;
}
.card-status.visited { background: #d5f5e3; color: #1e8449; }
.card-status.unvisited { background: #eaecee; color: #717d7e; }
.card-date { font-size: 0.72rem; color: var(--eh-light); margin-top: 4px; }

/* ========== TODO VIEW ========== */
#todo-view {
  height: calc(100vh - var(--header-h) - var(--progress-h) - var(--filter-h));
  overflow-y: auto; padding: 16px;
}
#todo-container { max-width: 900px; margin: 0 auto; }
.todo-header { margin-bottom: 20px; }
.todo-header h2 { font-size: 1.3rem; color: var(--eh-dark); }
.todo-subtitle { font-size: 0.85rem; color: var(--eh-mid); margin-top: 4px; }
.todo-categories { display: flex; flex-direction: column; gap: 20px; }
.todo-cat { background: white; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.todo-cat h3 { font-size: 1rem; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.cat-desc { font-size: 0.8rem; color: var(--eh-light); margin-bottom: 12px; }
.badge {
  font-size: 0.7rem; font-weight: 700; padding: 2px 8px;
  border-radius: 10px; color: white;
}
.badge.red { background: #e74c3c; }
.badge.orange { background: #e67e22; }
.badge.green { background: var(--visited-green); }

.todo-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--eh-cream);
  cursor: pointer;
}
.todo-item:last-child { border-bottom: none; }
.todo-item:hover { background: var(--eh-cream); margin: 0 -16px; padding: 10px 16px; border-radius: 6px; }
.todo-item-name { font-size: 0.9rem; font-weight: 500; }
.todo-item-meta { font-size: 0.75rem; color: var(--eh-mid); margin-top: 2px; }
.todo-opening { font-size: 0.75rem; color: #e67e22; margin-top: 3px; font-style: italic; }
.todo-opening.hard { color: #e74c3c; }

/* ========== SIDE PANEL ========== */
.side-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(420px, 100vw);
  background: white; z-index: 1000;
  box-shadow: -4px 0 20px rgba(0,0,0,0.2);
  overflow-y: auto;
  transition: transform 0.3s ease;
  transform: translateX(100%);
}
.side-panel.open { transform: translateX(0); }
.side-panel.hidden { display: none; }
#panel-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.15);
  z-index: 999; transition: opacity 0.3s;
}
#panel-overlay.hidden { display: none; }
.panel-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--eh-cream); border: none; border-radius: 50%;
  width: 32px; height: 32px; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.panel-close:hover { background: var(--eh-stone); }
#panel-content { padding: 20px; }

.panel-photo-hero {
  margin: -20px -20px 0; aspect-ratio: 1 / 1;
  overflow: hidden; background: var(--eh-cream);
}
.panel-photo-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.other-photos h3 { color: var(--eh-mid); }

/* Photo lightbox gallery */
.lightbox {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
}
.lightbox .lb-img { max-width: 88vw; max-height: 88vh; object-fit: contain; border-radius: 8px; }
.lightbox .lb-btn {
  position: absolute; background: rgba(255,255,255,0.15); color: #fff;
  border: none; cursor: pointer; border-radius: 50%;
  width: 48px; height: 48px; font-size: 1.8rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.lightbox .lb-btn:hover { background: rgba(255,255,255,0.3); }
.lightbox .lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox .lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lightbox .lb-close { top: 16px; right: 16px; width: 40px; height: 40px; font-size: 1.2rem; }
.lightbox .lb-counter {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 0.9rem; background: rgba(0,0,0,0.4);
  padding: 4px 12px; border-radius: 12px;
}
@media (max-width: 640px) {
  .lightbox .lb-prev { left: 6px; }
  .lightbox .lb-next { right: 6px; }
}
.panel-hero {
  background: linear-gradient(135deg, var(--eh-red), var(--eh-red-dark));
  color: white; padding: 24px 20px 20px;
  margin: -20px -20px 20px;
}
.panel-hero h2 { font-size: 1.2rem; line-height: 1.3; margin-bottom: 8px; }
.panel-hero-meta { font-size: 0.8rem; opacity: 0.85; display: flex; gap: 12px; flex-wrap: wrap; }
.panel-status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 20px; font-size: 0.85rem; font-weight: 600;
  margin-top: 12px;
}
.panel-status-badge.visited { background: white; color: var(--visited-green); }
.panel-status-badge.unvisited { background: rgba(255,255,255,0.2); color: white; }

.panel-section { margin-bottom: 18px; }
.panel-section h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--eh-light); margin-bottom: 8px; }
.panel-section p { font-size: 0.9rem; line-height: 1.6; color: var(--eh-dark); }

.opening-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px; font-size: 0.8rem;
}
.opening-badge.hard { background: #fde8e8; color: #c0392b; }
.opening-badge.seasonal { background: #fef3cd; color: #856404; }
.opening-badge.regular { background: #d5f5e3; color: #1e8449; }

.panel-links { display: flex; flex-direction: column; gap: 8px; }
.panel-link {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--eh-cream); text-decoration: none;
  color: var(--eh-dark); font-size: 0.85rem; transition: background 0.2s;
}
.panel-link:hover { background: var(--eh-stone); }
.panel-link span { font-size: 1rem; }

.photo-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  margin-top: 8px;
}
.photo-thumb {
  aspect-ratio: 1; border-radius: 6px;
  object-fit: cover; width: 100%; cursor: pointer;
  transition: opacity 0.2s;
}
.photo-thumb:hover { opacity: 0.85; }
.no-photos { font-size: 0.85rem; color: var(--eh-light); font-style: italic; }

/* ========== MODAL ========== */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.25);
}
.modal.hidden { display: none; }
.modal-content {
  background: white; border-radius: 12px;
  width: min(520px, 95vw); max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--eh-cream);
  position: sticky; top: 0; background: white; z-index: 1;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none; border: none; font-size: 1.2rem; cursor: pointer;
  color: var(--eh-mid); padding: 4px 8px;
}
.modal-close:hover { color: var(--eh-red); }

#admin-panel { padding: 20px 24px; }
.admin-note { font-size: 0.85rem; color: var(--eh-mid); margin-bottom: 12px; }
#admin-search {
  width: 100%; padding: 10px 12px; border: 1px solid var(--eh-stone);
  border-radius: var(--radius); font-size: 0.9rem; margin-bottom: 8px;
}
#admin-search-results { max-height: 180px; overflow-y: auto; }
.admin-result-item {
  padding: 8px 12px; cursor: pointer; border-radius: 6px;
  font-size: 0.85rem; display: flex; justify-content: space-between;
  align-items: center;
}
.admin-result-item:hover { background: var(--eh-cream); }
.admin-result-county { font-size: 0.75rem; color: var(--eh-light); }
#admin-edit-form { margin-top: 16px; border-top: 1px solid var(--eh-cream); padding-top: 16px; }
#admin-site-name { font-size: 1rem; margin-bottom: 16px; color: var(--eh-red); }
.form-row {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 12px;
}
.form-row label { font-size: 0.85rem; font-weight: 500; min-width: 100px; padding-top: 4px; }
.form-row input[type="text"],
.form-row input[type="date"],
.form-row input[type="number"],
.form-row textarea {
  flex: 1; padding: 8px 10px; border: 1px solid var(--eh-stone);
  border-radius: 6px; font-size: 0.85rem; font-family: inherit;
}
.form-row input:focus, .form-row textarea:focus { outline: none; border-color: var(--eh-red); }
.form-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--eh-red); margin-top: 4px; }

/* Photo editor */
.form-row-photos { flex-direction: column; }
.photo-editor { width: 100%; }
.admin-photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.admin-photo-item { position: relative; width: 72px; height: 72px; }
.admin-photo-item img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; border: 1px solid var(--eh-stone); }
.photo-del {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: var(--eh-red); color: white;
  font-size: 0.7rem; line-height: 1; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.no-photos-inline { font-size: 0.8rem; color: var(--eh-light); }
.photo-add-btn {
  display: inline-block; padding: 8px 14px; background: var(--eh-cream);
  border: 1px dashed var(--eh-stone); border-radius: var(--radius);
  font-size: 0.85rem; cursor: pointer; color: var(--eh-mid);
}
.photo-add-btn:hover { border-color: var(--eh-red); color: var(--eh-red); }
.photo-status { font-size: 0.8rem; color: var(--eh-mid); margin-left: 10px; }

.admin-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn-primary {
  padding: 10px 20px; background: var(--eh-red); color: white;
  border: none; border-radius: var(--radius); font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.btn-primary:hover { background: var(--eh-red-dark); }
.btn-secondary {
  padding: 10px 20px; background: var(--eh-cream); color: var(--eh-dark);
  border: 1px solid var(--eh-stone); border-radius: var(--radius);
  font-size: 0.9rem; cursor: pointer; transition: background 0.2s;
}
.btn-secondary:hover { background: var(--eh-stone); }
#admin-save-status { font-size: 0.85rem; margin-top: 10px; min-height: 20px; }
#admin-save-status.success { color: var(--visited-green); }
#admin-save-status.error { color: var(--eh-red); }

/* ========== MOBILE ========== */
@media (max-width: 640px) {
  #main-header { padding: 0 10px; gap: 8px; }
  #main-header h1 { font-size: 0.9rem; }
  .header-icon { width: 26px; height: 26px; }
  .header-right { gap: 4px; }
  /* Collapse view buttons to just their icons to save width */
  .view-btn { padding: 6px 8px; font-size: 0.9rem; }
  .view-btn .btn-label { display: none; }
  .admin-btn { padding: 6px 8px; font-size: 0.9rem; }

  #filter-bar { padding: 0 8px; gap: 6px; }
  .filter-group label { display: none; }
  .search-group { min-width: 100px; }

  #sites-grid { grid-template-columns: 1fr; }

  .side-panel { width: 100vw; }

  #map-legend { bottom: 12px; font-size: 0.72rem; padding: 8px 10px; }

  .todo-cat { padding: 12px; }
}

/* ========== SCROLLBAR ========== */
#list-view::-webkit-scrollbar,
#todo-view::-webkit-scrollbar,
.side-panel::-webkit-scrollbar { width: 6px; }
#list-view::-webkit-scrollbar-track,
#todo-view::-webkit-scrollbar-track,
.side-panel::-webkit-scrollbar-track { background: transparent; }
#list-view::-webkit-scrollbar-thumb,
#todo-view::-webkit-scrollbar-thumb,
.side-panel::-webkit-scrollbar-thumb { background: var(--eh-stone); border-radius: 3px; }

/* ========== UTILITIES ========== */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
