/* ============================================================
   Water Quality Platform — teal theme matching the reference UI
   ============================================================ */
:root {
  --teal: #3e6f63;
  --teal-dark: #33594f;
  --teal-light: #eaf2f0;
  --accent: #e8896a;
  --accent-light: #f6c1ab;
  --text: #253230;
  --muted: #6b7f7b;
  --border: #cfdad7;
  --danger: #c0392b;
  --ok: #2e7d32;
  --radius: 8px;
  --sidebar-w: 340px;
  --navbar-h: 60px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: #f4f7f6;
}

/* ---------- Navbar ---------- */
.navbar {
  position: sticky; top: 0; z-index: 1200;
  height: var(--navbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--teal); color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.navbar-left, .navbar-right { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand small { display: block; font-size: .68rem; opacity: .85; letter-spacing: .4px; }
.brand strong { font-size: 1.05rem; letter-spacing: .5px; }
.icon-btn {
  background: rgba(255,255,255,.12); color: #fff; border: none;
  width: 38px; height: 38px; border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.icon-btn:hover { background: rgba(255,255,255,.22); }
.brand-icon { height: 34px; width: auto; }
.nav-link { color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.15); }
.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px; background: rgba(255,255,255,.12);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary .fa-circle-user { font-size: 1.15rem; }
.user-menu summary .summary-caret { font-size: .75rem; transition: transform .2s; }
.user-menu[open] summary .summary-caret { transform: rotate(180deg); }
.user-menu-panel {
  position: absolute; right: 0; top: 110%;
  background: #fff; color: var(--text); border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(0,0,0,.18); min-width: 200px; overflow: hidden;
}
.user-menu-panel a, .user-menu-panel button {
  display: block; width: 100%; text-align: left; padding: 10px 14px;
  background: none; border: none; color: var(--text);
  text-decoration: none; font: inherit; cursor: pointer;
}
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--teal-light); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius); cursor: pointer;
  padding: 10px 16px; font: inherit; font-weight: 600; text-decoration: none;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-outline { background: #fff; color: var(--teal); border: 1.5px solid var(--teal); }
.btn-outline:hover { background: var(--teal-light); }
.btn-outline-light { background: transparent; color: #fff; border: 1.5px solid rgba(255,255,255,.7); border-radius: 6px; padding: 8px 14px; font-weight: 600; letter-spacing: .5px; }
.btn-outline-light:hover { background: rgba(255,255,255,.15); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .85rem; border-radius: 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Map layout ---------- */
.map-layout {
  display: flex; height: calc(100vh - var(--navbar-h)); overflow: hidden;
}
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: #fff; border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable;
  padding: 10px 5px 0px 15px;
  transition: margin-left .25s ease;
}
.map-layout.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
#map { flex: 1; min-width: 0; }

.panel-section { margin-bottom: 10px; }
.panel-section > h2 {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  font-size: 1.02rem; color: var(--text); 
  margin: 6px 0 14px;
  padding: 8px;
  cursor: pointer; user-select: none;
  border-left: 2px solid transparent; border-radius: 4px;
  transition: background .15s ease, border-left-color .15s ease;
}
.panel-section > h2:hover { background: rgba(0, 0, 0, .04); border-left-color: var(--teal); }
.panel-section > h2 .sec-icon { color: var(--teal); flex: 0 0 auto; font-size: 1.15rem; }
.panel-section > h2 .sec-title { flex: 1; }
.chev-btn {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent !important; color: var(--teal);
  font-size: .8rem; transition: transform .25s ease, background .2s, color .2s;
}
.panel-section > h2:hover .chev-btn { background: var(--teal);}
.panel-section.closed > h2 .chev-btn { transform: rotate(180deg); }
.panel-section.closed .panel-body { display: none; }
.panel-body { display: flex; flex-direction: column; gap: 20px; padding-bottom: 40px; padding-right: 10px; padding-left: 20px;}

/* Outlined (material-like) fields */
.field { position: relative; }
.field > label {
  position: absolute; top: -8px; left: 10px; background: #fff;
  padding: 0 5px; font-size: .72rem; color: var(--muted); letter-spacing: .3px;
}
.field select, .field input, .field textarea {
  width: 100%; padding: 11px 10px; font: inherit; color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: #fff; outline: none;
}
.field select:focus, .field input:focus, .field textarea:focus { border-color: var(--teal); }
.field .err { color: var(--danger); font-size: .78rem; margin-top: 3px; display: block; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.checkbox-list {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 8px 6px 8px 10px; max-height: 250px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.checkbox-list label {
  display: flex; gap: 10px; align-items: center;
  font-size: 1rem; cursor: pointer; padding: 4px 0;
}
.checkbox-list input[type="checkbox"] {
  flex: 0 0 auto; width: 18px; height: 18px; margin: 0;
  accent-color: var(--teal);
}
.checkbox-list label strong { font-size: 1.05rem; }

/* ---------- Leaflet extras ---------- */
.legend {
  background: #fff; padding: 10px 12px; border-radius: var(--radius);
  box-shadow: 0 1px 6px rgba(0,0,0,.25); font-size: .82rem; line-height: 1.5;
}
.legend h4 { margin: 0 0 6px; font-size: .85rem; color: var(--teal-dark); }
.legend .row { display: flex; align-items: center; gap: 8px; }
.legend .swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.leaflet-popup-content { margin: 14px 16px; }
.popup { word-wrap: break-word; max-width: 200px;}
.popup-site {
  margin: 0 0 8px; color: var(--teal-dark);
  font-size: 1.15rem; text-align: center;
}
.popup-value {
  text-align: center; font-size: 1.65rem; font-weight: 700;
  color: var(--text); margin: 0 0 12px; line-height: 1.15;
}
.popup-value .popup-unit { font-size: 1rem; font-weight: 600; color: var(--muted); }
.popup dl { margin: 0 0 10px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: .86rem; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; font-weight: 600; word-break: break-word; }

/* ---------- Cards / pages ---------- */
.page { padding: 22px; max-width: 1250px; margin: 0 auto; }
.card {
  background: #fff; border-radius: 10px; border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 18px 20px; margin-bottom: 18px;
}
.card h1, .card h2 { margin-top: 0; color: var(--teal-dark); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=search] {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius);
  min-width: 220px; font: inherit;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .9rem;
}
table.data th {
  background: var(--accent-light); color: #5c3a2e; text-align: left;
  padding: 9px 10px; border-bottom: 2px solid var(--accent);
  white-space: nowrap;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:hover td { background: var(--teal-light); }
table.data .actions { white-space: nowrap; text-align: right; }
.pagination { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: .88rem; color: var(--muted); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,35,32,.55);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 1500; padding: 4vh 14px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 640px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal.modal-lg { max-width: 980px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; color: var(--teal-dark); letter-spacing: .5px; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 14px; }
.form-grid .span-2 { grid-column: span 2; }

/* ---------- Alerts / toasts ---------- */
.alert { border-radius: var(--radius); padding: 11px 14px; font-size: .9rem; }
.alert-warning { background: #fdf3e3; border: 1px solid #e9c46a; color: #7a5b13; }
.alert-error { background: #fdecea; border: 1px solid #f5b7b1; color: var(--danger); }
.alert-success { background: #e8f5e9; border: 1px solid #a5d6a7; color: var(--ok); }
#toast-area { position: fixed; top: calc(var(--navbar-h) + 10px); right: 14px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #fff; border-left: 4px solid var(--teal); border-radius: 6px;
  box-shadow: 0 3px 14px rgba(0,0,0,.18); padding: 11px 16px; font-size: .9rem;
  animation: fadein .25s;
}
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px);} to { opacity: 1; } }

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - var(--navbar-h));
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(150deg, var(--teal-light), #f4f7f6 60%);
}
.login-card {
  background: #fff; border-radius: 12px; box-shadow: 0 8px 34px rgba(0,0,0,.14);
  width: 100%; max-width: 430px; padding: 26px 30px 30px;
}
.login-card .login-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 22px;
}
.login-card h1 { margin: 0; font-size: 1.25rem; letter-spacing: .5px; color: var(--text); }
.login-card label.f-label { color: var(--teal); font-weight: 600; display: block; margin: 16px 0 7px; }
.login-card .input-wrap { position: relative; }
.login-card input[type=text], .login-card input[type=password] {
  width: 100%; padding: 12px 42px 12px 12px; font: inherit;
  border: 1.5px solid var(--border); border-radius: var(--radius);
}
.login-card input:focus { outline: none; border-color: var(--teal); }
.login-card .eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px;
}
.login-card .btn-primary { margin-top: 24px; letter-spacing: .3px; }
.login-links { margin-top: 18px; font-size: .92rem; }
.login-links a { color: var(--teal); }

