/* ==========================================================================
   WebFIDS – stylesheet
   --------------------------------------------------------------------------
   • All colours derive from three tokens (--fids-fg, --fids-bg, --fids-accent)
     so a host page can hand us its palette and everything stays coherent.
   • Layout responds to the widget's own width (container queries), so it fits
     any iframe or column: wide ≥ 720px, compact 480–719px, narrow < 480px.
   • Table semantics survive the grid layouts thanks to explicit ARIA roles in
     the markup; this file never changes the DOM order.
   ========================================================================== */

/* When the widget is the whole document (iframe), stay transparent so the host
   page's background shows through and the iframe can be auto-sized. */
.fids-document,
.fids-document body { margin: 0; background: transparent; }

.fids {
  /* ---- tokens: light (default) ---- */
  --fids-font-family: sans-serif;
  --fids-font-size: 1rem;
  --fids-line-height: 1.4;
  --fids-fg: #1f2937;
  --fids-bg: #ffffff;
  --fids-accent: #0b5cad;
  --fids-status-ok: #15803d;
  --fids-status-warn: #a16207;
  --fids-status-bad: #b91c1c;
  --fids-status-info: #1d4ed8;
  --fids-status-alt: #6d28d9;
  --fids-radius: 6px;
  --fids-logo-size: 2em;
  --fids-cell-x: 0.75em;
  --fids-cell-y: 0.6em;

  /* ---- derived ---- */
  --fids-muted: color-mix(in srgb, var(--fids-fg) 72%, var(--fids-bg));
  --fids-border: color-mix(in srgb, var(--fids-fg) 14%, var(--fids-bg));
  --fids-border-strong: color-mix(in srgb, var(--fids-fg) 58%, var(--fids-bg));
  --fids-stripe: color-mix(in srgb, var(--fids-fg) 4%, var(--fids-bg));
  --fids-head-bg: color-mix(in srgb, var(--fids-fg) 7%, var(--fids-bg));
  --fids-hover: color-mix(in srgb, var(--fids-accent) 10%, var(--fids-bg));

  container: fids / inline-size;
  box-sizing: border-box;
  font-family: var(--fids-font-family);
  font-size: var(--fids-font-size);
  line-height: var(--fids-line-height);
  color: var(--fids-fg);
  background: var(--fids-bg);
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
}
.fids *, .fids *::before, .fids *::after { box-sizing: inherit; }

/* ---- dark tokens ---- */
.fids[data-theme="dark"] {
  --fids-fg: #e5e7eb;
  --fids-bg: #111827;
  --fids-accent: #7cc4ff;
  --fids-status-ok: #4ade80;
  --fids-status-warn: #fbbf24;
  --fids-status-bad: #f87171;
  --fids-status-info: #93c5fd;
  --fids-status-alt: #c4b5fd;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  .fids[data-theme="system"] {
    --fids-fg: #e5e7eb;
    --fids-bg: #111827;
    --fids-accent: #7cc4ff;
    --fids-status-ok: #4ade80;
    --fids-status-warn: #fbbf24;
    --fids-status-bad: #f87171;
    --fids-status-info: #93c5fd;
    --fids-status-alt: #c4b5fd;
    color-scheme: dark;
  }
}

/* ---- utilities ---- */
.fids-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.fids :focus-visible {
  outline: 3px solid var(--fids-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---- header ---- */
.fids-header {
  display: flex;
  align-items: center;
  gap: 0.75em;
  padding: 0.5em var(--fids-cell-x) 0.75em;
  border-bottom: 1px solid var(--fids-border);
}
.fids-airport-logo { height: 2.5em; width: auto; max-width: 40%; }
.fids-title { margin: 0; font-size: 1.35em; font-weight: 700; line-height: 1.2; }

/* ---- toolbar ---- */
.fids-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5em 1em;
  padding: 0.5em var(--fids-cell-x) 0;
  border-bottom: 1px solid var(--fids-border);
}

/* Locked to one flight type with search off: only the sr-only heading remains, so drop the empty strip. */
.fids-toolbar:not(:has(.fids-tablist, .fids-search)) { padding: 0; border-bottom: 0; }

.fids-tablist { display: flex; gap: 0.25em; margin-bottom: -1px; }
.fids-tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  margin: 0;
  padding: 0.6em 1em;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  color: var(--fids-muted);
  cursor: pointer;
  border-radius: var(--fids-radius) var(--fids-radius) 0 0;
  transition: background-color 0.15s, color 0.15s;
}
.fids-tab:hover { background: var(--fids-hover); color: var(--fids-fg); }
.fids-tab[aria-selected="true"] { color: var(--fids-accent); border-bottom-color: var(--fids-accent); }
.fids-tab:focus-visible { outline-offset: -3px; }

