:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #667180;
  --line: #d9e0e7;
  --panel: #ffffff;
  --soft: #f5f7fa;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --shadow: 0 14px 36px rgba(22, 33, 44, 0.14);
  --sheet-height: 50dvh;
  --bhumi-width: 50vw;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

.leaflet-bhumiPersilPane-pane {
  mix-blend-mode: multiply;
}

body.is-locked {
  overflow: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(rgba(9, 22, 31, 0.52), rgba(9, 22, 31, 0.66)),
    url("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/12/2116/3239");
  background-size: cover;
  background-position: center;
  z-index: 3000;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(100%, 430px);
  display: grid;
  gap: 12px;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

.login-card h1 {
  font-size: 30px;
}

.login-copy {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  min-height: 42px;
  margin-top: 4px;
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
}

.primary-button:hover {
  border-color: #0b5f59;
  background: #0b5f59;
}

.sidebar {
  position: fixed;
  top: 14px;
  bottom: 14px;
  left: 14px;
  width: min(320px, calc(100vw - 28px));
  height: auto;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(217, 224, 231, 0.92);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(calc(-100% - 24px));
  transition: transform 180ms ease;
  z-index: 1200;
}

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

.sheet-grip {
  display: none;
}

.app-header {
  display: grid;
  gap: 4px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
  letter-spacing: 0;
}

.summary {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.panel,
.layer-section {
  display: grid;
  gap: 7px;
}

.wfs-panel {
  padding-top: 2px;
}

.wfs-form {
  display: grid;
  gap: 7px;
}

.wfs-inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #3f4b57;
  font-size: 12px;
  font-weight: 750;
}

.wfs-inline-check input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.label,
.panel-title {
  color: #3f4b57;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.with-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  outline: none;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #24313d;
  background: var(--soft);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  border-color: #9daab6;
  background: #edf2f6;
}

.logout-button,
.menu-close-button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.menu-close-button {
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.32);
  background: #eefaf7;
}

.layer-section {
  min-height: 0;
}

.layer-list {
  min-height: 0;
  overflow: auto;
  padding-right: 3px;
  display: grid;
  align-content: start;
  gap: 7px;
}

.layer-item {
  display: grid;
  grid-template-columns: 21px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.layer-item.loaded {
  border-color: rgba(15, 118, 110, 0.38);
  background: #f5fbfa;
}

.layer-item input {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.layer-name {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.layer-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.swatch {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.22);
}

.map-shell {
  position: fixed;
  inset: 0;
  min-width: 0;
  height: 100vh;
  transition: right 180ms ease;
}

body.surat-open .map-shell {
  right: var(--bhumi-width);
}

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

.status-bar {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: min(680px, calc(100vw - 370px));
  padding: 10px 12px;
  border: 1px solid rgba(217, 224, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 9px 24px rgba(22, 33, 44, 0.16);
  color: #3f4b57;
  font-size: 13px;
  z-index: 800;
}

.legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: none;
  max-width: 280px;
  padding: 11px;
  border: 1px solid rgba(217, 224, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 9px 24px rgba(22, 33, 44, 0.16);
  z-index: 800;
}

.legend.visible {
  display: none;
  gap: 7px;
}

.map-toolbar {
  position: static;
}

.map-action {
  position: absolute;
  z-index: 900;
  display: inline-grid;
  place-items: center;
  min-width: 74px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid rgba(217, 224, 231, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 9px 24px rgba(22, 33, 44, 0.16);
  color: #24313d;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.map-action:hover {
  border-color: #9daab6;
  background: #edf2f6;
}

.layer-toggle-button {
  left: calc(50% - 88px);
  bottom: 16px;
  transform: translateX(-50%);
}

.fullscreen-button {
  top: 16px;
  right: 16px;
}

.surat-button {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}

.nib-button {
  left: calc(50% + 88px);
  bottom: 16px;
  transform: translateX(-50%);
}

body.menu-open .layer-toggle-button {
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.38);
  background: #eefaf7;
}

body.surat-open .surat-button {
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.38);
  background: #eefaf7;
}

body.nib-open .nib-button {
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.38);
  background: #eefaf7;
}

.bhumi-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--bhumi-width);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 10px;
  padding: 14px;
  overflow: hidden;
  border: 0;
  border-left: 1px solid rgba(217, 224, 231, 0.92);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 1220;
}

body.surat-open .bhumi-panel {
  transform: translateX(0);
}

.bhumi-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.bhumi-panel h2 {
  margin: 3px 0 0;
  font-size: 21px;
  line-height: 1.15;
}

.bhumi-close-button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.32);
  background: #eefaf7;
  font-size: 12px;
}

