:root {
  --ink: #1e293b;
  --muted: #64748b;
  --line: #dbe3ec;
  --panel: #ffffff;
  --bg: #eef3f7;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(15, 23, 42, .32), rgba(15, 23, 42, .62)),
    url("https://images.unsplash.com/photo-1569336415962-a4bd9f69c07a?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.login-panel {
  width: min(440px, 100%);
  padding: 32px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  color: #fff;
  background: var(--primary);
  border-radius: 8px;
  font-size: 1.5rem;
}

.login-panel h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 750;
}

.login-panel p {
  margin: 8px 0 24px;
  color: var(--muted);
}

.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary-dark);
  --bs-btn-hover-border-color: var(--primary-dark);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.app-title {
  font-weight: 760;
  line-height: 1.1;
}

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

.brand-logos img {
  width: auto;
  max-width: 58px;
  height: 42px;
  object-fit: contain;
}

.brand-logos img[src$="geotech.png"] {
  max-width: 72px;
}

.app-subtitle {
  color: var(--muted);
  font-size: .86rem;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
}

.workspace {
  min-height: 0;
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr) minmax(360px, 430px);
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  background: #f8fafc;
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 18px;
}

.form-label,
.section-title {
  color: #475569;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.metric {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: .8rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.15rem;
}

.group-list {
  display: grid;
  gap: 8px;
}

.group-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.group-item.active {
  border-color: var(--primary);
  background: #ecfdf5;
}

.group-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.user-admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, .8fr) minmax(360px, 1.2fr);
  gap: 18px;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-list-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.user-list-item.active {
  border-color: var(--primary);
  background: #ecfdf5;
}

.user-list-item strong,
.user-list-item small {
  display: block;
}

.user-list-item small {
  color: var(--muted);
}

.role-pill {
  align-self: start;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef3f7;
  color: #475569;
  font-size: .72rem;
  font-weight: 700;
}

.role-pill.admin {
  background: #ccfbf1;
  color: #0f766e;
}

.layer-controls {
  display: grid;
  gap: 6px;
}

.layer-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: .86rem;
}

.link-mode-status {
  margin-top: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: #fff;
  font-size: .78rem;
}

.link-mode-status.active {
  color: #115e59;
  border-color: #14b8a6;
  background: #ecfdf5;
}

.main-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(320px, 58%) minmax(220px, 42%);
  overflow: hidden;
}

.map-wrap {
  position: relative;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.map-tools {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
}

.data-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #fff;
  border-top: 1px solid var(--line);
  overflow: hidden;
}

.table-toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.data-pane .table-responsive {
  min-height: 0;
  overflow: auto;
}

.data-pane .table {
  margin-bottom: 0;
}

.data-pane thead th {
  position: sticky;
  top: 0;
  z-index: 5;
}

.table th {
  color: #475569;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .02em;
  background: #f8fafc;
}

.table td {
  vertical-align: middle;
}

.table tr.selected-row td {
  background: #ecfdf5;
}

.code-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  color: #134e4a;
  background: #ccfbf1;
  font-weight: 700;
  white-space: nowrap;
}

.detail-canvas {
  --bs-offcanvas-width: min(720px, 100vw);
}

.detail-panel {
  min-width: 0;
  min-height: 0;
  max-height: none;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #fff;
  border-left: 1px solid var(--line);
}