/* ---------- Manage layout ---------- */
.manage-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.manage-tabs a {
  padding: 10px 18px; text-decoration: none; color: var(--muted); font-weight: 600;
  border-radius: 8px 8px 0 0; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.manage-tabs a.active { color: var(--teal-dark); border-bottom-color: var(--teal); background: #fff; }
.manage-tabs a:hover { color: var(--teal-dark); }
.map-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.mini-map { height: 380px; border-radius: var(--radius); border: 1px solid var(--border); }
.muted { color: var(--muted); font-size: .85rem; }
a.ref-link { color: var(--teal); }

/* ---------- Ingest wizard ---------- */
.wizard-steps {
  display: flex; flex-wrap: wrap; gap: 6px; list-style: none;
  padding: 0; margin: 0 0 20px; counter-reset: none;
}
.wizard-steps li {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 150px;
  padding: 10px 12px; border-radius: var(--radius); font-weight: 600;
  color: var(--muted); background: var(--teal-light);
  border: 1.5px solid transparent; font-size: .9rem;
}
.wizard-steps li .wz-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto;
  background: #fff; color: var(--muted); font-size: .85rem;
  border: 1.5px solid var(--border);
}
.wizard-steps li.active { color: var(--teal-dark); border-color: var(--teal); background: #fff; }
.wizard-steps li.active .wz-num { background: var(--teal); color: #fff; border-color: var(--teal); }
.wizard-steps li.done .wz-num { background: var(--ok); color: #fff; border-color: var(--ok); }
.wizard-panel { min-height: 200px; }
.wizard-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.wizard-nav {
  display: flex; align-items: center; gap: 10px; margin-top: 22px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.wizard-nav .spacer { flex: 1; }
.wizard-panel table.data input:not([type="checkbox"]):not([type="radio"]),
.wizard-panel table.data select {
  width: 100%; padding: 6px 7px; font: inherit; color: var(--text);
  border: 1.5px solid var(--border); border-radius: 6px; background: #fff;
  min-width: 78px;
}
.wizard-panel table.data input[type="checkbox"],
.wizard-panel table.data input[type="radio"] {
  width: 16px; height: 16px; accent-color: var(--teal);
}
.wizard-panel table.data input:focus,
.wizard-panel table.data select:focus { outline: none; border-color: var(--teal); }
.wizard-panel table.data input:disabled { background: var(--teal-light); color: var(--muted); }
.wizard-panel table.data td { padding: 6px 7px; }
.wizard-panel table.data input.cell-error { border-color: var(--danger); background: #fdecea; }
.row-status {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: .72rem; font-weight: 700; letter-spacing: .3px;
}
.row-status.new { background: #e8f5e9; color: var(--ok); }
.row-status.existing { background: #eef1fb; color: #3f51b5; }
.row-select { accent-color: var(--teal); width: 16px; height: 16px; }
.ref-cell { display: flex; align-items: center; gap: 6px; }
.ref-cell .ref-text { font-size: .82rem; color: var(--text); }
.ref-cell .ref-none { font-size: .82rem; color: var(--muted); font-style: italic; }
.var-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px; max-height: 460px; overflow-y: auto; padding: 2px;
}
.var-item {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px;
  border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.var-item:hover { border-color: var(--teal); background: var(--teal-light); }
.var-item.selected { border-color: var(--teal); background: var(--teal-light); }
.var-item input { margin-top: 3px; accent-color: var(--teal); width: 16px; height: 16px; }
.var-item .var-meta { font-size: .78rem; color: var(--muted); }
.review-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 4px 0 18px; }
.review-tile {
  background: var(--teal-light); border-radius: var(--radius); padding: 14px 16px;
  border: 1px solid var(--border);
}
.review-tile .num { font-size: 1.7rem; font-weight: 700; color: var(--teal-dark); line-height: 1.1; }
.review-tile .lbl { font-size: .8rem; color: var(--muted); }
.result-ok { text-align: center; padding: 30px 10px; }
.result-ok .fa-circle-check { font-size: 3rem; color: var(--ok); }

/* ---------- Dataset (wide table) ---------- */
#ds-filter-panel { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
#ds-filter-panel > h2 { margin: 0; }
#ds-filter-panel .panel-body { padding: 0 14px 14px; gap: 14px; }
.ds-filter-grid { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 18px; align-items: start; }
.ds-filter-col { display: flex; flex-direction: column; gap: 18px; }
.ds-filter-actions { display: flex; gap: 10px; }

.ds-table-wrap { max-height: 66vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.ds-table { font-size: .82rem; }
.ds-table th, .ds-table td { white-space: nowrap; }
/* Sticky header row + two pinned identifier columns (site_id, sample_id).
   sample_id's left offset is set at runtime (applyStickyOffset). */
.ds-table thead th { position: sticky; top: 0; z-index: 2; }
.ds-table th:first-child, .ds-table td:first-child { position: sticky; left: 0; }
.ds-table th.ds-sticky-2, .ds-table td.ds-sticky-2 { position: sticky; }
.ds-table thead th:first-child, .ds-table thead th.ds-sticky-2 { z-index: 3; }
.ds-table td:first-child, .ds-table td.ds-sticky-2 { background: #fff; z-index: 1; }
.ds-table tr:hover td:first-child, .ds-table tr:hover td.ds-sticky-2 { background: var(--teal-light); }

.ds-var-h { text-align: center; }
.ds-var-h .ds-unit { display: block; font-weight: 400; font-size: .72rem; color: #7a5b3e; }
.ds-var-h .ds-vid { display: block; font-weight: 400; font-size: .66rem; color: var(--muted); }
.ds-ro { color: var(--muted); }
.ds-ro:first-child, .ds-table td.ds-sticky-2 { color: var(--text); font-weight: 600; }
.ds-cell { text-align: right; }
.ds-cell.ds-editable { cursor: pointer; }
.ds-cell.ds-editable:hover { background: var(--teal-light); outline: 2px solid var(--teal); outline-offset: -2px; }
.ds-cell.ds-editable.ds-empty::after { content: "+"; color: var(--border); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .form-grid, .map-form-grid, .wizard-grid, .ds-filter-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .brand small { display: none; }
}
@media (max-width: 720px) {
  .sidebar {
    position: absolute; z-index: 1100; height: calc(100vh - var(--navbar-h));
    box-shadow: 4px 0 18px rgba(0,0,0,.2);
  }
  .map-layout { position: relative; }
  .page { padding: 12px; }
  .toolbar input[type=search] { min-width: 140px; flex: 1; }
}