.bhumi-card,
.coordinate-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bhumi-card {
  padding: 12px;
}

.bhumi-note {
  margin: 0;
  color: #3f4b57;
  font-size: 13px;
  line-height: 1.5;
}

.coordinate-card {
  display: grid;
  gap: 6px;
  padding: 13px;
  background: #f5fbfa;
  border-color: rgba(15, 118, 110, 0.26);
}

.coordinate-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.coordinate-card strong {
  font-size: 20px;
  line-height: 1.2;
  word-break: break-word;
}

.coordinate-card small {
  color: #526171;
  font-size: 12px;
  line-height: 1.35;
}

.bhumi-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-button,
.primary-button.compact {
  width: 100%;
  min-height: 40px;
}

.secondary-button {
  color: #24313d;
  background: #f8fafc;
}

.primary-button.compact {
  margin-top: 0;
}

.bhumi-steps {
  margin: 0;
  padding-left: 20px;
  color: #3f4b57;
  font-size: 13px;
  line-height: 1.55;
}

.bhumi-steps li + li {
  margin-top: 6px;
}

.bhumi-frame-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.bhumi-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.nib-panel {
  position: fixed;
  top: 14px;
  bottom: 14px;
  left: 14px;
  width: min(360px, calc(100vw - 28px));
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
  border: 1px solid rgba(217, 224, 231, 0.92);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
  transform: translateX(calc(-100% - 28px));
  transition: transform 180ms ease;
  z-index: 1230;
}

body.nib-open .nib-panel {
  transform: translateX(0);
}

.nib-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.nib-panel h2 {
  margin: 3px 0 0;
  font-size: 21px;
  line-height: 1.15;
}

.nib-close-button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.32);
  background: #eefaf7;
  font-size: 12px;
}

.nib-form {
  display: grid;
  gap: 8px;
}

.nib-location-fields,
.nib-hak-field {
  display: grid;
  gap: 8px;
}

.nib-inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #3f4b57;
  font-size: 13px;
  font-weight: 750;
}

.nib-inline-check input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.nib-result {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #3f4b57;
  font-size: 13px;
  line-height: 1.45;
}

.nib-number-input {
  min-height: 82px;
  resize: vertical;
  line-height: 1.4;
}

.nib-result-card {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.nib-result-card:first-child {
  padding-top: 0;
}

.nib-result-card:last-child {
  border-bottom: 0;
}

.nib-result-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 850;
  color: var(--ink);
}

.nib-result-grid {
  display: grid;
  gap: 6px;
}

.nib-result-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
}

.nib-result-key {
  color: var(--muted);
  font-weight: 800;
}

.nib-result-error {
  color: var(--danger);
  font-weight: 800;
}

.nib-result-success {
  color: var(--accent);
  font-weight: 800;
}

