:root {
  --bg: #edf2ee;
  --panel: #ffffff;
  --panel-soft: #f6f8f6;
  --ink: #18211e;
  --muted: #64706c;
  --line: #d7dfd9;
  --accent: #0f8b8d;
  --accent-dark: #0a6769;
  --warn: #d97706;
  --danger: #d84c3f;
  --shadow: 0 16px 40px rgba(24, 33, 30, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 14px;
  letter-spacing: 0;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  max-width: 70vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 12px;
  white-space: nowrap;
}

.button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
  border-color: #a7b7ae;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.button.ghost {
  min-height: 32px;
  background: transparent;
}

.button.icon {
  min-width: 62px;
  padding: 0 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  height: calc(100vh - 68px);
}

.sidebar {
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 14px;
  z-index: 3;
}

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

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  min-width: 0;
}

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

.stat strong {
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin-bottom: 12px;
}

.filters {
  padding: 12px;
}

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

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  min-width: 0;
}

.field > span,
.toggle span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

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

select {
  padding-right: 28px;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.airport-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.range-field input {
  accent-color: var(--accent);
  padding: 0;
}

.toggle {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.results {
  overflow: hidden;
}

.results .panel-heading {
  padding: 12px 12px 0;
}

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

.aircraft-list {
  display: grid;
  gap: 6px;
  max-height: 48vh;
  overflow: auto;
  padding: 0 12px 12px;
}

.lookup {
  padding: 12px;
}

.lookup-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.lookup-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.lookup-row.live {
  border-color: var(--accent);
  background: #f3fbfa;
  cursor: pointer;
}

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

.lookup-title {
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lookup-meta,
.lookup-sub {
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aircraft-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 7px;
}

.aircraft-row:hover,
.aircraft-row.active {
  border-color: var(--accent);
  background: #f3fbfa;
}

.row-top,
.row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.callsign {
  font-weight: 800;
  letter-spacing: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta,
.row-sub {
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.row-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.maplibregl-popup-content {
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.selected-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  width: min(360px, calc(100% - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 2;
}

.selected-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.selected-title {
  font-size: 19px;
  font-weight: 850;
  letter-spacing: 0;
}

.selected-title-link,
.detail-link {
  color: var(--accent-dark);
  text-decoration: none;
}

.selected-title-link:hover,
.detail-link:hover {
  text-decoration: underline;
}

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

.close-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

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

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

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

.detail strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.legend {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  max-width: calc(100% - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 9px 10px;
  font-size: 12px;
  color: var(--muted);
  z-index: 2;
}

.legend div {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot.commercial {
  background: #0f8b8d;
}

.legend-dot.cargo {
  background: #c26a00;
}

.legend-dot.private {
  background: #2f855a;
}

.legend-dot.military {
  background: #c2410c;
}

.legend-dot.unknown {
  background: #6b7280;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
  text-align: center;
  font-size: 13px;
}

@media (max-width: 980px) {
  body {
    overflow: hidden;
  }

  .topbar {
    height: 62px;
    padding: 10px 12px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }

  h1 {
    font-size: 16px;
  }

  .brand p {
    max-width: 50vw;
  }

  .app-shell {
    display: block;
    height: calc(100vh - 62px);
  }

  .sidebar {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-height: 54vh;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .map-shell {
    position: absolute;
    inset: 62px 0 0;
  }

  .selected-panel {
    top: 12px;
    right: 12px;
    width: min(340px, calc(100% - 24px));
  }

  .legend {
    left: 12px;
    bottom: calc(54vh + 24px);
  }
}

@media (max-width: 620px) {
  .top-actions .pill {
    display: none;
  }

  .grid-two {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stat {
    padding: 8px;
  }

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

  .stat span {
    font-size: 10px;
  }

  .legend {
    display: none;
  }
}
