/* FieldMap — dense, desktop-GIS-style chrome around a Leaflet canvas. */

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --ink: #1b2733;
  --ink-2: #566575;
  --ink-3: #8996a5;
  --line: #dde3ea;
  --line-2: #eceff3;
  --accent: #2f6f4e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f1eb;
  --topbar: #23303d;
  --topbar-ink: #dfe6ee;
  --danger: #b4451f;
  --warn: #9a6b12;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 4px 14px rgba(20, 30, 40, .07);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/*
 * Panels here are shown and hidden with the [hidden] attribute, but the
 * browser's "display: none" for [hidden] loses to any author display rule
 * on the same element. The modal, drawer and style panel all set
 * display: flex, so without this they can never be dismissed.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 44px 1fr auto 24px;
  height: 100%;
}

/* ------------------------------ topbar ------------------------------ */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px;
  background: var(--topbar);
  color: var(--topbar-ink);
  border-bottom: 1px solid #16202b;
}


.toolgroup { display: flex; gap: 2px; }

/*
 * Scoped away from .menu-item. This puts light text on the dark bar, but the
 * menu panels hanging off the bar are white — and this selector is more
 * specific than .menu-item, so without the exclusion every menu entry came
 * out light grey on white.
 */
.topbar button:not(.menu-item) {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--topbar-ink);
  padding: 5px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}
.topbar button:not(.menu-item):hover { background: #31404f; }
.topbar button:not(.menu-item).active {
  background: var(--accent); border-color: #3d8a63; color: #fff;
}
.topbar .ico { font-size: 14px; line-height: 1; }

.spacer { flex: 1; }

.basemap-select {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #a9b8c7;
}
.basemap-select select {
  background: #31404f; color: var(--topbar-ink);
  border: 1px solid #3d4d5d; border-radius: var(--radius);
  padding: 4px 6px; font: inherit;
}

/* ---------------------------- workspace ----------------------------- */

.workspace {
  display: flex;
  min-height: 0;
  position: relative;
}

#map {
  flex: 1;
  min-width: 0;
  background: #e8edf1;
  z-index: 0;
}

.panel {
  width: 288px;
  flex: 0 0 288px;
  background: var(--panel);
  display: flex; flex-direction: column;
  min-height: 0;
  z-index: 2;
}
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); width: 312px; flex-basis: 312px; }

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.ptab {
  flex: 1; padding: 9px 6px;
  background: none; border: none; border-bottom: 2px solid transparent;
  font: inherit; color: var(--ink-2); cursor: pointer;
}
.ptab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; background: var(--panel); }

.panel-body { overflow: auto; flex: 1; min-height: 0; padding: 10px; }

.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 650; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--ink-3);
  font-size: 14px; padding: 2px 5px; border-radius: 4px; line-height: 1;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

/* ---------------------------- layer list ---------------------------- */

.layer-toolbar { display: flex; gap: 4px; margin-bottom: 8px; }
.layer-toolbar input {
  flex: 1; min-width: 0;
  padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--radius); font: inherit;
}
.layer-toolbar button {
  padding: 5px 7px; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: var(--radius); cursor: pointer; font-size: 11px; color: var(--ink-2);
}
.layer-toolbar button:hover { background: var(--line-2); }

.layer-list { list-style: none; margin: 0; padding: 0; }

.layer-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 6px;
  background: var(--panel);
  transition: border-color .12s, box-shadow .12s;
}
.layer-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.layer-item.dragging { opacity: .45; }
.layer-item.drop-target { border-top: 2px solid var(--accent); }

.layer-row { display: flex; align-items: center; gap: 7px; padding: 7px 8px; cursor: pointer; }
.layer-row input[type=checkbox] { margin: 0; cursor: pointer; flex: none; }

.layer-swatch {
  width: 16px; height: 16px; border-radius: 3px; flex: none;
  border: 1px solid rgba(0,0,0,.18);
  background-size: cover;
}
.layer-swatch.line { height: 4px; border-radius: 2px; }
.layer-swatch.point { border-radius: 50%; }

.layer-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.layer-meta { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); flex: none; }
.layer-actions { display: flex; gap: 1px; flex: none; }
.layer-actions button {
  background: none; border: none; cursor: pointer; color: var(--ink-3);
  padding: 2px 4px; border-radius: 3px; font-size: 12px; line-height: 1;
}
.layer-actions button:hover { background: var(--line-2); color: var(--ink); }

