:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef1ef;
  color: #202427;
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

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

body.auth-pending .app-shell,
body.login-required .app-shell {
  visibility: hidden;
}

body.authenticated .login-overlay,
.login-overlay[hidden] {
  display: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #eef1ef;
}

.login-panel {
  width: min(340px, 100%);
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid #c8d0ca;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(31, 40, 36, 0.18);
}

.login-panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
  line-height: 1.2;
}

.login-panel button {
  width: 100%;
}

.login-error {
  min-height: 17px;
  color: #a13326;
  font-size: 12px;
  line-height: 1.35;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-height: 82px;
  padding: 12px 16px;
  border-bottom: 1px solid #d3d9d4;
  background: #fbfcf9;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-form {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(118px, 1fr)) max-content max-content;
  gap: 9px;
  align-items: end;
}

label {
  min-width: 0;
  display: grid;
  gap: 4px;
}

label span {
  color: #59635e;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0;
}

input,
select {
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid #c4ccc6;
  border-radius: 6px;
  background: #ffffff;
  color: #202427;
  padding: 0 9px;
}

.tool-button,
.primary-button {
  height: 36px;
  border-radius: 6px;
  border: 1px solid #b9c2bc;
  background: #ffffff;
  color: #27312d;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  border-color: #244b68;
  background: #244b68;
  color: #ffffff;
}

.tool-button:disabled,
.primary-button:disabled {
  opacity: 0.45;
  cursor: default;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid #2d6cdf;
  outline-offset: 2px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(460px, 38vw);
}

.map-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #dfe6e0;
}

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

.bbox-panel {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 3;
  width: min-content;
  max-width: calc(100% - 24px);
  display: grid;
  grid-template-columns: repeat(4, 78px);
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(53, 61, 57, 0.18);
  border-radius: 8px;
  background: rgba(251, 252, 249, 0.94);
  box-shadow: 0 12px 28px rgba(31, 40, 36, 0.14);
}

.bbox-panel label {
  width: 78px;
}

.bbox-panel input {
  padding: 0 7px;
  font-size: 12px;
}

.bbox-panel .tool-button {
  grid-column: span 2;
}

.tool-button.is-active {
  border-color: #b94739;
  background: #fff4f1;
  color: #8f2f22;
}

.results-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  border-left: 1px solid #d3d9d4;
  background: #ffffff;
}

.results-loading {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 8;
  min-width: 248px;
  max-width: calc(100% - 24px);
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid #b9c2bc;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 34px rgba(31, 40, 36, 0.18);
}

.results-loading[hidden] {
  display: none;
}

.results-loading strong,
.results-loading span {
  display: block;
}

.results-loading strong {
  font-size: 13px;
  line-height: 1.2;
}

.results-loading span {
  margin-top: 2px;
  color: #59635e;
  font-size: 12px;
  line-height: 1.25;
}

.loading-indicator {
  width: 18px;
  height: 18px;
  border: 2px solid #d5ddd7;
  border-top-color: #244b68;
  border-radius: 50%;
  animation: loading-spin 700ms linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.results-view {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

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

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid #e1e5e0;
}

.summary-strip div {
  min-width: 0;
  padding: 12px 14px;
  border-left: 1px solid #e1e5e0;
}

.summary-strip div:first-child {
  border-left: 0;
}

.summary-strip span {
  display: block;
  font-size: 19px;
  line-height: 1.15;
  font-weight: 720;
}

.summary-strip label {
  display: block;
  margin-top: 3px;
  color: #66716c;
  font-size: 11px;
  text-transform: uppercase;
}

.results-mode-toggle {
  display: flex;
  gap: 0;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #e1e5e0;
  background: #fbfcfa;
}

.export-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
  font-weight: 680;
}

.export-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.mode-button {
  min-height: 32px;
  min-width: 86px;
  border: 1px solid #b8c3bc;
  border-left: 0;
  border-radius: 0;
  background: #ffffff;
  color: #34413c;
  padding: 6px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 680;
}

.mode-button:first-child {
  border-left: 1px solid #b8c3bc;
  border-radius: 6px 0 0 6px;
}

.mode-button:last-child {
  border-radius: 0 6px 6px 0;
}

.mode-button:hover {
  background: #edf3ef;
}

.mode-button.is-active {
  background: #27312d;
  border-color: #27312d;
  color: #ffffff;
}

.table-wrap {
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid #edf0ed;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0;
  background: #f6f8f5;
  color: #56605c;
  font-size: 11px;
  line-height: 1.1;
  text-transform: uppercase;
}

