:root {
  color-scheme: light;
  --ink: #082f54;
  --muted: #60758a;
  --line: #c8d8e6;
  --panel: #ffffff;
  --panel-soft: #f3f8fc;
  --navy: #083860;
  --navy-deep: #052944;
  --sky: #b0cce8;
  --gold: #edc33a;
  --gold-deep: #b48710;
  --blue: var(--navy);
  --green: #237766;
  --amber: #9b6710;
  --red: #a83232;
  --shadow: 0 18px 42px rgba(5, 41, 68, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    linear-gradient(180deg, rgba(176, 204, 232, 0.46), rgba(243, 248, 252, 0.92) 360px),
    #eef5fa;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--navy);
  cursor: pointer;
}

button:hover {
  filter: brightness(0.94);
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-rows: minmax(420px, 1fr) auto;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.control-panel,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-panel {
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-radius: 8px;
  border-top: 5px solid var(--gold);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  color: var(--navy);
}

.brand-row p,
.last-updated,
small {
  color: var(--muted);
}

.tail-form,
.settings {
  display: grid;
  gap: 8px;
}

label {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}

input,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(237, 195, 58, 0.22);
  outline: 0;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

.mode-row,
.action-row,
.roster-row,
.map-layer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.map-layer-row {
  grid-template-columns: repeat(3, 1fr);
}

.mode-button,
.layer-button {
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.mode-button.active,
.layer-button.active {
  color: var(--navy-deep);
  background: var(--gold);
  border-color: var(--gold);
}

.layer-button {
  min-height: 38px;
  padding: 7px 8px;
  font-size: 13px;
}

.subtle {
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.hidden {
  display: none;
}

.fleet-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.fleet-summary div {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, var(--panel-soft));
}

.fleet-summary span {
  display: block;
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
}

.map-panel {
  position: relative;
  overflow: hidden;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sky);
  box-shadow: var(--shadow);
}

#map {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.empty-state {
  position: absolute;
  inset: auto 24px 24px 24px;
  max-width: 430px;
  padding: 18px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(8, 56, 96, 0.2);
  border-left: 5px solid var(--gold);
}

.empty-state h2 {
  margin-bottom: 6px;
  font-size: 21px;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.45;
}

.table-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: min(46vh, 520px);
  overflow: hidden;
  border-radius: 8px;
}

.table-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--navy);
}

.table-header h2 {
  margin-bottom: 3px;
  font-size: 19px;
  color: #fff;
}

.table-header span {
  color: var(--sky);
  font-size: 13px;
}

.table-filters {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid rgba(176, 204, 232, 0.42);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.filter-button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 4px;
  color: var(--sky);
  font-size: 12px;
  font-weight: 700;
  background: transparent;
}

.filter-button:hover,
.filter-button.active {
  color: var(--navy-deep);
  background: #fff;
  filter: none;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 210px;
  max-height: 440px;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

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

th,
td {
  position: relative;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 8;
  color: var(--navy);
  font-size: 12px;
  text-transform: uppercase;
  background: #f7fafc;
}

th:nth-child(1),
td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 7;
  width: 98px;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
}

th:nth-child(1) {
  z-index: 10;
  background: #f7fafc;
}

th:nth-child(2),
td:nth-child(2) {
  width: 105px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 170px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 175px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 170px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 74px;
}

th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8),
th:nth-child(9),
td:nth-child(9),
th:nth-child(10),
td:nth-child(10) {
  width: 78px;
}

th:nth-child(11),
td:nth-child(11) {
  width: 162px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.status.airborne {
  color: #0b5f4a;
  background: #e3f3ee;
}

.status.ground {
  color: var(--muted);
  background: #edf1f5;
}

.status.issue {
  color: var(--amber);
  background: #fff5d7;
}

.status.error {
  color: var(--red);
  background: #fde8e8;
}

.tail-jump-button {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--navy);
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  background: transparent;
}

.tail-jump-button:hover {
  color: var(--gold-deep);
  filter: none;
}

.tail-jump-button:disabled {
  color: var(--ink);
  text-decoration: none;
  cursor: default;
  opacity: 1;
}

.pinned-row td {
  background: #fffdf2;
}

.pinned-row td:first-child {
  background: #fff7d1;
}