.fids-search {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0 0 0.5em;
}
.fids-search-label { font-weight: 600; white-space: nowrap; }
.fids-search-input {
  font: inherit;
  color: var(--fids-fg);
  background: var(--fids-bg);
  border: 1px solid var(--fids-border-strong);
  border-radius: var(--fids-radius);
  padding: 0.45em 0.7em;
  min-height: 2.5em;
  min-width: 12em;
  width: 16em;
  max-width: 100%;
}
.fids-search-input::placeholder { color: var(--fids-muted); opacity: 1; }

/* ---- panels / table (wide layout = native table) ---- */
.fids-panel[hidden] { display: none; }
.fids-scroll { overflow-x: auto; }   /* only matters in browsers without container-query support */

.fids-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.fids-table th,
.fids-table td {
  padding: var(--fids-cell-y) var(--fids-cell-x);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--fids-border);
}
.fids-table th {
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fids-muted);
  background: var(--fids-head-bg);
  white-space: nowrap;
}
.fids-table tbody tr:nth-child(even of :not([hidden])) { background: var(--fids-stripe); }
/* Filtered/paged-out rows. Must outrank the `tr { display: grid }` rules in the container
   queries below, otherwise the browser's own [hidden] { display: none } loses to them. */
.fids-table tr[hidden] { display: none; }
.fids-table [data-col="time"],
.fids-table [data-col="gate"],
.fids-table [data-col="claim"],
.fids-table [data-col="flight"] { white-space: nowrap; }
.fids-table [data-col="gate"],
.fids-table [data-col="claim"] { text-align: center; }
.fids-table [data-col="flight"] { font-variant-numeric: tabular-nums; }

.fids-airline { display: flex; align-items: center; gap: 0.5em; }
.fids-logo {
  flex: none;
  width: var(--fids-logo-size);
  height: var(--fids-logo-size);
  border-radius: 4px;
  object-fit: contain;
  background: #fff;
}
.fids-airline-name { font-weight: 600; }
.fids-city-code { color: var(--fids-muted); font-size: 0.85em; margin-inline-start: 0.15em; }
.fids-empty { color: var(--fids-muted); }

.fids-status { font-weight: 600; }
.fids-status[data-status="ontime"],
.fids-status[data-status="early"],
.fids-status[data-status="arrived"],
.fids-status[data-status="departed"] { color: var(--fids-status-ok); }
.fids-status[data-status="delayed"] { color: var(--fids-status-warn); }
.fids-status[data-status="cancelled"],
.fids-status[data-status="diverted"] { color: var(--fids-status-bad); }
.fids-status[data-status="boarding"] { color: var(--fids-status-info); }

.fids-message-row td { text-align: center; color: var(--fids-muted); padding: 1.5em var(--fids-cell-x); }
.fids-panel[aria-busy="true"] .fids-table tbody { opacity: 0.6; }

/* ---- pagination (only built when rows > 0 and pagination is on; hidden with a single page) ---- */
.fids-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5em 0.75em;
  padding: 0.6em var(--fids-cell-x);
  border-bottom: 1px solid var(--fids-border);
}
.fids-pager[hidden] { display: none; }
.fids-pager-btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  color: var(--fids-fg);
  background: var(--fids-bg);
  border: 1px solid var(--fids-border-strong);
  border-radius: var(--fids-radius);
  margin: 0;
  padding: 0.5em 1em;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
  transition: background-color 0.15s;
}
.fids-pager-btn:hover { background: var(--fids-hover); }
.fids-pager-btn[aria-disabled="true"] { color: var(--fids-muted); border-color: var(--fids-border); background: none; cursor: default; }
.fids-pager-btn[data-dir="prev"]::before { content: "‹ " / ""; }
.fids-pager-btn[data-dir="next"]::after { content: " ›" / ""; }
.fids-pager-status { min-width: 7em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---- footer ---- */
.fids-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25em 1em;
  padding: 0.6em var(--fids-cell-x);
  font-size: 0.85em;
  color: var(--fids-muted);
}
.fids-footer p { margin: 0; }
.fids-notice[data-kind="stale"],
.fids-notice[data-kind="error"] { color: var(--fids-status-warn); font-weight: 600; }
.fids-notice[data-kind="error"] { color: var(--fids-status-bad); }

/* ==========================================================================
   COMPACT  (480–719px): four visual columns
     Airline      From/To      Time      Gate
     Flight                    Status
   ========================================================================== */
