:root {
  color-scheme: dark;
  --bg: #101115;
  --surface: #181a20;
  --surface-2: #20232b;
  --surface-3: #282c35;
  --text: #f4f1ea;
  --muted: #a9a39a;
  --line: rgba(244, 241, 234, .13);
  --accent: #36c2a4;
  --accent-strong: #f0b84d;
  --danger: #ff6b6b;
  --shadow: 0 20px 70px rgba(0, 0, 0, .34);
  --radius: 8px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --surface-3: #e2ded5;
  --text: #17191d;
  --muted: #68635c;
  --line: rgba(23, 25, 29, .15);
  --shadow: 0 20px 60px rgba(37, 33, 27, .16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  height: 100dvh;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(260px, 1fr) minmax(560px, 760px);
  gap: 14px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}

.brand {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 96px;
  max-height: 42px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  min-width: 0;
}

.brand strong,
.brand small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab,
.text-btn,
.quick button,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.tab {
  display: grid;
  flex: 0 0 auto;
  min-height: 42px;
  align-content: center;
  gap: 2px;
  padding: 0 13px;
  color: var(--muted);
  text-align: left;
}

.tab.active {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
  background: rgba(54, 194, 164, .1);
  color: var(--text);
}

.tab strong,
.tab span {
  display: block;
  line-height: 1.05;
}

.tab strong {
  font-size: 12px;
}

.tab span {
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
}

.search {
  display: grid;
  grid-template-columns: 40px 0fr;
  align-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  overflow: hidden;
  transition: width .2s ease, border-color .16s ease, background .16s ease;
}

.top-actions {
  display: flex;
  min-width: 0;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.search:hover,
.search:focus-within,
.search.is-expanded {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  background: rgba(54, 194, 164, .1);
}

.search:focus-within,
.search.is-expanded {
  grid-template-columns: 38px minmax(0, 1fr);
  width: min(280px, calc(100vw - 132px));
}

.search.has-value:not(.is-expanded):not(:focus-within) {
  border-color: color-mix(in srgb, var(--accent) 64%, var(--line));
}

.search svg {
  width: 19px;
  margin: auto;
  fill: var(--muted);
  transition: fill .16s ease;
}

.search:hover svg,
.search:focus-within svg,
.search.is-expanded svg,
.search.has-value svg {
  fill: var(--text);
}

.search input {
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}

.search:focus-within input,
.search.is-expanded input {
  padding-right: 10px;
  opacity: 1;
  pointer-events: auto;
}

.search input::placeholder {
  color: #807b74;
}

.layout {
  --sidebar-width: 360px;
  --sidebar-compact-width: 64px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 0;
  transition: grid-template-columns .22s ease;
}

.filters {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
  overflow: hidden;
  transition: opacity .18s ease, padding .22s ease, border-color .22s ease;
}

.layout.sidebar-collapsed {
  --sidebar-width: var(--sidebar-compact-width);
}

.layout.sidebar-collapsed .filters {
  justify-items: center;
  gap: 0;
  padding: 14px 12px;
  opacity: 1;
  pointer-events: auto;
}

.layout.sidebar-collapsed .filters > :not(.sidebar-toggle) {
  display: none;
}

.layout.sidebar-collapsed .filters > .sidebar-toggle {
  justify-self: center;
}

.selector-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.filters > .sidebar-toggle {
  justify-self: start;
}

.layout.is-profile-section .filters > .sidebar-toggle {
  order: 0;
}

.layout.is-profile-section .selector-head {
  order: 1;
}

.layout.is-profile-section #categoryBlock {
  order: 2;
}

.layout.is-profile-section #areaBlock {
  order: 3;
}

.layout.is-profile-section #typeBlock {
  order: 4;
}

.layout.is-profile-section .selector-actions {
  order: 5;
}