.detail-panel-header {
  min-height: 74px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.detail-panel-header h2 {
  margin: 2px 0;
  font-size: .98rem;
  font-weight: 760;
  line-height: 1.25;
}

.detail-panel-body {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 14px;
}

.empty-state {
  min-height: 320px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state i {
  color: #94a3b8;
  font-size: 2rem;
}

.detail-code {
  color: var(--muted);
  font-size: .9rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-section {
  margin-bottom: 10px;
}

.detail-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: #334155;
  font-size: .9rem;
  font-weight: 760;
}

.detail-section h3 i {
  color: var(--primary);
}

.detail-field {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.layer-controls label.wms-context {
  border-color: #99f6e4;
  background: #f0fdfa;
  color: #115e59;
  font-weight: 650;
}

.detail-field span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-field strong {
  display: block;
  margin-top: 4px;
  font-size: .92rem;
  overflow-wrap: anywhere;
}

.detail-field.wide {
  grid-column: 1 / -1;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  font-size: .78rem;
  white-space: nowrap;
}

.status-pill.active {
  border-color: #14b8a6;
  background: #ecfdf5;
  color: #115e59;
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.compact-item:hover {
  border-color: var(--primary);
  background: #f0fdfa;
}

.compact-item-main {
  min-width: 0;
}

.compact-item-main strong,
.compact-item-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-item-main span {
  color: var(--muted);
  font-size: .82rem;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 8px;
}

.detail-tabs {
  flex-wrap: wrap;
  gap: 2px;
  overflow: visible;
  border-bottom: 1px solid #0f2744;
}

.detail-tabs .nav-link {
  min-height: 26px;
  padding: 4px 7px;
  border: 0;
  border-radius: 0;
  color: #17324f;
  font-size: .72rem;
  font-weight: 760;
  white-space: nowrap;
}

.detail-tabs .nav-link.active {
  color: #fff;
  background: #17324f;
}

.detail-tab-content {
  padding-top: 8px;
}

.kv-section {
  margin-bottom: 9px;
}

.kv-section h3 {
  margin: 0;
  padding: 5px 8px;
  color: #17324f;
  background: #eef3f7;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  font-size: .78rem;
  font-weight: 780;
  text-transform: uppercase;
}

.kv-section h3:empty {
  display: none;
}

.kv-list {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  background: #fff;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(112px, 38%) minmax(0, 1fr);
  min-height: 27px;
  border-top: 1px solid #edf2f7;
}

.kv-row:first-child {
  border-top: 0;
}

.kv-row dt,
.kv-row dd {
  margin: 0;
  padding: 5px 7px;
  font-size: .8rem;
  line-height: 1.25;
}

.kv-row dt {
  color: #475569;
  background: #fbfdff;
  border-right: 1px solid #edf2f7;
  font-weight: 700;
}

.kv-row dd {
  color: #0f172a;
  overflow-wrap: anywhere;
}

.mini-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
}

.mini-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: .78rem;
}

.mini-table th,
.mini-table td {
  padding: 5px 7px;
  border-top: 1px solid #edf2f7;
  border-right: 1px solid #edf2f7;
  vertical-align: top;
}

.mini-table th {
  color: #475569;
  background: #fbfdff;
  font-weight: 760;
}

.dense-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  background: #fff;
}

.dense-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border: 0;
  border-top: 1px solid #edf2f7;
  background: #fff;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
}

.dense-item:first-child {
  border-top: 0;
}

.dense-item:hover {
  background: #f0fdfa;
}

.doc-item {
  grid-template-columns: minmax(0, 1fr) 30px;
}

.doc-link {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.dense-item span,
.dense-item small,
.doc-link span,
.doc-link small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dense-item small {
  color: var(--muted);
  font-size: .75rem;
}

.as-button {
  font: inherit;
  cursor: pointer;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  background: #fff;
}

.upload-inline {
  display: grid;
  grid-template-columns: minmax(92px, 112px) minmax(0, .8fr) minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
}

.file-picker {
  min-width: 0;
  height: 31px;
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  font-size: .78rem;
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-status {
  min-height: 18px;
  margin-top: 6px;
  color: var(--muted);
  font-size: .78rem;
}

.upload-status.success {
  color: #0f766e;
}

.upload-status.error {
  color: #b91c1c;
}

.upload-status.active {
  color: #1d4ed8;
}

@media (max-width: 760px) {
  .upload-inline {
    grid-template-columns: 1fr;
  }

  .upload-inline .btn {
    justify-self: end;
  }
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.photo-grid a {
  display: grid;
  gap: 4px;
  color: var(--ink);
  text-decoration: none;
}

.photo-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.photo-grid span,
.detail-empty {
  color: var(--muted);
  font-size: .8rem;
}

.gis-toolbox {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  background: #fff;
}

.gis-layer-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.gis-layer-buttons .btn,
.gis-link-btn {
  --bs-btn-padding-y: .16rem;
  --bs-btn-padding-x: .38rem;
  --bs-btn-font-size: .72rem;
}

.gis-hint {
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.22;
}

#map.link-mode-map {
  cursor: crosshair;
}

.btn-mini {
  --bs-btn-padding-y: .12rem;
  --bs-btn-padding-x: .32rem;
  --bs-btn-font-size: .75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

.leaflet-popup-content {
  margin: 10px 12px;
}

@media (max-width: 991.98px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    display: block;
    overflow: visible;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 68px);
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    position: fixed;
    z-index: 1020;
    top: 68px;
    bottom: 0;
    left: 0;
    width: min(340px, 88vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 20px 0 40px rgba(15, 23, 42, .18);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-pane {
    min-height: calc(100vh - 68px);
    grid-template-rows: 52vh minmax(320px, 48vh);
  }

  .detail-panel {
    display: none;
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }
}

@media (max-width: 575.98px) {
  .topbar {
    height: auto;
    min-height: 68px;
    align-items: flex-start;
    padding: 12px;
  }

  .topbar .btn span {
    display: none;
  }

  .app-title {
    font-size: .98rem;
  }

  .sidebar {
    top: 76px;
  }

  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
