:root {
  --panel: #ffffff;
  --panel-muted: #f1eee7;
  --text: #22211d;
  --muted: #6d685f;
  --border: #d8d3c7;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b42318;
  --focus: rgba(37, 99, 235, 0.22);
  --shadow: 0 10px 28px rgba(34, 33, 29, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell,
.map-area,
#viewDiv {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #ece8df;
  color: var(--text);
  font-family: "Aptos", "Tahoma", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell,
.map-area {
  position: relative;
}

.map-search {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  left: 12px;
  z-index: 4;
}

.search-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  direction: rtl;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  outline: none;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%236d685f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: left 14px center;
  background-repeat: no-repeat;
  background-size: 14px;
  padding-left: 40px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.map-search input,
.map-search button {
  box-shadow: var(--shadow);
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  outline: none;
  padding: 8px 13px;
  transition: background 140ms ease, border-color 140ms ease, opacity 140ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:focus-visible {
  box-shadow: 0 0 0 3px var(--focus);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button,
.secondary-button {
  border-color: var(--border);
  background: #fff;
  color: var(--text);
}

.icon-button:hover,
.secondary-button:hover {
  border-color: #bcb5a7;
  background: var(--panel-muted);
}

.icon-only-button {
  display: grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.icon-only-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  width: min(88vw, 380px);
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: max(18px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  transform: translateX(100%);
  transition: transform 180ms ease;
}

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

.panel-backdrop {
  position: fixed;
  top: 0;
  right: min(88vw, 380px);
  bottom: 0;
  left: 0;
  z-index: 5;
  display: none;
  min-height: 0;
  border: 0;
  border-radius: 0;
  appearance: none;
  background: rgba(34, 33, 29, 0.34);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.panel-backdrop.is-open {
  display: block;
}

.panel-backdrop:focus,
.panel-backdrop:focus-visible,
.unit-zones-backdrop:focus,
.unit-zones-backdrop:focus-visible {
  outline: none;
  box-shadow: none;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

h1 {
  margin: 0 0 5px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

label {
  display: block;
  margin-bottom: 7px;
  color: #3f3b35;
  font-size: 13px;
  font-weight: 700;
}

.filters-section,
.actions-section {
  display: grid;
  gap: 12px;
}

.summary-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
}

.summary-section div {
  min-width: 0;
  padding: 12px;
}

.summary-section div + div {
  border-right: 1px solid var(--border);
}

.summary-section span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.summary-section strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 20px;
}

.results-list {
  display: none;
  max-height: min(310px, calc(100vh - 84px));
  overflow: auto;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.results-list.is-open {
  display: block;
}

.result-item {
  width: 100%;
  min-height: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  text-align: right;
  box-shadow: none;
}

.result-item:hover,
.result-item:focus {
  background: var(--panel-muted);
  color: var(--text);
}

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

.result-main {
  display: block;
  font-weight: 700;
}

.result-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.map-status {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 64px));
  left: 50%;
  bottom: auto;
  transform: translateX(-50%);
  max-width: min(360px, calc(100% - 24px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: rgba(58, 43, 38, 0.82);
  display: none;
  font-size: 12px;
  padding: 7px 10px;
  text-align: center;
  z-index: 4;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.08);
}

.map-status.is-visible {
  display: block;
}

.map-status.is-error {
  border-color: rgba(180, 35, 24, 0.22);
  background: rgba(255, 255, 255, 0.78);
  color: rgba(180, 35, 24, 0.82);
}

.unit-zones-button {
  position: absolute;
  left: 12px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 11px;
}

.unit-zones-button:hover,
.unit-zones-button:focus-visible {
  border-color: #bcb5a7;
  background: #fff;
  color: var(--text);
}

.unit-zones-button.is-muted {
  color: var(--muted);
}

.unit-zones-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b42318;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.14);
}

.unit-zones-button.is-muted .unit-zones-dot {
  background: #9c968c;
  box-shadow: none;
}

.unit-zones-button strong {
  color: var(--muted);
  font-size: 11px;
}

.unit-zones-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3;
  min-height: 0;
  border: 0;
  border-radius: 0;
  appearance: none;
  background: transparent;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.unit-zones-backdrop[hidden] {
  display: none;
}

.unit-zones-dropup {
  position: absolute;
  left: 12px;
  bottom: max(68px, calc(env(safe-area-inset-bottom) + 68px));
  z-index: 7;
  display: grid;
  gap: 10px;
  width: min(300px, calc(100% - 24px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  padding: 12px;
}

.unit-zones-dropup[hidden] {
  display: none;
}

.unit-zones-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.unit-zones-header h2 {
  margin: 0 0 4px;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
}

.unit-zones-field {
  display: grid;
  gap: 6px;
  margin: 0;
}

.unit-zones-select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border-color: var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  text-align: right;
}

.unit-zones-select-button:hover,
.unit-zones-select-button:focus-visible {
  border-color: var(--accent);
  background: #fff;
  color: var(--text);
  box-shadow: 0 0 0 3px var(--focus);
}

.unit-zones-select-button svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.unit-zones-select-button[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.unit-zones-menu {
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}

.unit-zones-menu[hidden] {
  display: none;
}

.unit-zones-menu-option {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  margin: 0;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
}

.unit-zones-menu-option:hover {
  background: var(--panel-muted);
}

.unit-zones-menu-option:has(input:checked) {
  background: rgba(180, 35, 24, 0.08);
}

.unit-zones-menu-option input {
  width: 17px;
  height: 17px;
  min-height: 17px;
  margin: 0;
  padding: 0;
  accent-color: #b42318;
}

.location-fab {
  position: absolute;
  right: 12px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  min-width: 46px;
  min-height: 46px;
  border-radius: 50%;
  box-shadow: var(--shadow);
  padding: 0;
}

.location-icon {
  display: block;
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.location-icon-body {
  fill: #fff;
}

.location-icon-dot {
  fill: var(--accent);
}

.location-fab.is-locating {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.esri-view .esri-view-surface:focus::after {
  outline: none;
}

.esri-ui {
  direction: ltr;
}

.esri-ui-top-left,
.esri-ui-top-right {
  top: 70px;
}

.esri-ui-bottom-left,
.esri-ui-bottom-right {
  bottom: 84px;
}

@media (min-width: 760px) {
  .map-search {
    right: 18px;
    left: auto;
    width: min(520px, calc(100vw - 36px));
  }

  .unit-zones-button {
    left: 18px;
  }

  .unit-zones-dropup {
    left: 18px;
    width: 300px;
  }

  .location-fab {
    right: 18px;
  }
}
