* { box-sizing: border-box; margin: 0; }

:root {
  --bg: #fff;
  --bg-alt: #f8f8fa;
  --bg-controls: #f4f4f6;
  --text: #1a1a2e;
  --text-dim: #666;
  --border: #ddd;
  --row-border: #e8eaed;
  --header-bg: linear-gradient(120deg, #0d1730 0%, #14213d 55%, #1d3262 100%);
  --header-text: #fff;
  --row-hover: #eef2ff;
  --accent: #14213d;
  --amber: #f5a623;
  --accent-text: #fff;
}
:root[data-theme="dark"] {
  --bg: #16181d;
  --bg-alt: #1c1f26;
  --bg-controls: #1c1f26;
  --text: #e8e8ec;
  --text-dim: #9aa0ab;
  --border: #32363f;
  --row-border: transparent;
  --header-bg: linear-gradient(120deg, #090f1e 0%, #101b36 55%, #16264d 100%);
  --header-text: #e8e8ec;
  --row-hover: #263041;
  --accent: #7f9cf5;
  --amber: #f5b84d;
  --accent-text: #0b1120;
}

body {
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
header {
  padding: 10px 16px;
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--header-text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.02em;
}
.brand-text { line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 650; display: block; }
.brand-text span { font-size: 11px; opacity: 0.65; }
#meta { font-size: 12px; opacity: 0.75; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.admin-chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  background: var(--amber);
  color: #14213d;
  border-radius: 4px;
  padding: 3px 7px;
}
#theme, #account, #resources {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: var(--header-text);
  border-radius: 5px;
  padding: 3px 9px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  height: 28px;
}
#theme { margin-left: auto; }
#account-tip {
  position: fixed;
  top: 46px;
  right: 12px;
  background: var(--header-bg);
  color: var(--header-text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  z-index: 2000;
}

#controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-controls);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
#controls input, #controls select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  color-scheme: light;
}
:root[data-theme="dark"] #controls input,
:root[data-theme="dark"] #controls select { color-scheme: dark; }
#q { width: 230px; }
#recent-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
#recent-label input { margin: 0; }
#recent-count { color: var(--text-dim); font-size: 11px; }
#csv {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  white-space: nowrap;
}
#csv:hover { filter: brightness(1.15); }
#csv.disabled { opacity: .45; pointer-events: none; }
#count { font-size: 11px; opacity: .75; }

.new-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff;
  background: #d32f2f;
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 4px;
  vertical-align: middle;
}

#main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#map { flex: 1; min-height: 120px; background: var(--bg-alt); }
#drag {
  height: 14px;
  flex: none;
  background: var(--bg-controls);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
}
#drag span {
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-dim);
  opacity: 0.6;
}
#tablewrap { height: 40vh; flex: none; overflow: auto; }
#tablewrap.collapsed { height: 0 !important; }

table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 10px; text-align: left; white-space: nowrap; }
td { border-bottom: 1px solid var(--row-border); }
th {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
  cursor: pointer;
  user-select: none;
}
th[data-k]::after {
  content: "▲";
  display: inline-block;
  margin-left: 6px;
  font-size: 9px;
  opacity: 0.25;
  transition: transform 0.15s, opacity 0.15s;
}
th[data-k].sort-asc::after,
th[data-k].sort-desc::after { opacity: 1; }
th[data-k].sort-desc::after { transform: rotate(180deg); }
tbody tr:nth-child(even) { background: var(--bg-alt); }
tbody tr:hover { background: var(--row-hover); cursor: pointer; }
td.str { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.row-btn {
  display: inline-block;
  font-size: 11px;
  padding: 2px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  text-decoration: none;
}
.row-btn:hover { background: var(--accent); color: var(--accent-text); }
td.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
  font-style: italic;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

.twp-label {
  color: #777;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 0 3px var(--bg);
  pointer-events: none;
}
:root[data-theme="dark"] .twp-label { color: #9aa0ab; }

.sec-label {
  color: #555;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 0 2px var(--bg);
}
:root[data-theme="dark"] .sec-label { color: #b0b5bd; }

.county-label {
  color: #8a6d3b;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg);
  pointer-events: none;
}
:root[data-theme="dark"] .county-label { color: #d8b878; }

:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip {
  background: var(--bg-alt);
  color: var(--text);
}
:root[data-theme="dark"] .leaflet-bar a {
  background: var(--bg-alt);
  color: var(--text);
  border-color: var(--border);
}


/* fairway overlay: hatch pattern defined in index.html <defs> */
path.fairway { fill: url(#hatchFairway); }
/* black hatch vanishes on the dark basemap; lighten it there */
:root[data-theme="dark"] #hatchFairway line { stroke: #c9ced6; }

/* resources dropdown: takes over the auto margin that right-aligns the
   header buttons since it's now leftmost */
#resources-wrap { position: relative; margin-left: auto; }
#resources .caret { font-size: 10px; opacity: 0.85; }
#theme { margin-left: 0; }

#resources-dropdown {
  display: none;
  position: absolute;
  top: 34px;
  left: 0;
  min-width: 160px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  z-index: 2000;
}
#resources-wrap.open #resources-dropdown { display: block; }
#resources-dropdown a {
  display: block;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--header-text);
  text-decoration: none;
  font-size: 13px;
}
#resources-dropdown a[hidden] { display: none; }
#resources-dropdown a:hover { background: rgba(255, 255, 255, 0.12); }

/* account dropdown: mirrors the nav dropdown but right-aligned */
#account-wrap { position: relative; }
#account-dropdown {
  display: none;
  position: absolute;
  top: 34px;
  right: 0;
  min-width: 220px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  z-index: 2000;
}
#account-wrap.open #account-dropdown { display: block; }
#account-dropdown a {
  display: block;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--header-text);
  text-decoration: none;
  font-size: 13px;
}
#account-dropdown a:hover { background: rgba(255, 255, 255, 0.12); }
.account-info {
  padding: 6px 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  margin-bottom: 4px;
  color: var(--header-text);
  font-size: 13px;
}
.account-info span { display: block; font-size: 11px; opacity: 0.65; margin-top: 2px; }

/* login page */
.auth-page { justify-content: flex-start; }
.auth-card {
  margin: 12vh auto 0;
  width: min(360px, calc(100% - 32px));
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.auth-card h1 { font-size: 18px; margin-bottom: 4px; }
.auth-card p { font-size: 12px; color: var(--text-dim); margin-bottom: 16px; }
.auth-card label { display: block; font-size: 12px; margin: 10px 0 4px; }
.auth-card input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.auth-card button {
  width: 100%;
  margin-top: 16px;
  padding: 9px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.auth-error { color: #c0392b; font-size: 12px; margin-top: 10px; min-height: 16px; }
.auth-toggle {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 14px;
}
.auth-toggle a { font-weight: 600; }