.layer-sub {
  padding: 0 8px 7px 30px;
  font-size: 10.5px; color: var(--ink-3);
  display: flex; gap: 8px; flex-wrap: wrap;
}
.layer-sub .tag {
  background: var(--line-2); border-radius: 3px; padding: 1px 5px;
  font-family: var(--mono); font-size: 10px; color: var(--ink-2);
}
.layer-sub .tag.warn { background: #fdf1dd; color: var(--warn); }

.layer-legend { padding: 0 8px 8px 30px; }
.legend-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; font-size: 11px; color: var(--ink-2); }
.legend-chip { width: 12px; height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,.15); flex: none; }
.legend-ramp { height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,.12); margin: 3px 0; }
.legend-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-3); font-family: var(--mono); }

.group-head {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-3); margin: 10px 0 5px; font-weight: 650;
}
.group-head:first-child { margin-top: 0; }

.empty-hint { color: var(--ink-3); line-height: 1.55; padding: 4px 2px; }

/* ----------------------------- dropzone ----------------------------- */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 22px 14px;
  text-align: center;
  background: var(--panel-2);
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-title { margin: 0 0 4px; font-weight: 600; }
.dz-sub { margin: 4px 0; color: var(--ink-3); font-size: 11px; }
.dz-formats { margin: 12px 0 0; font-size: 10.5px; color: var(--ink-3); line-height: 1.6; }

button.primary {
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--radius);
  padding: 7px 14px; font: inherit; font-weight: 550; cursor: pointer;
}
button.primary:hover { background: #276042; }
button.primary:disabled { opacity: .55; cursor: default; }

.upload-status { margin-top: 12px; font-size: 12px; }
.upload-status .row { padding: 5px 7px; border-radius: 4px; margin-bottom: 4px; }
.upload-status .ok { background: var(--accent-soft); color: #1f5238; }
.upload-status .err { background: #fbeae4; color: var(--danger); }
.upload-status .info { background: var(--line-2); color: var(--ink-2); }

.progress { height: 4px; background: var(--line-2); border-radius: 2px; overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.api-help { margin-top: 16px; font-size: 11.5px; color: var(--ink-2); }
.api-help summary { cursor: pointer; color: var(--accent); }
.api-help pre {
  background: #1e2a35; color: #cfe0ef; padding: 9px; border-radius: var(--radius);
  overflow-x: auto; font-family: var(--mono); font-size: 10.5px; line-height: 1.5;
}

/* --------------------------- style panel ---------------------------- */

.field { margin-bottom: 11px; }
.field > label {
  display: block; font-size: 11px; color: var(--ink-2);
  margin-bottom: 4px; font-weight: 550;
}
.field select, .field input[type=text], .field input[type=number] {
  width: 100%; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: var(--radius); font: inherit; background: #fff;
}
.field input[type=range] { width: 100%; }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; min-width: 0; }

.swatch-input { display: flex; align-items: center; gap: 7px; }
.swatch-input input[type=color] {
  width: 34px; height: 26px; padding: 0; border: 1px solid var(--line);
  border-radius: 4px; background: none; cursor: pointer;
}
.swatch-input output { font-family: var(--mono); font-size: 11px; color: var(--ink-2); }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1; padding: 6px 4px; border: none; background: var(--panel-2);
  font: inherit; font-size: 11.5px; cursor: pointer; color: var(--ink-2);
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 550; }

.ramp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.ramp-opt { border: 1px solid var(--line); border-radius: 4px; padding: 3px; cursor: pointer; background: #fff; }
.ramp-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.ramp-opt i { display: block; height: 13px; border-radius: 2px; }
.ramp-opt span { display: block; font-size: 9.5px; color: var(--ink-3); text-align: center; margin-top: 2px; }

.style-section {
  border-top: 1px solid var(--line-2);
  padding-top: 11px; margin-top: 11px;
}
.style-section > h3 {
  margin: 0 0 9px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--ink-3);
}

.class-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.class-row {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 7px; border-bottom: 1px solid var(--line-2); font-size: 11.5px;
}
.class-row:last-child { border-bottom: none; }
.class-row input[type=color] { width: 24px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; }
.class-row .lab { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-row .cnt { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }

.hint { font-size: 11px; color: var(--ink-3); line-height: 1.5; margin: 6px 0 0; }
.hint.warn { color: var(--warn); }

/* --------------------------- attribute table ------------------------- */

.drawer {
  height: 260px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column;
  min-height: 0;
}
.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.drawer-head h2 { margin: 0; font-size: 12.5px; font-weight: 650; }
.drawer-head input {
  padding: 4px 7px; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; width: 200px;
}
.drawer-meta { font-size: 11px; color: var(--ink-3); font-family: var(--mono); margin-left: auto; }

.table-wrap { overflow: auto; flex: 1; min-height: 0; }
#attr-table { border-collapse: collapse; font-size: 11.5px; width: 100%; }
#attr-table th, #attr-table td {
  border-bottom: 1px solid var(--line-2); border-right: 1px solid var(--line-2);
  padding: 4px 8px; text-align: left; white-space: nowrap;
}
#attr-table th {
  position: sticky; top: 0; background: var(--panel-2); z-index: 1;
  font-weight: 600; cursor: pointer; user-select: none;
}
#attr-table th:hover { background: var(--line-2); }
#attr-table td.num { text-align: right; font-family: var(--mono); }
#attr-table tbody tr:hover { background: var(--accent-soft); }
#attr-table tbody tr.sel { background: #d9eadf; }
#attr-table tbody tr { cursor: pointer; }

/* ----------------------------- statusbar ----------------------------- */

.statusbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-2);
  font-family: var(--mono);
}
.statusbar .sep { width: 1px; height: 12px; background: var(--line); }
.statusbar .spacer { flex: 1; }
#status-msg { color: var(--accent); font-family: var(--sans); }
#status-msg.err { color: var(--danger); }

