:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --line: #e2e8f0;
  --ink: #0f172a;
  --ink-dim: #64748b;
  --accent: #0369a1;
  --accent-2: #b45309;
  --good: #059669;
  --warn: #d97706;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top nav */
.topnav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.topnav .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topnav .links {
  display: flex;
  gap: 1rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.topnav .links a {
  color: var(--ink-dim);
  font-size: 0.9rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
}

.topnav .links a.active,
.topnav .links a:hover {
  color: var(--ink);
  background: var(--panel-2);
  text-decoration: none;
}

/* Homepage layout */
.home {
  display: grid;
  grid-template-columns: 1fr 420px;
  height: calc(100vh - 56px);
}

#map {
  width: 100%;
  height: 100%;
  background: #e8f0fe;
}

.sidebar {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 5;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar-header .sub {
  color: var(--ink-dim);
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.stat {
  text-align: center;
}

.stat strong {
  display: block;
  color: var(--accent);
  font-size: 1.05rem;
  line-height: 1.1;
}

.stat span {
  color: var(--ink-dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stops-list {
  padding: 0.5rem 0;
}

.stop-row {
  display: flex;
  gap: 0.85rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s;
}

.stop-row:hover {
  background: var(--panel-2);
}

.stop-row.active {
  background: rgba(3, 105, 161, 0.1);
  border-left: 3px solid var(--accent);
  padding-left: calc(1.25rem - 3px);
}

.stop-pin {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px currentColor, 0 1px 3px rgba(0,0,0,0.2);
}

.stop-content { flex: 1; min-width: 0; }

.stop-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.stop-title .name {
  font-weight: 600;
  font-size: 0.95rem;
}

.stop-title .nights {
  color: var(--ink-dim);
  font-size: 0.8rem;
  white-space: nowrap;
}

.stop-note {
  color: var(--ink-dim);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.country-divider {
  padding: 0.85rem 1.25rem 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}

.country-divider .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.country-divider .name {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}

.country-divider .meta {
  color: var(--ink-dim);
  font-size: 0.78rem;
}

.country-divider a {
  color: var(--ink-dim);
  font-size: 0.78rem;
  margin-left: 0.5rem;
}

.note-row {
  margin: 0.35rem 1.25rem 0.7rem;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  font-size: 0.82rem;
  background: rgba(3, 105, 161, 0.07);
  border-left: 3px solid var(--accent);
  color: var(--ink);
}

.note-row.warn {
  background: rgba(220, 38, 38, 0.06);
  border-left-color: var(--danger);
}

/* Generic page layout */
.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.page h1 {
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
}

.page h2 {
  font-size: 1.15rem;
  margin: 1.5rem 0 0.5rem;
}

.page h3 {
  margin: 1rem 0 0.4rem;
  color: var(--accent);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page .lead {
  color: var(--ink-dim);
  font-size: 0.95rem;
  margin: 0 0 1.25rem;
}

@media (min-width: 640px) {
  .page {
    padding: 2.5rem 1.5rem 4rem;
  }
  .page h1 { font-size: 2rem; }
  .page h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; }
  .page h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
  .page .lead { font-size: 1.05rem; margin: 0 0 1.5rem; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.country-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--country-color), transparent 80%), var(--panel);
  border: 1px solid var(--line);
  margin-bottom: 1.5rem;
}

.country-hero .flag { font-size: 2.5rem; }
.country-hero h1 { margin: 0; }
.country-hero .meta { color: var(--ink-dim); font-size: 0.95rem; }

.stops-table {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
}

.stops-table li {
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.stops-table li:last-child { border: none; }

.stops-table .name { font-weight: 600; }
.stops-table .note { color: var(--ink-dim); font-size: 0.9rem; flex: 1; margin-left: 0.5rem; }
.stops-table .nights { color: var(--ink-dim); font-size: 0.85rem; white-space: nowrap; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

th, td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  font-weight: 600;
}

td:nth-child(n+2), th:nth-child(n+2) { text-align: right; }

tr.subtotal td {
  background: rgba(3, 105, 161, 0.06);
  font-weight: 700;
}

tr.total td {
  border-top: 2px solid var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  padding-top: 0.85rem;
}

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.country-link {
  display: block;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  transition: transform 0.12s, border-color 0.12s;
}

.country-link:hover {
  text-decoration: none;
  border-color: var(--accent);
  transform: translateY(-2px);
}

.country-link .flag { font-size: 1.8rem; }
.country-link h3 {
  margin: 0.4rem 0 0.2rem;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.15rem;
}

.country-link .meta { color: var(--ink-dim); font-size: 0.85rem; }

footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.85rem;
  padding: 1.5rem;
  border-top: 1px solid var(--line);
}

/* MapLibre popup styling */
.maplibregl-popup-content {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line);
  border-radius: 8px !important;
  font-family: inherit;
  padding: 0.6rem 0.85rem !important;
}

/* Part II banner */
.pt2-banner {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 0 1.25rem 1rem;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 60%, #99f6e4 100%);
  border: 1px solid #059669;
  color: #064e3b !important;
  text-decoration: none !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.pt2-banner:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(5, 150, 105, 0.2);
  text-decoration: none !important;
}
.pt2-banner .pt2-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #047857;
  font-weight: 600;
}
.pt2-banner .pt2-title {
  font-weight: 700;
  font-size: 1rem;
}
.pt2-banner .pt2-sub {
  font-size: 0.82rem;
  color: #065f46;
}

.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-content .pop-name { font-weight: 700; }
.maplibregl-popup-content .pop-meta { color: var(--ink-dim); font-size: 0.85rem; }

@media (max-width: 880px) {
  .home { grid-template-columns: 1fr; height: auto; }
  #map { height: 60vh; /* sticky removed — scrolls away on mobile */ }
  .sidebar { max-height: none; border-left: none; border-top: 1px solid var(--line); }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .topnav {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav .brand { font-size: 0.9rem; white-space: nowrap; }
  .topnav .links {
    gap: 0.15rem;
  }
  .topnav .links a {
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
    white-space: nowrap;
  }
}
