:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-strong: #f0f4f8;
  --text: #17202a;
  --muted: #617083;
  --line: #d9e1ea;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0f9f6e;
  --red: #c2410c;
  --nav: #111827;
  --nav-muted: #9ca3af;
  --shadow: 0 18px 48px rgba(16, 24, 40, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 236px 380px minmax(0, 1fr);
  min-height: 100vh;
}

.nav-sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 22px;
  background: var(--nav);
  color: #fff;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.view-panel[hidden] {
  display: none;
}

.stats-grid p,
.status,
.api-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.main-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--nav-muted);
  font-weight: 800;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.panel-heading {
  display: grid;
  gap: 3px;
}

.panel-heading span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-heading strong {
  font-size: 22px;
  line-height: 1.15;
}

.search-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

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

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.switch-row {
  display: grid;
  gap: 10px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--text);
  font-weight: 650;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.2s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.28);
  transition: transform 0.2s ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.action-row,
.export-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.icon-button,
.primary,
.secondary,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  font-weight: 750;
}

.icon-button {
  width: 44px;
}

.primary {
  background: var(--blue);
  color: #fff;
}

.primary:hover {
  background: var(--blue-dark);
}

.secondary {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
}

.ghost {
  background: transparent;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats-grid div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.stats-grid span {
  display: block;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
}

.status {
  min-height: 38px;
  padding: 12px;
  border-left: 3px solid var(--blue);
  background: var(--panel-strong);
}

.status.error {
  border-color: var(--red);
  color: #7c2d12;
}

.status.success {
  border-color: var(--green);
  color: #065f46;
}

.api-card {
  display: grid;
  gap: 16px;
}

.api-metrics {
  display: grid;
  gap: 10px;
}

.api-metrics div {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.api-metrics label {
  margin-bottom: 4px;
}

.api-metrics strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.usage-card {
  display: grid;
  gap: 8px;
}

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

.usage-heading label {
  margin: 0;
}

.usage-bar {
  overflow: hidden;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #dbe4ef;
}

.usage-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.25s ease, background 0.25s ease;
}

.usage-bar span.full {
  background: #dc2626;
}

.usage-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.api-status-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.pill.neutral {
  background: #e5e7eb;
  color: #374151;
}

.pill.success {
  background: #d1fae5;
  color: #065f46;
}

.pill.error {
  background: #ffedd5;
  color: #9a3412;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.wide-button {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-rows: minmax(360px, 52vh) minmax(0, 1fr);
  min-width: 0;
}

.map-area {
  position: relative;
  min-height: 360px;
  border-bottom: 1px solid var(--line);
  background: #d8dee9;
}

#map {
  width: 100%;
  height: 100%;
}

.map-empty {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(340px, calc(100% - 36px));
  padding: 11px 13px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 14px;
}

.results-area {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  background: var(--bg);
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.results-toolbar h2 {
  margin: 0;
  font-size: 18px;
}

.filter-box {
  position: relative;
  width: min(360px, 50%);
}

.filter-box svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--muted);
}

.filter-box input {
  padding-left: 38px;
}

.table-wrap {
  overflow: auto;
  height: calc(100% - 54px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fbff;
}

.empty-row,
.empty-row:hover {
  cursor: default;
  background: transparent;
  color: var(--muted);
}

.name-cell strong {
  display: block;
  margin-bottom: 4px;
}

.name-cell span {
  color: var(--muted);
  font-size: 12px;
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-list a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.link-list a:hover {
  text-decoration: underline;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .nav-sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .main-nav {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    grid-template-rows: 420px 560px;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .results-area {
    padding: 14px;
  }

  .field-grid,
  .action-row,
  .export-row,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .results-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-box {
    width: 100%;
  }
}
