:root {
  /* Brand & semantic */
  --bg: #f4f6f8;
  --bg-elevated: #ffffff;
  --fg: #1a2026;
  --muted: #6b7480;
  --muted-2: #9aa3ad;
  --accent: #0f9d8c;
  --accent-dark: #0b7a6d;
  --accent-soft: #e2f2ef;
  --danger: #e11d3a;
  --danger-soft: #fdeef0;
  --border: #e3e6ea;
  --border-strong: #d0d5db;
  --shadow-sm: 0 1px 2px rgba(20, 26, 34, 0.06);
  --shadow-md: 0 4px 12px rgba(20, 26, 34, 0.08);
  --shadow-lg: 0 10px 30px rgba(20, 26, 34, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  /* Map */
  --pin-blue: #0f9d8c;
  --pin-amber: #f59e0b;

  /* Tags (generated) */
  --chip-bg: #eef3ff;
  --chip-fg: #2f5fb0;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.container {
  width: min(1280px, 93vw);
  margin: 0 auto;
}

.site-header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 400;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0;
  gap: 1rem;
}

.brand {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--accent-dark);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.brand .logo-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.nav a {
  color: var(--fg);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.3rem 0.1rem;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.nav a:hover { color: var(--accent-dark); border-color: var(--accent); }
.nav a[aria-current="page"] { color: var(--accent-dark); border-color: var(--accent-dark); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { padding: 0.35rem 0.6rem; font-size: 0.82rem; }

.site-footer {
  margin-top: 2.5rem;
  padding: 1.75rem 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 1.5rem 0;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-head h1 { font-size: 1.55rem; margin: 0; }

.muted { color: var(--muted); }
.empty { color: var(--muted); margin: 1rem 0; }

.error {
  background: var(--danger-soft);
  border: 1px solid #f5c2cb;
  color: var(--danger);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

/* Table */
.dest-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.dest-table th, .dest-table td {
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.dest-table th {
  background: #f8f9fb;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}
.dest-table tbody tr:last-child td { border-bottom: none; }
.dest-table td a { color: var(--accent-dark); font-weight: 600; }
.dest-table td a:hover { text-decoration: underline; }

.chip {
  display: inline-block;
  background: var(--chip-bg);
  color: var(--chip-fg);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  margin: 0.1rem 0.15rem 0 0;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge.on { background: #e6ffef; color: #1f8a4e; }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.fb { background: #e4f0ff; color: #1563c2; }
.badge.manual { background: #f2f2f2; color: #555; }
.badge.edited { background: #fff4e5; color: #b9721a; }

/* Detail */
.detail {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  max-width: 900px;
  margin: 1.5rem auto;
}
.detail h1 { font-size: 1.8rem; margin: 0 0 0.75rem; }

.meta {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.8rem 1.25rem;
  margin: 1.5rem 0;
}
.meta dt { color: var(--muted); font-weight: 700; }
.meta dd { margin: 0; }

.coords { color: var(--muted); font-size: 0.9rem; margin-top: 0.5rem; }

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}
.actions-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.summary {
  background: #eafbe4;
  border: 1px solid #bfe8bf;
  color: #1c5021;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}

.original-panel {
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}
.original-panel h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  color: var(--muted);
}
.original-panel dl.meta dt { color: var(--muted); }

.map-inline {
  height: 340px;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 1rem 0;
  box-shadow: var(--shadow-sm);
}

/* ---- Map page (map-first) ---- */
.map-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.1rem;
  margin: 1.25rem 0 2rem;
  align-items: start;
}

.sidebar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1rem 1.25rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.sidebar-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0.2rem 0 0.75rem;
}
.sidebar-title h1 { font-size: 1.4rem; margin: 0; }
.sidebar-count { color: var(--muted); font-size: 0.85rem; font-weight: 600; }

.filters {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.search-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-row {
  display: flex;
  gap: 0.5rem;
}
.filter-row select {
  flex: 1;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 0.88rem;
}
.filter-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  margin-top: 0.2rem;
}

.dest-list { list-style: none; margin: 0; padding: 0; }
.dest-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.7rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.55rem;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  background: #fff;
}
.dest-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateX(2px);
}
.dest-item.active {
  border-color: var(--accent-dark);
  background: var(--accent-soft);
}
.dest-item .pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 4px;
  background: var(--pin-blue);
  color: #fff;
  transform: rotate(-45deg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.dest-item .pin span {
  transform: rotate(45deg);
  font-size: 0.85rem;
}
.dest-item .item-body { flex: 1; min-width: 0; }
.dest-item .item-name { font-weight: 700; color: var(--fg); }
.dest-item .item-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dest-item .item-tags { margin-top: 0.35rem; }
.dest-item .empty-coords { color: var(--muted-2); font-size: 0.85rem; }

/* Map container */
.map-wrap {
  position: relative;
}
#atimonan-map {
  height: calc(100vh - 220px);
  min-height: 480px;
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  background: #dfe7ee;
}

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.map-controls .ctl {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: var(--shadow-md);
  color: var(--fg);
}
.map-controls .ctl:hover { background: var(--accent-soft); }
.zoom-legend {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
  box-shadow: var(--shadow-md);
  max-width: 190px;
  line-height: 1.35;
}

/* Leaflet popup polish */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

/* Custom map markers (pins) */
.atimonan-pin {
  background: transparent;
  border: none;
}
.atimonan-pin .pin-body {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  border: 2px solid rgba(255, 255, 255, 0.9);
}
.atimonan-pin .pin-body span {
  transform: rotate(45deg);
  font-size: 0.95rem;
  line-height: 1;
}
.leaflet-popup-content { margin: 0.6rem 0.8rem; font-size: 0.9rem; }
.map-popup strong { font-size: 1rem; color: #111; }
.map-popup .pop-meta { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; }
.map-popup .pop-link { display: inline-block; margin-top: 0.4rem; color: var(--accent-dark); font-weight: 700; }

@media (max-width: 960px) {
  .map-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  #atimonan-map { height: 60vh; min-height: 400px; }
}

@media (max-width: 640px) {
  .header-inner { justify-content: space-between; }
  .nav { gap: 0.6rem; }
  .nav a { font-size: 0.85rem; }
  .nav .btn.primary { padding: 0.45rem 0.6rem; font-size: 0.82rem; }
  .meta { grid-template-columns: 1fr; }
  .detail { padding: 1.25rem; }
}

/* Form */
.form {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  max-width: 720px;
  margin: 1.5rem auto;
}
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 700; margin-bottom: 0.3rem; font-size: 0.95rem; }
.field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; margin-top: 0.5rem; }
.checkbox input { width: auto; }
.form .actions { margin-top: 1.5rem; }
