:root {
  --ink: #0d2634;
  --ink-deep: #071a24;
  --ink-panel: #102c3b;
  --ink-panel-2: #143244;
  --line: #e9f3ee;
  --line-dim: #b9d3ce;
  --muted: #7fa2ab;
  --grid: rgba(233, 243, 238, 0.08);
  --grid-strong: rgba(233, 243, 238, 0.16);
  --brass: #c9a35f;
  --brass-bright: #e0bd7d;

  --series-1: #4fa7c9;
  --series-2: #8b7ec8;
  --series-3: #c9a35f;
  --series-4: #d08a2e;
  --series-5: #6b8cae;
  --series-6: #9c6b4f;
  --series-7: #7aa889;
  --series-8: #b5473a;

  --good: #5c9a70;
  --warning: #d08a2e;
  --critical: #b5473a;
  --neutral: #7fa2ab;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-color: #3a5966 var(--ink-deep);
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(79, 167, 201, 0.10), transparent 45%),
    radial-gradient(circle at 88% 0%, rgba(201, 163, 95, 0.06), transparent 40%),
    repeating-linear-gradient(0deg, var(--grid) 0px, var(--grid) 1px, transparent 1px, transparent 32px),
    repeating-linear-gradient(90deg, var(--grid) 0px, var(--grid) 1px, transparent 1px, transparent 32px),
    var(--ink);
  color: var(--line);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Header / title block ---- */

header {
  padding: 14px 28px;
  border-bottom: 1px solid var(--grid-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(79, 167, 201, 0.07), transparent);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand .mark {
  flex-shrink: 0;
  color: var(--brass);
  filter: drop-shadow(0 0 8px rgba(201, 163, 95, 0.35));
}

.brand .eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
}

header h1 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin: 1px 0 0;
  letter-spacing: 0.01em;
  color: var(--line);
}

header h1 span {
  color: var(--brass-bright);
}

header .brand-sub {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.field-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-value {
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.75); }
}

header .subtitle {
  color: var(--line-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", monospace;
}

main {
  padding: 24px 28px 60px;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---- KPI instrument row ---- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-tile {
  background: linear-gradient(160deg, var(--ink-panel-2), var(--ink-panel));
  border: 1px solid var(--grid-strong);
  border-radius: 3px;
  padding: 16px 18px 14px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.kpi-tile::before {
  content: "";
  position: absolute;
  top: 10px;
  right: 12px;
  bottom: 10px;
  width: 1px;
  background: repeating-linear-gradient(0deg, var(--grid-strong) 0 3px, transparent 3px 7px);
}

.kpi-tile:hover {
  border-color: rgba(201, 163, 95, 0.45);
}

.kpi-label {
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kpi-label::before {
  content: "▸";
  color: var(--brass);
}

.kpi-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 32px;
  font-weight: 700;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--brass-bright);
}

.kpi-rule {
  margin-top: 10px;
  height: 5px;
  background-image: repeating-linear-gradient(90deg, var(--grid-strong) 0 1px, transparent 1px 8px);
}

/* ---- Panels ---- */

.panel {
  background: linear-gradient(160deg, var(--ink-panel), var(--ink-panel) 65%, var(--ink-panel-2));
  border: 1px solid var(--grid-strong);
  border-radius: 3px;
  padding: 18px;
  margin-bottom: 20px;
  position: relative;
}

.panel h2 {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--line-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2::before {
  content: "";
  width: 3px;
  height: 12px;
  background: var(--brass);
  display: inline-block;
}

.panel.accent-status h2::before { background: var(--good); }
.panel.accent-map h2::before { background: var(--series-1); }

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

.chart-grid canvas {
  max-height: 260px;
}

/* ---- Map: survey console ---- */

.map-wrap {
  position: relative;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--grid-strong);
}

.map-wrap .corner-tl,
.map-wrap .corner-tr,
.map-wrap .corner-bl,
.map-wrap .corner-br {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  z-index: 1000;
  pointer-events: none;
}

.map-wrap .corner-tl,
.map-wrap .corner-tr,
.map-wrap .corner-bl,
.map-wrap .corner-br {
  border: 1.5px solid rgba(224, 189, 125, 0.75);
}

.map-wrap .corner-tl { top: 8px; left: 8px; border-right: none; border-bottom: none; }
.map-wrap .corner-tr { top: 8px; right: 8px; border-left: none; border-bottom: none; }
.map-wrap .corner-bl { bottom: 8px; left: 8px; border-right: none; border-top: none; }
.map-wrap .corner-br { bottom: 8px; right: 8px; border-left: none; border-top: none; }

.map-sweep {
  position: absolute;
  inset: 0;
  z-index: 900;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(79, 167, 201, 0.35), transparent);
  width: 40%;
  transform: translateX(-120%);
  animation: sweep 2.2s cubic-bezier(0.4, 0, 0.2, 1) 1;
}

@keyframes sweep {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(340%); }
}