@container fids (max-width: 719.98px) {
  /* The airline column fits its content (logo + longest airline name, capped at 45%);
     the city column, whose names run longer, takes all remaining space. */
  .fids-table { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr) auto auto; }
  .fids-table caption { display: block; }
  .fids-table thead,
  .fids-table tbody { display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; }
  .fids-table tr {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
    grid-template-areas:
      "airline city time gate"
      "flight  city status gate";
    column-gap: 0.75em;
    row-gap: 0;
    align-items: start;
    padding: 0.5em var(--fids-cell-x);
    border-bottom: 1px solid var(--fids-border);
  }
  .fids-table[data-columns~="claim"] tr {
    grid-template-areas:
      "airline city time gate"
      "flight  city status claim";
  }
  .fids-table thead tr { padding-top: 0.4em; padding-bottom: 0.4em; background: var(--fids-head-bg); }
  .fids-table th,
  .fids-table td { display: block; padding: 0; border: 0; background: none; min-width: 0; line-height: 1.25; }
  /* Stacked pairs sit on consecutive lines; the logo hangs down beside both lines. */
  .fids-airline { align-items: flex-start; }
  .fids-airline .fids-logo { margin-bottom: calc(1.25em - var(--fids-logo-size)); }
  .fids-table [data-col="airline"] { grid-area: airline; }
  .fids-table [data-col="flight"]  { grid-area: flight; }
  .fids-table [data-col="city"]    { grid-area: city; align-self: center; }
  .fids-table [data-col="time"]    { grid-area: time; }
  .fids-table [data-col="status"]  { grid-area: status; }
  .fids-table [data-col="gate"]    { grid-area: gate; align-self: center; }
  .fids-table [data-col="claim"]   { grid-area: claim; }
  .fids-table [data-col="gate"],
  .fids-table [data-col="claim"] { text-align: center; }
  /* With a claim column, gate and claim stack as two bare numbers, so label them. */
  .fids-table[data-columns~="claim"] [data-col="gate"],
  .fids-table[data-columns~="claim"] [data-col="claim"] { text-align: end; align-self: start; }
  .fids-table[data-columns~="claim"] td[data-col="gate"] .fids-gate::before,
  .fids-table[data-columns~="claim"] td[data-col="claim"] .fids-claim::before { content: attr(data-label) " " / ""; font-weight: 400; color: var(--fids-muted); }
  .fids-table td[data-col="flight"] { padding-inline-start: calc(var(--fids-logo-size) + 0.5em); color: var(--fids-muted); }
  .fids-table [data-col="status"],
  .fids-table [data-col="time"] { white-space: normal; }
  .fids-table td[data-col="status"] { font-size: 0.92em; }
  .fids-city-code { display: none; }
  .fids-message-row td,
  .fids-table [data-col="message"] { grid-column: 1 / -1; grid-area: auto; }
  .fids-table th[data-col="flight"] { padding-inline-start: 0; }
}

/* ==========================================================================
   NARROW  (< 480px): two visual columns
     [logo] Airline        Time
            Flight         Status
            From/To        Gate 2
   ========================================================================== */
@container fids (max-width: 479.98px) {
  .fids-table { grid-template-columns: minmax(0, 1fr) auto; }
  .fids-table tr {
    grid-template-areas:
      "airline time"
      "flight  status"
      "city    gate";
    column-gap: 1em;
  }
  .fids-table[data-columns~="claim"] tr {
    grid-template-areas:
      "airline time"
      "flight  status"
      "city    gate"
      "city    claim";
  }
  .fids-table thead {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .fids-table [data-col="time"],
  .fids-table [data-col="status"],
  .fids-table [data-col="gate"],
  .fids-table [data-col="claim"] { text-align: end; align-self: start; }
  .fids-table [data-col="city"] { align-self: start; padding-inline-start: calc(var(--fids-logo-size) + 0.5em); }
  .fids-table [data-col="gate"] .fids-gate::before  { content: attr(data-label) " " / ""; font-weight: 400; color: var(--fids-muted); }
  .fids-table [data-col="claim"] .fids-claim::before { content: attr(data-label) " " / ""; font-weight: 400; color: var(--fids-muted); }
  .fids-table td[data-col="gate"] .fids-empty,
  .fids-table td[data-col="claim"] .fids-empty { display: none; }

  .fids-toolbar { flex-direction: column; align-items: stretch; }
  .fids-pager { justify-content: space-between; }
  .fids-tablist { justify-content: stretch; }
  .fids-tab { flex: 1; text-align: center; }
  .fids-search { flex-wrap: wrap; }
  .fids-search-input { width: 100%; }
}

/* ==========================================================================
   User preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .fids *, .fids *::before, .fids *::after { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .fids { --fids-border: CanvasText; --fids-border-strong: CanvasText; }
  .fids-tab[aria-selected="true"] { border-bottom-color: Highlight; text-decoration: underline; }
  .fids-pager-btn[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
  .fids-table tbody tr { border-bottom: 1px solid CanvasText; }
  .fids-logo { background: Canvas; }
}

@media print {
  .fids-tablist, .fids-search, .fids-pager { display: none !important; }
  .fids-toolbar { padding: 0; border-bottom: 0; }
  .fids { font-size: 11pt; }
  .fids-table tr { break-inside: avoid; }
}