/* ------------------------------- modal ------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 40, .42);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
  background: var(--panel); border-radius: 8px; box-shadow: var(--shadow);
  width: min(460px, 92vw); max-height: 80vh; display: flex; flex-direction: column;
}
.modal header {
  display: flex; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.modal header h2 { margin: 0; font-size: 14px; flex: 1; }
.modal > div { padding: 14px; overflow: auto; }

.project-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 6px;
}
.project-row .nm { flex: 1; font-weight: 550; }
.project-row .dt { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); }
.project-row button { border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 4px; padding: 3px 8px; cursor: pointer; font: inherit; font-size: 11px; }

/* ------------------------- leaflet overrides ------------------------- */

.leaflet-container { font: inherit; background: #e8edf1; }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; max-height: 320px; overflow: auto; }
.leaflet-popup-content table { border-collapse: collapse; }
.leaflet-popup-content th {
  text-align: left; padding: 2px 10px 2px 0; color: var(--ink-2);
  font-weight: 550; vertical-align: top; white-space: nowrap;
}
.leaflet-popup-content td { padding: 2px 0; font-family: var(--mono); font-size: 11px; }
.leaflet-popup-content h4 { margin: 0 0 6px; font-size: 12.5px; }

.map-label {
  background: none; border: none; box-shadow: none; padding: 0;
  font-weight: 600; font-size: 11px;
  text-shadow: -1px -1px 0 var(--halo, #fff), 1px -1px 0 var(--halo, #fff),
               -1px 1px 0 var(--halo, #fff), 1px 1px 0 var(--halo, #fff);
}
.map-label::before { display: none; }

.measure-tip {
  background: rgba(35, 48, 61, .92); color: #fff; border: none;
  border-radius: 4px; padding: 3px 7px; font-family: var(--mono); font-size: 11px;
}
.measure-tip::before { border-top-color: rgba(35, 48, 61, .92); }

.busy-badge {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(35, 48, 61, .9); color: #fff;
  padding: 5px 12px; border-radius: 20px; font-size: 11.5px; z-index: 800;
  pointer-events: none;
}

@media (max-width: 900px) {
  .panel-left { flex-basis: 240px; width: 240px; }
  .topbar .lbl { display: none; }
}

/* --------------------------- unit toggle ---------------------------- */

.unit-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.unit-toggle button {
  border: none; background: var(--panel);
  font: inherit; font-family: var(--mono); font-size: 10px;
  padding: 1px 7px; cursor: pointer; color: var(--ink-3);
}
.unit-toggle button + button { border-left: 1px solid var(--line); }
.unit-toggle button.on { background: var(--accent); color: #fff; font-weight: 600; }

/* --------------------------- measure bar ---------------------------- */

.measure-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  background: #31404f;
  border: 1px solid #46586a;
  border-radius: var(--radius);
}
.measure-readout {
  font-family: var(--mono); font-size: 11.5px; color: #ffd9a0;
  white-space: nowrap; padding-right: 4px;
}
.measure-bar button {
  padding: 3px 8px !important;
  font-size: 11.5px;
  border: 1px solid #56697c !important;
  border-radius: 4px;
  background: #3b4b5c !important;
}
.measure-bar button:hover { background: #48596b !important; }
.measure-bar button:disabled { opacity: .4; cursor: default; }

/* ------------------------------- dock -------------------------------- */

.dock { display: flex; flex-direction: column; min-height: 0; }

.drawer-profile { height: 268px; }

.inline-field {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--ink-2); white-space: nowrap;
}
.inline-field select {
  padding: 3px 5px; border: 1px solid var(--line);
  border-radius: 4px; font: inherit; font-size: 11px; background: #fff;
  max-width: 190px;
}

.mini-btn {
  padding: 3px 9px; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 4px; cursor: pointer; font: inherit; font-size: 11px; color: var(--ink-2);
}
.mini-btn:hover { background: var(--line-2); color: var(--ink); }
.mini-btn:disabled { opacity: .45; cursor: default; }

/* ---------------------------- profile chart -------------------------- */

.profile-body { display: flex; flex: 1; min-height: 0; }
.profile-chart { flex: 1; min-width: 0; position: relative; }
.profile-chart svg { display: block; width: 100%; height: 100%; }

.profile-stats {
  width: 196px; flex: none;
  border-left: 1px solid var(--line);
  padding: 8px 10px;
  overflow: auto;
  background: var(--panel-2);
}
.stat-row {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11.5px; padding: 2px 0;
}
.stat-row .k { color: var(--ink-3); }
.stat-row .v { font-family: var(--mono); font-weight: 550; }
.stat-group { border-top: 1px solid var(--line); margin-top: 7px; padding-top: 6px; }
.stat-group:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.grade-bar {
  display: flex; height: 11px; border-radius: 3px; overflow: hidden;
  margin: 5px 0 4px; border: 1px solid rgba(0,0,0,.12);
}
.grade-bar i { display: block; height: 100%; }
.grade-key { display: flex; flex-wrap: wrap; gap: 3px 8px; font-size: 10px; color: var(--ink-3); }
.grade-key span { display: inline-flex; align-items: center; gap: 3px; }
.grade-key i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.axis-label { font-size: 10px; fill: var(--ink-3); font-family: var(--mono); }
.grid-line { stroke: var(--line-2); stroke-width: 1; }
.axis-line { stroke: var(--line); stroke-width: 1; }
.profile-cursor { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }

.profile-tip {
  position: absolute; pointer-events: none;
  background: rgba(35, 48, 61, .94); color: #fff;
  border-radius: 4px; padding: 4px 8px;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.5;
  white-space: nowrap; z-index: 5;
}

.profile-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--ink-3); font-size: 12px; text-align: center; padding: 16px;
}

.popup-action {
  margin-top: 6px;
  padding: 4px 9px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  font: inherit; font-size: 11.5px; font-weight: 550;
  cursor: pointer;
}
.popup-action:hover { background: var(--accent); color: #fff; }

/* A link styled as a topbar button (e.g. "View as client"). */
.topbar-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: var(--radius);
  color: var(--topbar-ink); text-decoration: none;
  border: 1px solid transparent; white-space: nowrap;
}
.topbar-link:hover { background: #31404f; }

/* ---------------------------- sign-in gate ---------------------------- */
/* Used by both sites: the company password screen and the client login. */

/* Sign-in gate, shown instead of the app until the password is accepted. */
.gate {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--topbar);
}
.gate-card {
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow);
  padding: 26px 28px; width: min(360px, 92vw);
}
.gate-card h1 { margin: 0 0 4px; font-size: 17px; }
.gate-card p { margin: 0 0 16px; color: var(--ink-2); font-size: 12.5px; line-height: 1.5; }
.gate-card input {
  width: 100%; padding: 8px 10px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px;
}
.gate-card button { width: 100%; }
.gate-error { color: var(--danger); font-size: 12px; margin-top: 9px; min-height: 16px; }

/* ------------------------ centred company mark ------------------------ */

/*
 * Just the mark, at the far left, the way an application shows its own
 * identity. The window is for delivering work, so the company name lives
 * quietly in the status bar rather than competing with the map for the
 * middle of the chrome.
 */
.app-mark { display: flex; align-items: center; flex: none; }

.statusbar .company {
  font-family: var(--sans); font-weight: 600; color: var(--ink-2);
  letter-spacing: .2px;
}

/* ------------------------- what is open, right ------------------------ */

.context {
  display: inline-flex; flex-direction: column; align-items: flex-end;
  line-height: 1.25; max-width: 260px; overflow: hidden;
}
.context-client {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: #8fa6b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%;
}
.context-project {
  font-size: 12px; color: #dfe6ee; font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.context:empty, .context-client:empty, .context-project:empty { display: none; }

/* The map context earns the emphasis now that it is the only label. */
.context-project { font-size: 12.5px; }