.pinned-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--navy-deep);
  font-size: 11px;
  font-weight: 700;
  background: rgba(237, 195, 58, 0.55);
  border: 1px solid rgba(180, 135, 16, 0.42);
}

.route-main,
.flight-message {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-cell {
  cursor: help;
}

.clipped-text {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-cell::after {
  position: absolute;
  left: 14px;
  bottom: calc(100% - 4px);
  z-index: 30;
  display: none;
  width: min(460px, 72vw);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-line;
  background: #fff;
  box-shadow: 0 12px 28px rgba(5, 41, 68, 0.22);
  content: attr(data-tooltip);
}

.type-cell:hover::after,
.type-cell:focus::after {
  display: block;
}

.type-cell:focus {
  outline: 2px solid rgba(237, 195, 58, 0.65);
  outline-offset: -2px;
}

.flight-message {
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
}

.roster-badge,
.popup-roster-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--navy-deep);
  font-size: 11px;
  font-weight: 700;
  background: rgba(237, 195, 58, 0.32);
  border: 1px solid rgba(180, 135, 16, 0.36);
}

.popup-roster-badge {
  margin: 4px 0;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pin-button,
.trail-history-button,
.edit-roster-button,
.remove-button {
  width: 32px;
  min-height: 32px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.pin-button,
.trail-history-button,
.edit-roster-button {
  width: auto;
  padding: 0 7px;
  color: var(--navy);
}

.pin-button.active {
  color: var(--navy-deep);
  background: rgba(237, 195, 58, 0.32);
}

.pin-button:hover,
.trail-history-button:hover,
.edit-roster-button:hover,
.remove-button:hover {
  color: var(--navy-deep);
  background: var(--panel-soft);
  filter: none;
}

.table-empty-row {
  position: static;
  width: auto;
  padding: 26px 16px;
  color: var(--muted);
  text-align: center;
  background: #fff;
  box-shadow: none;
}

.roster-dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(5, 41, 68, 0.32);
}

.roster-dialog::backdrop {
  background: rgba(5, 41, 68, 0.42);
}

.roster-editor {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-header h2 {
  font-size: 20px;
  color: var(--navy);
}

.dialog-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

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

.editor-grid label {
  display: grid;
  gap: 6px;
}

.editor-wide {
  grid-column: 1 / -1;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions button {
  min-width: 86px;
  padding: 0 12px;
}

.danger {
  color: var(--red);
}

.danger:hover {
  color: #fff;
  background: var(--red);
}

.plane-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--navy);
  font-size: 18px;
  background: var(--gold);
  border: 2px solid #fff;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.flight-trail {
  cursor: pointer;
  filter:
    drop-shadow(0 0 1px rgba(255, 255, 255, 0.95))
    drop-shadow(0 1px 2px rgba(5, 41, 68, 0.65));
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trail-popup {
  min-width: 210px;
  color: var(--ink);
}

.trail-popup strong {
  display: block;
  margin-bottom: 8px;
  color: var(--navy);
  font-size: 14px;
}

.trail-popup dl {
  display: grid;
  gap: 5px;
  margin: 0 0 10px;
}

.trail-popup dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.trail-popup dt {
  color: var(--muted);
}

.trail-popup dd {
  margin: 0;
  font-weight: 700;
}

.remove-trail-button {
  width: 100%;
  min-height: 34px;
  color: #fff;
  background: var(--red);
}

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

  .table-panel {
    max-height: 54vh;
  }

  .table-wrap {
    max-height: 46vh;
  }

  table {
    min-width: 780px;
  }

  th:nth-child(5),
  td:nth-child(5),
  th:nth-child(6),
  td:nth-child(6),
  th:nth-child(9),
  td:nth-child(9),
  th:nth-child(10),
  td:nth-child(10) {
    display: none;
  }

  th:nth-child(3),
  td:nth-child(3),
  th:nth-child(4),
  td:nth-child(4) {
    width: 180px;
  }

  .control-panel {
    grid-row: auto;
  }

  .map-panel,
  #map {
    min-height: 440px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 10px;
  }

  .table-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  table {
    min-width: 640px;
  }

  th:nth-child(4),
  td:nth-child(4),
  th:nth-child(7),
  td:nth-child(7) {
    display: none;
  }

  th,
  td {
    padding: 9px 10px;
  }

  .control-panel {
    padding: 14px;
  }

  .fleet-summary {
    grid-template-columns: 1fr;
  }
}
