/* ---- Tokens ---------------------------------------------------- */
:root {
  --ink-900: #121a17;      /* near-black pine, panel bg */
  --ink-800: #1b2622;      /* panel bg, slightly lighter */
  --ink-700: #26332e;      /* borders / dividers */
  --paper:   #eae6d9;      /* text on dark, warm paper tone */
  --paper-dim: #a9ab9e;    /* secondary text */
  --contour: #8fae86;      /* muted moss green — trace / accent */
  --ochre:   #c98a3e;      /* burnt ochre — highlight / active */
  --font-ui:   -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-data: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  color: var(--paper);
  background: var(--ink-900);
}

/* ---- Layout ------------------------------------------------------ */
/* The sidebar is always an overlay panel above the map, toggled by
   #sidebar-toggle. This keeps one code path for desktop and mobile
   instead of two different layout systems. */

#mapid {
  position: fixed;
  inset: 0;
  background: #2b2b2b;
}

#sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 340px;
  max-width: 86vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 18% 8%, rgba(143,174,134,0.10), transparent 45%),
    repeating-radial-gradient(circle at 80% 100%, rgba(234,230,217,0.035) 0, rgba(234,230,217,0.035) 1px, transparent 1px, transparent 26px),
    var(--ink-900);
  border-right: 1px solid var(--ink-700);
  box-shadow: 6px 0 24px rgba(0,0,0,0.35);
  z-index: 500;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}
#sidebar.open { transform: translateX(0); }

/* ---- Sidebar header ------------------------------------------------ */
#sidebar-header {
  padding: 18px 18px 10px;
  border-bottom: 1px solid var(--ink-700);
}
#sidebar-header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}
.subtitle {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--paper-dim);
}

/* ---- Search --------------------------------------------------- */
#search-wrap {
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  border-bottom: 1px solid var(--ink-700);
}
#search { min-width: 120px; }
#search {
  flex: 1;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  color: var(--paper);
  border-radius: 4px;
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: 0.88rem;
}
#search:focus {
  outline: 2px solid var(--ochre);
  outline-offset: 1px;
}
#search::placeholder { color: var(--paper-dim); }
#select-all-btn {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--ink-700);
  color: var(--paper-dim);
  font-size: 0.72rem;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
#select-all-btn:hover:not(:disabled) { color: var(--paper); border-color: var(--paper-dim); }
#select-all-btn:disabled { opacity: 0.4; cursor: default; }
#result-count {
  font-family: var(--font-data);
  font-size: 0.72rem;
  color: var(--paper-dim);
  white-space: nowrap;
}

/* ---- Trace list ------------------------------------------------ */
#trace-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1 1 auto;
  border-bottom: 1px solid var(--ink-700);
}
#trace-list li {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 18px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
#trace-list li:hover { background: rgba(234,230,217,0.05); }
#trace-list li.checked {
  border-left-color: var(--contour);
  background: rgba(143,174,134,0.08);
}
#trace-list input[type="checkbox"] {
  accent-color: var(--contour);
  flex: 0 0 auto;
}
.color-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}
#trace-list .t-name {
  flex: 1;
  font-size: 0.86rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#trace-list .t-date {
  flex: 0 0 auto;
  font-family: var(--font-data);
  font-size: 0.72rem;
  color: var(--paper-dim);
}
#trace-list .empty-msg,
#trace-list .error-msg {
  padding: 14px 18px;
  color: var(--paper-dim);
  font-size: 0.85rem;
  cursor: default;
}
#trace-list .error-msg { color: var(--ochre); }

/* ---- Selected / summary ----------------------------------------- */
#selected-wrap {
  flex: 0 0 auto;
  max-height: 34vh;
  display: flex;
  flex-direction: column;
}
#selected-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px 6px;
}
#selected-header h2 {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
#clear-btn {
  background: none;
  border: 1px solid var(--ink-700);
  color: var(--paper-dim);
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
}
#clear-btn:hover { color: var(--paper); border-color: var(--paper-dim); }

#summary-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-data);
  font-size: 0.72rem;
  overflow-y: auto;
  display: block;
  padding: 0 18px 14px;
}
#summary-table thead, #summary-table tbody { display: table; width: 100%; table-layout: fixed; }
#summary-table th {
  text-align: right;
  color: var(--paper-dim);
  font-weight: 400;
  padding: 3px 4px;
  border-bottom: 1px solid var(--ink-700);
}
#summary-table th:first-child, #summary-table td:first-child { text-align: left; }
#summary-table td {
  padding: 4px 4px;
  text-align: right;
  border-bottom: 1px solid rgba(38,51,46,0.6);
}
#summary-table td.t-name {
  text-align: left;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}
