:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #1e2320;
  --muted: #5c6560;
  --line: #d7dad3;
  --accent: #14572b;        /* KGS deep green */
  --accent-ink: #ffffff;
  --focus: #1f6feb;
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  /* App fills the viewport; the filter rail and results scroll on their own. */
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- KGS header ---------- */
.site-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 9px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-logo { height: 42px; width: auto; background: #fff; border-radius: 4px; padding: 2px 10px 2px 10px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 6px;
  background: #fff; color: var(--accent);
  font-weight: 800; font-size: 15px; letter-spacing: 0.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text small { font-size: 11.5px; opacity: 0.85; }
.tool-title {
  margin: 0;
  font-size: 16px; font-weight: 600;
  padding-left: 20px;
  border-left: 1px solid rgba(255, 255, 255, 0.35);
}


/* ---------- app shell: two independently-scrolling columns ---------- */
.app {
  flex: 1 1 auto;
  min-height: 0;                 /* lets children scroll instead of the page */
  display: grid;
  grid-template-columns: 340px 1fr;
}
 
.filters {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.filters-body {
  flex: 1 1 auto;
  overflow-y: auto;              /* the filters scroll here, not the page */
  padding: 18px;
}
.actions {
  flex: none;                    /* pinned at the bottom of the rail, always visible */
  display: flex;
  gap: 10px;
  padding: 12px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
 
.results {
  min-height: 0;
  overflow-y: auto;              /* results scroll independently of the filters */
  padding: 16px 20px 40px;
}
 
/* ---------- form controls ---------- */
.field { margin-bottom: 16px; }
.field > label,
.field legend { display: block; font-weight: 600; margin-bottom: 6px; }
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; }
 
input[type="text"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
select[multiple] { padding: 4px; }
 
.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
 
.check { display: block; font-weight: 400; margin: 4px 0; cursor: pointer; }
.check input { margin-right: 8px; }
 
.btn {
  font: inherit;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:hover { filter: brightness(0.97); }
 
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* source links + inline "zoom" action */
.desc-src a,
.unit-name a { color: var(--accent); text-decoration: underline; }
.desc-src a:hover,
.unit-name a:hover { text-decoration: none; }

.linkbtn {
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.linkbtn:hover { text-decoration: none; }

/* ---------- map ---------- */
#lithoMap {
  height: 440px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  background: #eef0ea;
}
 
/* ---------- results ---------- */
.status {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  margin-bottom: 16px;
}
 
.section-heading {
  font-size: 17px;
  margin: 8px 0 14px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
}
 
.rank { margin-bottom: 26px; }
.rank-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin: 0 0 12px;
}
 
.unit-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.unit-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid #000;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
}
.unit-name { font-weight: 700; }
 
.desc { padding: 8px 0; border-top: 1px dashed var(--line); }
.desc:first-of-type { border-top: 0; }
.desc-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.desc-text { margin: 0; text-align: justify; }
.desc-src { font-size: 12.5px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
 
.related-units {
  margin-top: 8px;
  padding: 8px 10px;
  background: #f0f2ee;
  border-radius: 6px;
}
.related-title { font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.related-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.related-name { font-size: 13px; }
.swatch.small { min-width: 34px; height: 22px; font-size: 11px; }

/* small button + strat-code lookup dialog */
.btn-small { padding: 5px 10px; font-size: 13px; }
#stratLookupBtn { margin-top: 8px; }

.strat-dialog {
  width: min(760px, 94vw);
  max-height: 86vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.strat-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.strat-closebar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--accent); color: var(--accent-ink);
}
.strat-closebar .btn-small { background: #fff; }
.strat-controls { display: flex; flex-wrap: wrap; gap: 16px; padding: 16px; }
.strat-group { flex: 1 1 300px; }
.strat-group > label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.strat-row { display: flex; gap: 8px; }
.strat-status { padding: 0 16px 10px; color: var(--muted); font-size: 13px; }
.strat-results { padding: 0 16px 16px; overflow-y: auto; max-height: 52vh; }
.strat-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.strat-table th, .strat-table td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.strat-table thead th { position: sticky; top: 0; background: var(--panel); border-bottom: 2px solid var(--line); }

/* ---------- mobile: stack, and let the page scroll normally ---------- */
@media (max-width: 800px) {
  body { display: block; height: auto; overflow: visible; }
  .app { display: block; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); }
  .filters-body { overflow: visible; }
  .actions { position: sticky; bottom: 0; }
  .results { overflow: visible; }
  #lithoMap { height: 360px; }
  .site-header { flex-wrap: wrap; gap: 6px 14px; }
  .tool-title { border-left: 0; padding-left: 0; font-size: 14px; }
}
 
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}