td {
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.model-name-column {
  width: 39%;
}

.source-column {
  width: 10%;
}

.numeric-column {
  width: 11%;
}

.emissions-column {
  width: 18%;
}

.gph-source-icon {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.gph-source-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.gph-source-ground-truth {
  color: #247247;
  background: #eef8f1;
}

.gph-source-placeholder {
  color: #9a5f00;
  background: #fff7e8;
}

.gph-source-mixed {
  color: #336486;
  background: #eef6fb;
}

.gph-source-unavailable {
  color: #69746f;
  background: #f5f7f5;
}

.sort-header-button {
  width: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  line-height: inherit;
  text-align: left;
  text-transform: inherit;
}

.sort-header-button:hover {
  background: #edf3ef;
}

.sort-header-button:focus-visible {
  position: relative;
  z-index: 2;
}

.sort-header-button > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sort-indicator {
  width: 0;
  height: 0;
  flex: 0 0 auto;
  opacity: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.sort-header-button.sort-asc .sort-indicator {
  opacity: 1;
  border-bottom: 6px solid currentColor;
}

.sort-header-button.sort-desc .sort-indicator {
  opacity: 1;
  border-top: 6px solid currentColor;
}

td strong {
  display: block;
  font-size: 12px;
}

td span {
  display: block;
  color: #69746f;
}

.pagination {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #e1e5e0;
}

#pageStatus {
  text-align: center;
  color: #59635e;
  font-size: 12px;
}

.empty-row td {
  color: #69746f;
  padding: 22px 12px;
  text-align: center;
}

.result-row {
  cursor: pointer;
}

.result-row:hover td,
.result-row:focus-within td {
  background: #f2f7f5;
}

.flight-detail-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #ffffff;
  overflow: hidden;
}

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

.flight-detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 14px;
  align-items: start;
  padding: 16px 18px;
  border-bottom: 1px solid #e1e5e0;
  background: #f8faf7;
}

.flight-detail-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.flight-detail-header span {
  display: block;
  margin-top: 5px;
  color: #5e6964;
  font-size: 12px;
  line-height: 1.35;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #bcc6bf;
  border-radius: 6px;
  background: #ffffff;
  color: #27312d;
  cursor: pointer;
  font-weight: 720;
}

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

.settings-button {
  width: 36px;
  height: 36px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: start end;
  padding: 76px 18px 18px;
  background: rgba(32, 36, 39, 0.22);
}

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

.settings-dialog {
  width: min(360px, calc(100vw - 36px));
  border: 1px solid #c8d0ca;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(31, 40, 36, 0.22);
  overflow: hidden;
}

.settings-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #e1e5e0;
  background: #f8faf7;
}

.settings-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.settings-body {
  padding: 14px;
}

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #dce2dd;
  border-radius: 8px;
  background: #fbfcfa;
  cursor: pointer;
}

.toggle-text {
  color: #27312d;
  font-size: 13px;
  line-height: 1.25;
  font-weight: 680;
  text-transform: none;
}

.toggle-row input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #b7c1bb;
  transition: background 120ms ease;
}

.toggle-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(31, 40, 36, 0.22);
  transition: transform 120ms ease;
}

.toggle-row input:checked + .toggle-switch {
  background: #244b68;
}

.toggle-row input:checked + .toggle-switch::before {
  transform: translateX(20px);
}

.toggle-row input:focus-visible + .toggle-switch {
  outline: 2px solid #2d6cdf;
  outline-offset: 3px;
}

.flight-detail-body {
  min-height: 0;
  overflow: auto;
  padding: 16px 18px 18px;
}

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

.detail-section {
  margin-top: 16px;
}

.detail-section:first-child {
  margin-top: 0;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.2;
  text-transform: uppercase;
  color: #4c5954;
}

.detail-list {
  display: grid;
  gap: 1px;
  border: 1px solid #e2e7e3;
  border-radius: 8px;
  overflow: hidden;
}

.detail-list div {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(120px, 0.45fr) minmax(0, 1fr);
  gap: 10px;
  padding: 8px 10px;
  background: #fbfcfa;
}

.detail-list dt {
  color: #65706b;
  font-size: 12px;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  font-size: 12px;
  color: #202427;
  overflow-wrap: anywhere;
}

.detail-list dd span,
.detail-source-note {
  display: block;
  margin-top: 3px;
  color: #69746f;
}

.detail-list a {
  color: #1d5f83;
}

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

  .search-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 48vh) minmax(0, 1fr);
  }

  .results-panel {
    border-left: 0;
    border-top: 1px solid #d3d9d4;
  }
}

@media (max-width: 620px) {
  .bbox-panel {
    grid-template-columns: repeat(2, 78px);
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .detail-grid,
  .detail-list div {
    grid-template-columns: 1fr;
  }
}