#summary-empty td {
  color: var(--paper-dim);
  font-family: var(--font-ui);
  font-style: italic;
  border-bottom: none;
}
.remove-x {
  cursor: pointer;
  color: var(--paper-dim);
}
.remove-x:hover { color: var(--ochre); }

/* ---- Footer ------------------------------------------------------ */
#sidebar-footer {
  padding: 10px 18px 14px;
  font-size: 0.68rem;
  color: var(--paper-dim);
  border-top: 1px solid var(--ink-700);
}
#sidebar-footer a { color: var(--contour); }
#sidebar-footer p { margin: 0; }

/* ---- Sidebar toggle ------------------------------------------------ */
#sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 600;
  width: 38px;
  height: 38px;
  border-radius: 4px;
  border: 1px solid var(--ink-700);
  background: var(--ink-800);
  color: var(--paper);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
#sidebar-toggle:hover { border-color: var(--paper-dim); }
/* Slide the button along with the sidebar so it always sits at its edge */
#sidebar.open ~ #sidebar-toggle { left: calc(340px + 12px); }
@media (max-width: 460px) {
  /* sidebar is full-width here, so keep the button pinned in the corner,
     floating above the sidebar content, rather than pushing it off-screen */
  #sidebar.open ~ #sidebar-toggle { left: 12px; }
}

/* ---- Leaflet popup / control theming ------------------------------ */
.leaflet-control-layers,
.leaflet-bar a {
  background: var(--ink-800) !important;
  color: var(--paper) !important;
  border-color: var(--ink-700) !important;
}
.leaflet-control-layers-toggle { filter: invert(0.9); }

/* Leaflet's zoom control sits top-left by default, which is exactly where
   #sidebar-toggle is — push it down clear of the button. */
.leaflet-top.leaflet-left {
  margin-top: 58px;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--ink-800);
  color: var(--paper);
}
.leaflet-popup-content { font-size: 0.85rem; line-height: 1.4; }
.leaflet-popup-content .trace-popup { font-family: var(--font-ui); }
.leaflet-popup-close-button { color: var(--paper-dim) !important; }
.ele-spark { display: block; margin-top: 6px; }
.ele-range {
  font-family: var(--font-data);
  font-size: 0.65rem;
  color: var(--paper-dim);
  text-align: right;
  margin-top: 1px;
}
.photo-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  max-width: 240px;
}
.photo-gallery .gallery-status {
  font-size: 0.72rem;
  color: var(--paper-dim);
  font-style: italic;
}
.photo-gallery .thumb-btn {
  padding: 0;
  border: 1px solid var(--ink-700);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  line-height: 0;
}
.photo-gallery .thumb-btn:hover { border-color: var(--ochre); }
.photo-gallery img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 2px;
  display: block;
}
.photo-gallery .gallery-more {
  align-self: center;
  font-size: 0.7rem;
  color: var(--paper-dim);
  padding: 0 4px;
}

/* ---- Lightbox ------------------------------------------------------ */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(10, 13, 12, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox[hidden] { display: none; }
#lightbox-img {
  max-width: 88vw;
  max-height: 82vh;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#lightbox-caption {
  position: absolute;
  bottom: 22px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-data);
  font-size: 0.78rem;
  color: var(--paper-dim);
}
#lightbox-close,
#lightbox-prev,
#lightbox-next {
  position: absolute;
  background: rgba(27, 38, 34, 0.75);
  color: var(--paper);
  border: 1px solid var(--ink-700);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}
#lightbox-close:hover,
#lightbox-prev:hover:not(:disabled),
#lightbox-next:hover:not(:disabled) { border-color: var(--paper-dim); }
#lightbox-prev:disabled,
#lightbox-next:disabled { opacity: 0.3; cursor: default; }
#lightbox-close { top: 16px; right: 16px; width: 38px; height: 38px; }
#lightbox-prev, #lightbox-next {
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 64px;
}
#lightbox-prev { left: 16px; }
#lightbox-next { right: 16px; }
@media (max-width: 460px) {
  #lightbox-prev, #lightbox-next { width: 38px; height: 52px; font-size: 1.1rem; }
}

/* ---- Small screens --------------------------------------------------- */
@media (max-width: 460px) {
  #sidebar { width: 100vw; max-width: 100vw; }
}
