/* Classic almanac-inspired palette — warm parchment, brick red + navy accents,
   serif display type for headings, sans-serif for data-dense UI. Reference:
   The Old Farmer's Almanac (cream bg, Source Serif headlines, brick/navy accents). */
:root {
  --bg: #f3e9d2;
  --paper: #faf3e3;
  --surface: #fffaf0;
  --border: #d9c69c;
  --border-strong: #b89f6d;
  --text: #241d14;
  --text-muted: #6b5d47;
  --accent: #a3312b;
  --accent-soft: #f2ddd2;
  --navy: #1c2b46;
  --navy-soft: #dfe4ee;
  --general: #a3312b;
  --hydro: #2b6e6e;
  --agro: #5c6b2f;
  --synop: #b8860b;
  --radius: 8px;
  /* Playfair Display / Inter have no Thai glyphs at all, so Thai text was
     silently falling back to whatever default font the browser/OS picked —
     inconsistent and hard to read. Noto Serif Thai / Sarabun fill the Thai
     half of each stack; the browser picks per-character based on coverage. */
  --serif: "Playfair Display", "Noto Serif Thai", Georgia, "Times New Roman", serif;
  --sans: "Inter", "Sarabun", -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header.topbar {
  background: var(--navy);
  border-bottom: 3px solid var(--accent);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

header.topbar h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0;
  white-space: nowrap;
  color: #faf3e3;
  letter-spacing: 0.01em;
}

nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }

nav.tabs a {
  text-decoration: none;
  color: #cdd3e0;
  padding: 7px 16px;
  border-radius: 4px;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

nav.tabs a.active, nav.tabs a:hover { background: rgba(250, 243, 227, 0.12); color: #faf3e3; border-color: rgba(250,243,227,0.25); }

main { padding: 20px 24px 60px; max-width: 1200px; margin: 0 auto; }

h2 { font-family: var(--serif); font-weight: 700; }

.notice {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #e0b7ac;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.88rem;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(36, 29, 20, 0.06);
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-tile .label { font-size: 0.74rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-tile .value { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; margin-top: 4px; color: var(--navy); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data-table th, table.data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--text-muted); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; text-transform: uppercase; font-size: 0.74rem; letter-spacing: 0.04em; }
table.data-table tbody tr:hover { background: var(--accent-soft); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar select, .toolbar input[type="date"], .toolbar input[type="number"] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
}

.badge { display: inline-block; padding: 2px 9px; border-radius: 3px; font-size: 0.7rem; color: #fff; letter-spacing: 0.02em; }
.badge.general { background: var(--general); }
.badge.hydro { background: var(--hydro); }
.badge.agro { background: var(--agro); }
.badge.synop { background: var(--synop); }

#map { height: 78vh; border-radius: var(--radius); border: 2px solid var(--border-strong); }

.leaflet-popup-content-wrapper { border-radius: 6px; font-family: var(--sans); }
.leaflet-popup-content a { color: var(--accent); }
.leaflet-popup-content h3 { font-family: var(--serif); margin: 0 0 4px; font-size: 1.05rem; }

.map-page-layout { position: relative; }

.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.cart-bar {
  background: var(--navy);
  color: #faf3e3;
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
}
.cart-bar button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.cart-bar button.secondary { background: transparent; border: 1px solid #faf3e3; color: #faf3e3; }
.cart-bar button:hover { opacity: 0.9; }

.popup-select-btn {
  margin-top: 8px;
  width: 100%;
  padding: 6px 10px;
  border-radius: 5px;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--sans);
}
.popup-select-btn.selected { background: var(--accent); color: #fff; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.form-grid label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }

select[multiple] { width: 100%; min-height: 140px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-family: var(--sans); }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: var(--sans);
}
button.primary:hover { opacity: 0.9; }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.format-toggle { display: flex; gap: 8px; }
.format-toggle button {
  padding: 7px 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--sans);
}
.format-toggle button.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 16px; }

.muted { color: var(--text-muted); font-size: 0.85rem; }