.selector-head span {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.selector-head h1 {
  margin: 0;
  font-size: 21px;
}

.text-btn {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
}

.text-btn.compact {
  min-width: 44px;
}

.text-btn.full {
  width: 100%;
  min-height: 40px;
}

.primary-btn {
  min-height: 38px;
  border: 1px solid color-mix(in srgb, var(--accent) 65%, var(--line));
  border-radius: var(--radius);
  background: var(--accent);
  color: #06110e;
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.text-btn:hover,
.text-btn.active,
.quick button:hover,
.quick button.active,
.icon-btn:hover,
.icon-btn.active {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  background: rgba(54, 194, 164, .1);
  color: var(--text);
}

.field {
  display: grid;
  gap: 6px;
}

.field-card,
.choice-block {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-2) 74%, transparent);
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.choice-block {
  display: grid;
  gap: 8px;
}

.choice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.choice-head > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.collapse-toggle {
  display: none;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.collapse-toggle::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform .18s ease;
}

.filter-section.is-collapsed .collapse-toggle::before {
  transform: rotate(-45deg);
}

.quick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.quick button,
.map-type-grid button {
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-weight: 700;
}

.map-type-grid {
  display: grid;
  gap: 8px;
  max-height: min(38vh, 390px);
  overflow: auto;
  padding-right: 2px;
}

.map-type-grid button {
  display: grid;
  gap: 3px;
  min-height: 54px;
  padding: 9px 10px;
  text-align: left;
}

.map-type-grid strong,
.map-type-grid span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-type-grid strong {
  color: var(--text);
  font-size: 13px;
}

.map-type-grid span {
  color: var(--muted);
  font-size: 11px;
}

.map-type-grid button.active span {
  color: color-mix(in srgb, var(--accent) 70%, var(--text));
}

.empty-inline {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
}

.viewer {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: color-mix(in srgb, var(--bg) 92%, #000);
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
}

.layout.sidebar-collapsed .sidebar-toggle svg {
  transform: scaleX(-1);
}

.map-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  flex: 1 1 270px;
  gap: 9px;
  align-items: center;
  min-width: 0;
  max-width: min(500px, 50vw);
}

#badge {
  display: grid;
  min-width: 50px;
  min-height: 30px;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(240, 184, 77, .13);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.map-title h2,
.map-title p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-title h2 {
  font-size: 16px;
}

.map-title p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.time-slider {
  display: grid;
  grid-template-columns: auto minmax(280px, 520px);
  align-items: center;
  gap: 9px;
  flex: 1 1 470px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
}

.time-slider span {
  min-width: 54px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.time-slider input {
  width: 100%;
  min-width: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 7px;
  align-items: center;
  justify-content: flex-start;
  padding: 7px 14px 8px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
}

.actions::-webkit-scrollbar {
  display: none;
}

.icon-btn {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
}

.icon-btn.locked {
  opacity: .42;
}

.icon-btn.loading {
  opacity: .7;
  pointer-events: none;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  cursor: default;
  touch-action: none;
}

.stage.is-zoomed {
  cursor: grab;
}

.stage.is-zoomed:active {
  cursor: grabbing;
}

.stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.empty {
  position: absolute;
  padding: 18px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.field input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: minmax(210px, 1fr);
  }

  .tabs,
  .top-actions {
    grid-column: 1 / -1;
  }

  .app {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .layout {
    --sidebar-width: 310px;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  body {
    height: auto;
  }

  .app {
    display: block;
    height: auto;
    min-height: 100dvh;
  }

  .layout {
    display: flex;
    flex-direction: column;
  }

  .layout.sidebar-collapsed .filters {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: flex-start;
  }

  .filters {
    order: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .selector-head,
  .quick,
  .choice-block,
  .field,
  .text-btn.full {
    grid-column: 1 / -1;
  }

  .viewer {
    order: 1;
    min-height: 72dvh;
  }

  .actions {
    padding: 7px 12px;
  }

  .choice-block {
    padding: 10px;
  }

  .choice-head {
    cursor: pointer;
  }

  .map-type-grid {
    max-height: 148px;
  }

  .map-type-grid button {
    min-height: 48px;
    padding: 7px 10px;
  }

  .collapse-toggle {
    display: grid;
  }

  .filter-section.is-collapsed .choice-body {
    display: none;
  }
}

@media (max-width: 560px) {
  .topbar,
  .filters {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    gap: 12px;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .time-slider {
    grid-template-columns: auto minmax(0, 1fr);
    flex-basis: min(100%, 320px);
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .selector-head h1 {
    font-size: 20px;
  }

  .selector-head,
  .quick,
  .choice-block,
  .field,
  .text-btn.full {
    grid-column: auto;
  }

  .map-title h2 {
    font-size: 14px;
  }

  .map-title {
    flex: 1 0 100%;
    max-width: none;
    margin-right: 0;
  }

  .map-title p {
    font-size: 11px;
  }

  #badge {
    min-width: 46px;
    min-height: 28px;
    font-size: 11px;
  }

  .actions {
    flex-wrap: wrap;
    gap: 6px;
    overflow-x: visible;
    padding: 6px 10px 7px;
  }

  .actions .icon-btn {
    width: 32px;
    height: 32px;
  }

  .actions .icon-btn svg {
    width: 17px;
    height: 17px;
  }
}