.map-readout {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1000;
  background: rgba(7, 26, 36, 0.82);
  border: 1px solid var(--grid-strong);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--line-dim);
  backdrop-filter: blur(4px);
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
}

.map-readout .n {
  font-family: "Space Grotesk", sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
  display: block;
}

.map-coords {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 1000;
  background: rgba(7, 26, 36, 0.82);
  border: 1px solid var(--grid-strong);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--line-dim);
  backdrop-filter: blur(4px);
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.02em;
}

.map-coords .lbl {
  color: var(--muted);
  margin-right: 6px;
}

#map {
  height: 520px;
  background: var(--ink-panel);
}

.map-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.map-controls select,
.map-controls button,
.table-controls input,
.table-controls select {
  background: var(--ink-panel-2);
  color: var(--line);
  border: 1px solid var(--grid-strong);
  border-radius: 2px;
  padding: 7px 11px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.map-controls button {
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.map-controls button:hover,
.table-controls input:hover {
  border-color: var(--grid-strong);
}

.map-controls button.active {
  border-color: var(--brass);
  color: var(--brass-bright);
  background: rgba(201, 163, 95, 0.12);
}

/* ---- Tabs / table controls ---- */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.03em;
  transition: color 0.15s ease;
}

.tabs button:hover {
  color: var(--line-dim);
}

.tabs button.active {
  color: var(--line);
  border-bottom-color: var(--brass);
}

.table-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.table-controls input {
  min-width: 240px;
}

.table-scroll {
  overflow-x: auto;
  border-radius: 2px;
  border: 1px solid var(--grid-strong);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--ink-panel-2);
  z-index: 5;
}

th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

td { font-variant-numeric: tabular-nums; }
td.mono-cell { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--line-dim); }

th {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
  font-family: "IBM Plex Mono", monospace;
}

th.col-photo, td.col-photo {
  width: 44px;
  max-width: 44px;
  padding-left: 12px;
  padding-right: 4px;
}

tbody tr {
  transition: background 0.1s ease;
}

tbody tr:hover {
  background: rgba(79, 167, 201, 0.08);
}

.pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.pagination button {
  background: var(--ink-panel-2);
  color: var(--line);
  border: 1px solid var(--grid-strong);
  border-radius: 2px;
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--brass);
}

.pagination button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---- Thumbnails ---- */

.thumb {
  width: 30px;
  height: 30px;
  border-radius: 2px;
  border: 1px solid var(--grid-strong);
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  background: var(--ink-deep);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.thumb:hover {
  border-color: var(--brass);
  transform: scale(1.06);
}

.thumb-avatar {
  width: 30px;
  height: 30px;
  border-radius: 2px;
  border: 1px dashed var(--grid-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  background: var(--ink-deep);
}

/* ---- Stamp badges ---- */

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transform: rotate(-2deg);
}

.stamp.good { color: var(--good); }
.stamp.warning { color: var(--warning); }
.stamp.critical { color: var(--critical); }
.stamp.neutral { color: var(--neutral); border-style: dashed; }

.nik-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 10px;
}

.nik-note a {
  color: var(--series-1);
  text-decoration: none;
}

.nik-note a:hover {
  text-decoration: underline;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--ink-panel);
  color: var(--line);
}

#map .marker-cluster-small,
#map .marker-cluster-medium,
#map .marker-cluster-large {
  background: rgba(201, 163, 95, 0.22);
}

#map .marker-cluster-small div,
#map .marker-cluster-medium div,
#map .marker-cluster-large div {
  background: var(--ink-panel-2);
  border: 1.5px solid var(--brass);
  color: var(--brass-bright);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
}

.map-legend {
  font-size: 12px;
  color: var(--line-dim);
  display: flex;
  gap: 14px;
  margin-top: 10px;
  flex-wrap: wrap;
  font-family: "IBM Plex Mono", monospace;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 4px currentColor;
}

/* ---- Lightbox ---- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(7, 20, 27, 0.86);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-width: min(90vw, 480px);
  max-height: 80vh;
  border: 1px solid var(--grid-strong);
  background: var(--ink-panel);
}

.lightbox .lightbox-cap {
  position: absolute;
  bottom: 10%;
  color: var(--line-dim);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* focus visibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
.thumb:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 2px;
}