.bhumi-frame-fallback {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(217, 224, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: #526171;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}

.legend-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #edf2f6;
  color: #40505e;
  font-size: 11px;
  font-weight: 800;
}

.leaflet-popup-content {
  min-width: 230px;
  max-width: 360px;
}

.popup-title {
  margin: 0 0 8px;
  font-weight: 850;
  line-height: 1.25;
}

.popup-grid {
  display: grid;
  gap: 5px;
}

.bhumi-info-card + .bhumi-info-card {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.popup-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  font-size: 12px;
  line-height: 1.35;
}

.popup-key {
  color: var(--muted);
  font-weight: 750;
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  body {
    display: block;
    background: #0a141b;
  }

  .sidebar {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(var(--sheet-height), 480px);
    min-height: 340px;
    grid-template-rows: auto auto 1fr;
    gap: 6px;
    padding: 7px 10px calc(10px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    border-right: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -14px 42px rgba(7, 18, 28, 0.3);
    backdrop-filter: blur(18px);
    transition: transform 180ms ease;
    transform: translateY(calc(100% + 16px));
    z-index: 1200;
  }

  body.menu-open .sidebar {
    transform: translateY(0);
  }

  body.map-focused .sidebar {
    transform: translateY(calc(100% + 16px));
  }

  .map-shell {
    position: fixed;
    inset: 0;
    height: 100dvh;
    z-index: 1;
  }

  body.surat-open .map-shell {
    right: 0;
    bottom: 50dvh;
  }

  .sheet-grip {
    display: block;
    width: 44px;
    height: 4px;
    margin: 0 auto 1px;
    border-radius: 999px;
    background: #b8c2cc;
  }

  .app-header {
    gap: 2px;
  }

  .header-top {
    min-height: 24px;
  }

  h1 {
    font-size: 15px;
    line-height: 1.15;
  }

  .summary {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.2;
  }

  .panel {
    gap: 3px;
  }

  .wfs-form {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }

  .wfs-form .input:first-child,
  .wfs-form .primary-button {
    grid-column: 1 / -1;
  }

  .wfs-inline-check {
    font-size: 11px;
  }

  .label,
  .panel-title {
    font-size: 10px;
  }

  .input {
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 9px;
    font-size: 14px;
  }

  button {
    min-height: 38px;
    border-radius: 10px;
    font-size: 13px;
  }

  .logout-button,
  .menu-close-button {
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
  }

  .layer-section {
    min-height: 0;
    overflow: hidden;
  }

  .layer-list {
    gap: 6px;
    padding: 1px 4px 10px 0;
    -webkit-overflow-scrolling: touch;
  }

  .layer-item {
    grid-template-columns: 25px 1fr auto;
    gap: 7px;
    padding: 8px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(22, 33, 44, 0.08);
  }

  .layer-item input {
    width: 20px;
    height: 20px;
  }

  .layer-name {
    font-size: 13px;
  }

  .layer-meta {
    margin-top: 2px;
    font-size: 11px;
  }

  .swatch {
    width: 16px;
    height: 16px;
  }

  .login-card h1 {
    font-size: 24px;
  }

  .login-screen {
    align-items: end;
    padding: 16px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .login-card {
    width: 100%;
    gap: 11px;
    padding: 22px;
    border-radius: 18px;
  }

  .status-bar {
    left: 12px;
    right: 12px;
    bottom: calc(58px + env(safe-area-inset-bottom));
    max-width: none;
    padding: 9px 11px;
    border-radius: 999px;
    font-size: 12px;
    text-align: center;
    z-index: 1100;
  }

  body.surat-open .status-bar {
    bottom: calc(42dvh + 10px);
  }

  body.menu-open .status-bar {
    bottom: calc(min(var(--sheet-height), 480px) + 10px);
  }

  body.map-focused .status-bar {
    bottom: 54px;
  }

  .map-toolbar {
    position: static;
  }

  .map-action {
    min-width: 58px;
    min-height: 36px;
    padding: 7px 10px;
    font-size: 12px;
    z-index: 1150;
  }

  .layer-toggle-button {
    left: calc(50% - 70px);
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    min-width: 64px;
    transform: translateX(-50%);
  }

  .fullscreen-button {
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
  }

  .surat-button {
    left: 50%;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    min-width: 64px;
    transform: translateX(-50%);
  }

  .nib-button {
    left: calc(50% + 70px);
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    min-width: 64px;
    transform: translateX(-50%);
  }

  .bhumi-panel {
    top: 50dvh;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: none;
    grid-template-rows: auto auto auto 1fr;
    gap: 7px;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 0 -14px 42px rgba(7, 18, 28, 0.3);
    transform: translateY(calc(100% + 16px));
    z-index: 1240;
  }

  body.surat-open .bhumi-panel {
    transform: translateY(0);
  }

  .bhumi-panel h2 {
    font-size: 16px;
  }

  .bhumi-card {
    padding: 9px;
  }

  .bhumi-note,
  .bhumi-steps {
    font-size: 12px;
    line-height: 1.35;
  }

  .coordinate-card {
    gap: 4px;
    padding: 10px;
  }

  .coordinate-card strong {
    font-size: 16px;
  }

  .bhumi-actions {
    grid-template-columns: 1fr 1fr;
  }

  .secondary-button,
  .primary-button.compact {
    min-height: 36px;
    font-size: 12px;
  }

  .bhumi-frame-fallback {
    left: 10px;
    right: 10px;
    bottom: 10px;
    font-size: 11px;
  }

  .nib-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(58dvh, 520px);
    grid-template-rows: auto auto 1fr;
    gap: 8px;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    transform: translateY(calc(100% + 16px));
    z-index: 1260;
  }

  body.nib-open .nib-panel {
    transform: translateY(0);
  }

  .nib-panel h2 {
    font-size: 16px;
  }

  .nib-form {
    gap: 6px;
  }

  .nib-result {
    padding: 10px;
    font-size: 12px;
  }

  .legend {
    display: none !important;
  }

  .leaflet-control-layers {
    display: none;
  }

  .leaflet-top .leaflet-control {
    margin-top: calc(10px + env(safe-area-inset-top));
  }

  .leaflet-left .leaflet-control {
    margin-left: 10px;
  }

  .leaflet-control-zoom a {
    width: 38px;
    height: 38px;
    line-height: 38px;
  }
}

@media (max-width: 420px) {
  :root {
    --sheet-height: 52dvh;
  }

  .sidebar {
    min-height: 360px;
    padding-inline: 10px;
  }

  .summary {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}
