:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #17202f;
  --muted: #647087;
  --blue: #1667d9;
  --green: #0b7a53;
  --amber: #986400;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.search,
.advanced,
.direct-mode,
.extension-guide,
.sync-monitor,
.fallback,
.status,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search {
  display: grid;
  grid-template-columns: repeat(10, minmax(92px, 1fr)) auto;
  gap: 12px;
  padding: 16px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.city-field {
  position: relative;
}

.city-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(23, 32, 47, 0.14);
}

.city-options button {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  white-space: normal;
}

.city-options button:hover,
.city-options button:focus {
  background: #eef3f9;
}

.city-options strong {
  color: var(--text);
  font-size: 13px;
}

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

.city-search::placeholder {
  color: #8893a5;
}

input,
textarea,
select,
button {
  font: inherit;
}

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

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--text);
}

.check input {
  width: auto;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

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

.advanced {
  margin-top: 12px;
  padding: 12px 16px;
}

.direct-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding: 14px 16px;
}

.direct-mode h2 {
  margin: 0;
  font-size: 17px;
}

.direct-mode p {
  font-size: 13px;
}

.extension-guide {
  margin-top: 12px;
  padding: 14px 16px;
}

.extension-guide h2 {
  margin: 0;
  font-size: 17px;
}

.extension-guide ol {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.sync-monitor {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) 1.3fr;
  gap: 14px;
  margin-top: 12px;
  padding: 14px 16px;
}

.sync-monitor h2 {
  margin: 0;
  font-size: 17px;
}

#extensionStatus.ok {
  color: var(--green);
}

#extensionStatus.warn {
  color: var(--amber);
}

.import-events {
  display: grid;
  gap: 6px;
  align-content: start;
  color: var(--muted);
  font-size: 13px;
}

.import-event {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfe;
}

.import-event strong {
  color: var(--text);
}

.fallback {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(320px, 1.3fr);
  gap: 16px;
  margin-top: 12px;
  padding: 14px 16px;
}

.fallback h2 {
  margin: 0;
  font-size: 17px;
}

.fallback p {
  font-size: 13px;
}

.script-text {
  margin-top: 10px;
  min-height: 74px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.direct-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  background: #fff;
  white-space: nowrap;
}

.button-link.accent {
  border-color: var(--green);
  color: var(--green);
  font-weight: 700;
}

.install-shell {
  max-width: 980px;
}

.install-panel {
  align-items: flex-start;
}

.install-guide code {
  display: block;
  margin-top: 8px;
  padding: 9px 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfe;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 600;
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-top: 12px;
}

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

.status {
  margin-top: 12px;
  padding: 12px 16px;
  color: var(--muted);
}

.progress-panel {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
}

#progressLabel {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
}

#progressPct {
  flex: none;
  font-weight: 700;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  background: #e8edf4;
  border-radius: 999px;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--blue);
  border-radius: inherit;
  transition: width 300ms ease;
}

.progress-sources {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.progress-sources span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfe;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.progress-sources span.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eef5ff;
  font-weight: 700;
}

.progress-sources span.done {
  border-color: rgba(11, 122, 83, 0.34);
  color: var(--green);
  background: #eefaf5;
  font-weight: 700;
}

.progress-sources span.error {
  border-color: rgba(152, 100, 0, 0.34);
  color: var(--amber);
  background: #fff8e6;
}

.progress-steps {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 0;
  margin: 12px 0 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.progress-steps li {
  min-width: 0;
  overflow-wrap: anywhere;
}

.progress-steps li.done {
  color: var(--green);
  font-weight: 700;
}

.progress-steps li.active {
  color: var(--blue);
  font-weight: 700;
}

.status strong {
  color: var(--text);
}

.table-wrap {
  margin-top: 12px;
  overflow: auto;
  max-height: calc(100vh - 260px);
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  line-height: 18px;
  height: 52px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f9;
  color: #3b4658;
  font-weight: 700;
  white-space: nowrap;
}

td.price {
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  height: 52px;
  overflow: hidden;
}

td.price .muted {
  display: inline-block;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

td.time,
td.leg {
  white-space: nowrap;
}

td.flight-no {
  font-weight: 700;
}

td.airline,
td.scheme,
td.route,
td.detail {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.baggage-detail,
td.refund-detail {
  max-height: 52px;
  color: #3b4658;
}

.truncate {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

th:nth-child(1),
th:nth-child(2) {
  width: 64px;
}

th:nth-child(3) {
  width: 58px;
}

th:nth-child(4) {
  width: 128px;
}

th:nth-child(5) {
  width: 132px;
}

th:nth-child(6) {
  width: 112px;
}

th:nth-child(7) {
  width: 170px;
}

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

th:nth-child(11) {
  width: 110px;
}

.muted,
.empty {
  color: var(--muted);
}

.empty {
  text-align: center;
  padding: 32px;
}

@media (max-width: 900px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .direct-mode {
    align-items: flex-start;
    flex-direction: column;
  }

  .extension-guide ol {
    grid-template-columns: 1fr;
  }

  .search,
  .advanced-grid,
  .fallback {
    grid-template-columns: 1fr 1fr;
  }

  .search button.primary {
    grid-column: span 2;
  }
}

@media (max-width: 560px) {
  .search,
  .advanced-grid,
  .fallback {
    grid-template-columns: 1fr;
  }

  .search button.primary {
    grid-column: auto;
  }

  .progress-steps {
    grid-template-columns: 1fr;
  }

  .progress-sources {
    grid-template-columns: 1fr;
  }
}
