:root {
  --bg:         #f5f4f0;
  --surface:    #ffffff;
  --border:     #e2e0db;
  --text:       #1a1916;
  --text-muted: #6b6860;
  --accent:     #1a1916;
  --sidebar-w:  300px;
  --header-h:   88px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* LOADER */
#loader {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 9999; transition: opacity .4s;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.loader-text { font-size: 12px; color: var(--text-muted); font-family: 'DM Mono', monospace; }
@keyframes spin { to { transform: rotate(360deg); } }

/* HEADER */
header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  z-index: 1000;
}
header img { height: 64px; width: auto; }
.header-divider { width: 1px; height: 56px; background: var(--border); flex-shrink: 0; }
.header-text { display: flex; flex-direction: column; gap: 1px; }
.header-inst  { font-size: 10px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.header-title { font-size: 13px; font-weight: 600; line-height: 1.3; }

/* LAYOUT */
.layout {
  display: flex;
  padding-top: var(--header-h);
  height: 100vh;
}

/* SIDEBAR */
aside {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 20px 16px;
  display: flex; flex-direction: column; gap: 24px;
}

.section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 10px;
}

.control-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.control-group:last-child { margin-bottom: 0; }

.control-row {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px;
}
.control-name { font-size: 12px; font-weight: 500; }
.control-val {
  font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
  color: var(--text-muted); background: var(--bg);
  padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border);
  min-width: 60px; text-align: right;
}

/* RANGE INPUTS */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 2px; border-radius: 2px;
  background: var(--border); outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent); cursor: pointer; border: none;
}

/* EDITABLE VALUE INPUTS */
.val-input-wrap {
  display: flex; align-items: center; gap: 3px; flex-shrink: 0;
}
.val-input-wrap.dual { gap: 4px; }
.control-val-input {
  font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
  color: var(--text-muted); background: var(--bg);
  padding: 2px 4px; border-radius: 4px; border: 1px solid var(--border);
  width: 46px; text-align: right;
  -moz-appearance: textfield;
}
.control-val-input::-webkit-outer-spin-button,
.control-val-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.control-val-input:focus {
  outline: none; border-color: var(--accent); color: var(--text);
}
.val-unit { font-size: 10px; color: var(--text-muted); }

/* DUAL RANGE */
.dual-range {
  position: relative;
  height: 14px;
  margin-top: 8px;
}
/* grey base track */
.dual-range::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%; transform: translateY(-50%);
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  pointer-events: none;
}
.dual-track-fill {
  position: absolute;
  height: 2px;
  top: 50%; transform: translateY(-50%);
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
}
/* both range inputs stacked, full width, transparent track */
.dual-range input[type=range] {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 14px;
  background: transparent;
  pointer-events: none;
  margin: 0; padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.dual-range input[type=range]::-webkit-slider-runnable-track {
  background: transparent; height: 2px;
}
.dual-range input[type=range]::-moz-range-track {
  background: transparent; height: 2px;
}
.dual-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  pointer-events: all;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer; margin-top: -6px;
}
.dual-range input[type=range]::-moz-range-thumb {
  pointer-events: all;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer; border: none;
}

/* STATUS */
#status {
  font-size: 11px; padding: 8px 10px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); font-family: 'DM Mono', monospace; line-height: 1.5;
}
#status.computing { border-color: #d4a017; background: #fffbf0; color: #8a6800; }
#status.done      { border-color: #2d8a52; background: #f0faf4; color: #1a5c35; }
#status.empty     { border-color: #c0392b; background: #fdf0ef; color: #8a1c13; }

/* LEGEND */
.legend { display: flex; flex-direction: column; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }

.dot   { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.swatch { width: 18px; height: 10px; border-radius: 2px; flex-shrink: 0; }

.swatch.optima   { background: #6600cc; opacity: .7; }
.swatch.buf-edu  { background: #1d6fa4; opacity: .5; border: 1px solid #1d6fa4; }
.swatch.buf-stm  { background: #2d8a52; opacity: .5; border: 1px solid #2d8a52; }
.swatch.buf-excl { background: #c0392b; opacity: .5; border: 1px solid #c0392b; }

.dot.bib { background: #d4a017; border: 2px solid #333; }
.dot.edu { background: #1d6fa4; }
.dot.stm { background: #2d8a52; }

/* MAP */
#map { flex: 1; min-width: 0; }

/* LEAFLET OVERRIDES */
.leaflet-control-layers {
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,.08) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-size: 12px !important;
}
.leaflet-popup-content-wrapper {
  border-radius: 8px !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,.1) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-size: 12px !important;
}

/* POPUP TABLE */
.popup-table { font-size: 12px; border-collapse: collapse; max-width: 320px; }
.popup-table th { text-align: left; padding: 3px 10px 3px 0; font-weight: 500; color: var(--text-muted); white-space: nowrap; }
.popup-table td { padding: 3px 0; font-family: 'DM Mono', monospace; font-size: 11px; }
.popup-title    { font-weight: 600; margin-bottom: 8px; font-size: 13px; }

/* RESPONSIVE */
@media (max-width: 640px) {
  :root { --sidebar-w: 100%; }
  .layout { flex-direction: column; }
  aside { width: 100%; height: 280px; border-right: none; border-bottom: 1px solid var(--border); }
}
