/* ============================================================
   Pairing Viewer PWA — Mobile-first stylesheet
   Breakpoints: tablet 600px, desktop 1024px
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] { display: none !important; }

html, body {
  height: 100%;
  /* Minimum 16px base font prevents iOS auto-zoom on input focus */
  font-size: 16px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #eef2f7;
  color: #1a202c;

}

.hidden { display: none !important; }

/* ── Login ───────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);

  z-index: 1000;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem 1.75rem;
  width: min(90vw, 360px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
}

.login-card h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.375rem;
  color: #2563eb;
}

.login-card label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #64748b;
}

.login-card input {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid #dde3ed;
  border-radius: 7px;
  margin-bottom: 1rem;
  min-height: 44px;
}

.login-card input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.login-card button[type="submit"] {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
}

.login-card button[type="submit"]:hover { background: #1d4ed8; }
.login-card button[type="submit"]:disabled { opacity: 0.65; cursor: default; }

.error-msg {
  background: #f8d7da;
  color: #842029;
  padding: 0.75rem;
  border-radius: 7px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* ── App shell ───────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
  box-shadow: 0 2px 12px rgba(30,58,95,.35);
  color: #fff;
  min-height: 56px;
}

.header-brand {
  font-size: 0.9375rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 1;
  min-width: 0;
}

.file-select {
  font-size: 0.8125rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 7px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 180px;
  min-height: 44px;
  cursor: pointer;
}

/* Option and optgroup text must be dark for readability on white dropdown */
.file-select option, .file-select optgroup { color: #1a202c; background: #fff; }

.btn-icon {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  border-radius: 7px;
  font-size: 1.25rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-text {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  border-radius: 7px;
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.375rem 0.625rem;
  min-height: 44px;
  white-space: nowrap;
}

/* ── Install banner ──────────────────────────────────────── */
.install-banner {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  background: #0f2442;
  color: #fff;
  font-size: 0.8125rem;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.install-banner-text { flex: 1; line-height: 1.35; }

.install-btn {
  background: #fff;
  color: #0f2442;
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.install-btn:hover { background: #dbeafe; }

.install-dismiss-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 1rem;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.install-dismiss-btn:hover { color: #fff; background: rgba(255,255,255,0.12); }

/* ── Body layout ─────────────────────────────────────────── */
.app-body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;   /* filter is fixed on mobile — only results in grid */
  overflow: hidden;
  min-height: 0;
}

/* ── Filter backdrop (mobile only) ──────────────────────── */
.filter-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.38);
  z-index: 299;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.filter-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Drag handle ─────────────────────────────────────────── */
.drag-handle {
  width: 3.25rem;
  height: 0.3125rem;
  background: #aab5c9;
  border-radius: 0.25rem;
  margin: 0.625rem auto 0.25rem;
  flex-shrink: 0;
}

/* ── Filter panel header / collapse toggle ─────────────────── */
.filter-header {
  display: none; /* tablet+ only */
}

.filter-header-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #64748b;
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
}

.filter-collapse-btn {
  background: #e3e8f0;
  border: 1px solid #c7d0de;
  color: #475569;
  cursor: pointer;
  width: 32px;
  height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, transform 0.2s ease;
}
.filter-collapse-btn:hover { background: #cbd5e1; color: #1a202c; }

/* ── Filter panel — mobile bottom sheet ─────────────────── */
.filter-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72dvh;
  background: #eef2f7;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-panel.open {
  transform: translateY(0);
}

.filter-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 1rem 1rem;
}

/* ── Header filter button ────────────────────────────────── */
.btn-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 7px;
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.375rem 0.75rem;
  min-height: 44px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn-filter:hover       { background: rgba(255,255,255,0.25); }
.btn-filter.has-filters { border-color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.22); }

/* ── Active-filter badge ─────────────────────────────────── */
.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ff6b35;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.25rem;
  border-radius: 99px;
  line-height: 1;
}

.filter-scroll h3 {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.75rem;
  color: #1a202c;
}

.filter-section {
  margin-bottom: 0.25rem;
}

/* ── Collapsible section toggle ──────────────────────────── */
.filter-section-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid #dde3ed;
  padding: 0.375rem 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  text-align: left;
  gap: 0.375rem;
  min-height: 36px;
}

.filter-section-toggle:hover { color: #1a202c; }

.section-chevron {
  margin-left: auto;
  display: inline-block;
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  color: #8b93a7;
  flex-shrink: 0;
}

.filter-section.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.section-active-dot {
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: #2563eb;
  flex-shrink: 0;
  display: none;
}

.section-active-dot.visible { display: inline-block; }

.filter-section-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.2s ease;
}

.filter-section.collapsed .filter-section-body {
  grid-template-rows: 0fr;
}

.filter-section-inner {
  overflow: hidden;
  padding-top: 0.375rem;
}

.filter-label {
  display: block;
  width: 100%;
  padding: 0.375rem 0;
  border-bottom: 1px solid #dde3ed;
  font-size: 0.875rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.375rem;
}

.filter-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.625rem;
  font-size: 1rem;
  border: 1px solid #dde3ed;
  border-radius: 7px;
  background: #fff;
  margin-bottom: 0.375rem;
  min-height: 44px;
  color: #1a202c;
}

.filter-input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

/* ── Base chip toggles ───────────────────────────────────── */
.base-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.base-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0.75rem;
  border: 2px solid #2563eb;
  border-radius: 99px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
  min-width: 44px;
  background: #fff;
  color: #2563eb;
  transition: background 0.1s, color 0.1s;
}

.base-chip.selected {
  background: #2563eb;
  color: #fff;
}

/* ── Filter actions ──────────────────────────────────────── */
.filter-actions {
  padding-top: 0.75rem;
  border-top: 1px solid #dde3ed;
  margin-top: 0.5rem;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 0.625rem;
  font-size: 1rem;
  background: #64748b;
  color: #fff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  min-height: 44px;
}

.btn-secondary:hover { background: #4e5e72; }

/* ── Mobile filter tab (bottom bar) ─────────────────────── */
.filter-tab {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1rem;
  min-height: 48px;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 298;
  border-top: 1px solid rgba(255,255,255,0.2);
  user-select: none;
  transition: background 0.15s;
}
.filter-tab:hover { background: linear-gradient(135deg, #254a7a 0%, #2450c5 100%); }

@media (min-width: 600px) {
  .filter-tab { display: none; }
}

/* ── Results panel ───────────────────────────────────────── */
.results-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
}

.results-header {
  padding: 0.5rem 1rem;
  background: #fff;
  border-bottom: 1px solid #dde3ed;
  font-size: 1.0rem; //0.875rem;
  color: #64748b;
  line-height: 1.4;
}

.results-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
}

.placeholder-text {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #64748b;
  text-align: center;
  padding: 2.5rem 1rem;
  font-size: 1rem;
}

/* ── Pairing card ────────────────────────────────────────── */
.pairing-card {
  background: #f5f8fc;
  border: 1px solid #dde3ed;
  border-radius: 12px;
  margin-bottom: 0.5rem;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

.pairing-header {
  background: #d6e0ec;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #dde3ed;
}

.pairing-id-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
}

.p-base  { font-weight: 700; color: #2563eb; }
.p-id    { font-weight: 600; }
.p-days  { background: #64748b; color: #fff; border-radius: 5px;
           padding: 0.1rem 0.375rem; font-size: 0.75rem; }
.p-inst  { color: #64748b; font-size: 0.8125rem; }
.p-month { text-align: center; color: #64748b; font-size: 0.8125rem; font-style: italic; }

.pairing-times-row {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: #1a202c;
}

/* ── Legs ────────────────────────────────────────────────── */
.pairing-body {
  padding: 0.25rem 0.75rem 0.125rem;
  overflow-x: auto;
  display: grid;
  /*  day    DH      flt     dep          arr          gnd     blk     duty  */
  grid-template-columns:
    1.25rem 2.25rem 3rem max-content max-content 3.25rem 3.5rem 3.75rem;
  column-gap: 0.375rem;
  width: max-content;
  min-width: 100%;
}

.leg-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  padding: 0.2rem 0;
  font-size: 0.75rem;
  font-family: 'Courier New', Courier, monospace;
}

.leg-header {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  justify-items: center;
  padding: 0.15rem 0 0.25rem;
  font-size: 0.625rem;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  border-bottom: 1px solid #dde3ed;
}

.leg-wocl { color: #dc3545; background: rgba(220,53,69,0.05); border-radius: 5px; }
.leg-dh   { opacity: 0.6; font-style: italic; }

.dh-badge {
  font-size: 0.625rem;
  background: #64748b;
  color: #fff;
  padding: 0.1rem 0.25rem;
  border-radius: 0.2rem;
  justify-self: start;
}

.leg-day  { color: #64748b; text-align: right; font-size: 0.7rem; }
.leg-flt  { font-weight: 600; }
.leg-gnd  { color: #1a202c; text-align: right; }
.leg-blk  { text-align: right; color: #1a202c; }
.leg-duty { text-align: right; color: #1a202c; font-style: italic; }

.layover-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.75rem;
  font-size: 0.90rem;
  color: #64748b;
  padding: 0.1rem 0 0.3rem 1.5rem;
  border-bottom: 1px solid #dde3ed;
  font-family: 'Courier New', Courier, monospace;
}
.layover-row:last-child { border-bottom: none; }
.layover-sta  { font-weight: 700; min-width: 2rem; }
.layover-gnd  { min-width: 3rem; }
.layover-duty { margin-left: auto; }

/* ── Totals ──────────────────────────────────────────────── */
.pairing-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  background: #f5f8fc;
  border-top: 1px solid #dde3ed;
  color: #1a202c;
  font-family: 'Courier New', Courier, monospace;
}

/* ── Calendar ────────────────────────────────────────────── */
.pairing-calendar {
  padding: 0.375rem 0.75rem 0.5rem;
  border-top: 1px solid #dde3ed;
  background: #eef2f7;
}

.cal-grid {
  font-size: 0.75rem;
  font-family: 'Courier New', Courier, monospace;
  border-collapse: collapse;
}

.cal-grid th {
  text-align: center;
  padding: 0.1rem 0.35rem;
  color: #64748b;
  font-weight: 600;
}

.cal-grid td {
  text-align: center;
  padding: 0.1rem 0.35rem;
  min-width: 1.5rem;
}

.cal-active { font-weight: 700; color: #1a202c; }
.cal-blank  { color: #64748b; }

/* Phone screens: calendar is hidden by default — swipe left on the card to reveal it */
@media (max-width: 759.98px) {
  .pairing-calendar { display: none; }

  .pairing-card.cal-revealed .pairing-calendar {
    display: block;
    animation: cal-reveal 0.2s ease;
  }
}

@keyframes cal-reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Dark theme: cards ───────────────────────────────────── */
html.dark .pairing-card        { background: #1a1d27; border-color: #2a2f3d; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
html.dark .pairing-header      { background: #0f1117; border-color: #2a2f3d; }
html.dark .p-base              { color: #60a5fa; }
html.dark .p-days              { background: #45475a; }
html.dark .p-inst,
html.dark .p-month             { color: #8b93a7; }
html.dark .pairing-times-row   { color: #8b93a7; }
html.dark .leg-header          { color: #64748b; border-color: #2a2f3d; }
html.dark .leg-wocl            { color: #f87171; background: rgba(248,113,113,0.08); }
html.dark .leg-blk,
html.dark .leg-flt,
html.dark .leg-gnd,
html.dark .leg-duty            { color: #e8eaf0; }
html.dark .leg-day             { color: #64748b; }
html.dark .layover-row         { color: #8b93a7; border-color: #2a2f3d; }
html.dark .pairing-footer      { background: #1a1d27; border-color: #2a2f3d; color: #8b93a7; }
html.dark .pairing-calendar    { border-color: #2a2f3d; background: #0f1117; }
html.dark .cal-active          { color: #e8eaf0; }
html.dark .cal-blank           { color: #8b93a7; }

/* ── 760px+: calendar splits to right column ─────────────── */
@media (min-width: 760px) {
  .pairing-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "header  cal"
      "body    cal"
      "footer  cal";
  }

  .pairing-header   { grid-area: header; }
  .pairing-body     { grid-area: body; }
  .pairing-footer   { grid-area: footer; }

  .pairing-calendar {
    grid-area: cal;
    border-top: none;
    border-left: 1px solid #dde3ed;
    padding: 0.625rem 0.875rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  html.dark .pairing-calendar { border-left-color: #2a2f3d; }
}

/* Offline / readonly indicator */
.offline-badge {
  display: inline-block;
  background: #fd7e14;
  color: #fff;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* ── Phone: two-row header ───────────────────────────────── */
@media (max-width: 599px) {
  /* Push content above the fixed filter tab */
  .results-content { padding-bottom: 56px; }
  .app-header {
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.375rem;
    min-height: auto;
  }
  .header-brand {
    padding: 0.25rem 0;
  }
  .header-controls {
    flex-basis: 100%;
  }
  .file-select {
    max-width: none;
  }

  /* Compact leg table to fit portrait width without horizontal scroll */
  .pairing-body {
    grid-template-columns:
      1rem 1.5rem 2.25rem max-content max-content 2.4rem 2.5rem 2.75rem;
    column-gap: 0.2rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  .leg-row    { font-size: 0.6rem; }
  .leg-header { font-size: 0.55rem; }
}


/* ── Tablet 600px+ ───────────────────────────────────────── */
@media (min-width: 600px) {
  /* Filter column is 0 by default; results take full width */
  .app-body {
    grid-template-columns: 0 1fr;
    grid-template-rows: 1fr;
  }

  /* Open: give the filter column its width */
  .app-body.filters-open {
    grid-template-columns: 240px 1fr;
  }

  /* On tablet+: override bottom-sheet, restore to grid sidebar */
  .filter-panel {
    position: static;
    height: auto;
    transform: none;
    transition: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;   /* clips content when grid column is 0 */
    border-bottom: none;
    z-index: auto;
    display: block;     /* restore from flex */
  }

  .filter-panel .drag-handle,
  .filter-backdrop { display: none !important; }

  .filter-panel.open {
    overflow-y: auto;
    border-right: 1px solid #dde3ed;
  }

  /* Restore scroll area padding (no drag handle on tablet+) */
  .filter-scroll { padding: 0.875rem 1rem 1rem; }
  .leg-row { font-size: 1rem; }
  .pairing-body { column-gap: 0.85rem; }
  .results-content { font-size: 0.8125rem; }

  /* Filter panel header */
  .filter-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.375rem 0.25rem 0.75rem;
    background: #eef2f7;
    border-bottom: 1px solid #dde3ed;
    flex-shrink: 0;
    min-height: 36px;
  }

  /* h3 redundant with the header title on tablet+ */
  .filter-scroll h3 { display: none; }

  /* Collapsed sidebar: narrow 40px strip */
  .app-body.filters-open.filters-collapsed {
    grid-template-columns: 40px 1fr;
  }

  .filter-panel.collapsed .filter-scroll { display: none; }

  .filter-panel.collapsed .filter-header {
    flex-direction: column;
    height: 100%;
    border-bottom: none;
    border-right: 1px solid #dde3ed;
    padding: 0.625rem 0 0;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
  }

  .filter-panel.collapsed .filter-header-title { display: none; }

  .filter-panel.collapsed .filter-collapse-btn { transform: rotate(180deg); }
}

/* ── Desktop 1024px+ ─────────────────────────────────────── */
@media (min-width: 1024px) {
  .app-body.filters-open {
    grid-template-columns: 280px 1fr;
  }

  .app-body.filters-open.filters-collapsed {
    grid-template-columns: 40px 1fr;
  }

  .leg-row { font-size: 1rem; }
  .pairing-body { column-gap: 1.2rem; }
  .results-content { font-size: 0.875rem; }
  .file-select { max-width: 260px; }
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: min(96vw, 860px);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(37,99,235,.12), 0 2px 4px rgba(0,0,0,.06);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid #dde3ed;
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: #1a202c;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.125rem;
  cursor: pointer;
  color: #64748b;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}
.modal-close:hover { background: #eef2f7; color: #1a202c; }

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

.modal-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid #dde3ed;
  flex-shrink: 0;
}

.btn-primary {
  padding: 0.5rem 1.125rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.875rem;
  min-height: 44px;
}
.btn-primary:hover { background: #1d4ed8; }

/* ── ARC table ───────────────────────────────────────────── */
.arc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  white-space: nowrap;
}

.arc-table th,
.arc-table td {
  padding: 0.3125rem 0.75rem;
  text-align: center;
  border: 1px solid #dde3ed;
}

.arc-table th {
  background: #eef2f7;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.arc-table td:first-child { text-align: left; font-weight: 500; }
.arc-table tbody tr:nth-child(odd)  { background: #f7f9fc; }
.arc-table tbody tr:hover           { background: #e8f0fe; }

/* ── PDF modal overrides ─────────────────────────────────── */
.modal-content--pdf {
  width: min(98vw, 1100px);
  max-height: 95dvh;
}

.modal-body--pdf {
  padding: 0;
  display: flex;
  flex-direction: column;
}

#pdf-modal-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 70dvh;
  border: none;
  display: block;
}

/* Dark modal */
html.dark .modal-content          { background: #1a1d27; }
html.dark .modal-header           { border-color: #2a2f3d; }
html.dark .modal-title            { color: #e8eaf0; }
html.dark .modal-close            { color: #8b93a7; }
html.dark .modal-close:hover      { background: #2a2f3d; color: #e8eaf0; }
html.dark .modal-footer           { border-color: #2a2f3d; }
html.dark .arc-table th           { background: #0f1117; color: #e8eaf0; }
html.dark .arc-table th,
html.dark .arc-table td           { border-color: #2a2f3d; color: #e8eaf0; }
html.dark .arc-table tbody tr:nth-child(odd)  { background: #12151f; }
html.dark .arc-table tbody tr:hover           { background: #1e2a40; }

/* ── Hamburger dropdown menu ─────────────────────────────── */
.hamburger-wrap {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 0.375rem);
  left: 0;
  background: #fff;
  border: 1px solid #dde3ed;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  min-width: 170px;
  z-index: 200;
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid #dde3ed;
  text-align: left;
  font-size: 0.9375rem;
  color: #1a202c;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.1s;
}

.menu-item:last-child { border-bottom: none; }
.menu-item:hover      { background: #eef2f7; }

.menu-divider {
  border: none;
  border-top: 1px solid #dde3ed;
  margin: 0;
}

.menu-username {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

html.dark .menu-divider              { border-color: #2a2f3d; }
html.dark .menu-username             { color: #8b93a7; }

.menu-item--danger            { color: #dc3545; }
.menu-item--danger:hover      { background: #fff0f0; }
html.dark .menu-item--danger  { color: #f87171; }
html.dark .menu-item--danger:hover { background: #2d1a1a; }

#filter-menu-icon,
#theme-icon {
  font-size: 0.875rem;
  width: 1.125rem;
  text-align: center;
  flex-shrink: 0;
}

/* ── Dark theme ──────────────────────────────────────────── */
/* Applied via .dark on <html>. Override only what changes.  */

html.dark,
html.dark body                  { background: #0f1117; color: #e8eaf0; }

html.dark .app-header           { background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%); }

html.dark .filter-backdrop      { background: rgba(0,0,0,0.6); }
html.dark .filter-panel         { background: #1a1d27; box-shadow: 0 -4px 24px rgba(0,0,0,0.45); }
html.dark .drag-handle          { background: #6b7285; }
html.dark .filter-scroll h3     { color: #e8eaf0; }
html.dark .filter-section-toggle         { color: #8b93a7; border-color: #2a2f3d; }
html.dark .filter-section-toggle:hover  { color: #e8eaf0; }
html.dark .filter-label                 { color: #8b93a7; border-color: #2a2f3d; }
html.dark .section-active-dot           { background: #60a5fa; }
html.dark .filter-header                { background: #1a1d27; border-color: #2a2f3d; }
html.dark .filter-header-title          { color: #8b93a7; }
html.dark .filter-collapse-btn          { background: #262b38; border-color: #3a4152; color: #b7c0d1; }
html.dark .filter-collapse-btn:hover    { background: #333a4a; color: #e8eaf0; }
html.dark .filter-panel.collapsed .filter-header { border-right-color: #2a2f3d; }

html.dark .filter-input {
  background: #0f1117;
  color: #e8eaf0;
  border-color: #2a2f3d;
}
/* Keep dropdown option text readable on system-rendered selects */
html.dark .filter-input option  { background: #1a1d27; color: #e8eaf0; }

html.dark .base-chip            { background: #1a1d27; color: #60a5fa; border-color: #60a5fa; }
html.dark .base-chip.selected   { background: #60a5fa; color: #0f1117; }

html.dark .filter-actions       { border-color: #2a2f3d; }
html.dark .btn-secondary        { background: #2a2f3d; }
html.dark .btn-secondary:hover  { background: #374151; }

html.dark .results-header {
  background: #1a1d27;
  border-color: #2a2f3d;
  color: #8b93a7;
}
html.dark .results-content      { background: #0f1117; color: #e8eaf0; }
html.dark .placeholder-text     { color: #8b93a7; }

html.dark .login-card           { background: #1a1d27; }
html.dark .login-card h2        { color: #60a5fa; }
html.dark .login-card label     { color: #8b93a7; }
html.dark .login-card input {
  background: #0f1117;
  color: #e8eaf0;
  border-color: #2a2f3d;
}

html.dark .menu-dropdown        { background: #1a1d27; border-color: #2a2f3d; box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
html.dark .menu-item            { color: #e8eaf0; border-color: #2a2f3d; }
html.dark .menu-item:hover      { background: #2a2f3d; }

html.dark .file-select {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.25);
}

/* ── AI Smart Filter Chat ────────────────────────────────── */

/* Floating action button */
.chat-fab {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: #1e3a5f;
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(30,58,95,0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 350;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.chat-fab:hover {
  background: #2563eb;
  transform: scale(1.07);
  box-shadow: 0 6px 18px rgba(37,99,235,0.45);
}

/* Chat panel — mobile: bottom sheet */
.chat-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60dvh;
  background: #fff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 400;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel.open { transform: translateY(0); }

/* Panel header */
.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
  color: #fff;
  flex-shrink: 0;
}

.chat-panel-title {
  font-size: 0.9375rem;
  font-weight: 700;
  flex: 1;
}

.chat-action-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 6px;
  font-size: 0.8125rem;
  padding: 0.25rem 0.625rem;
  cursor: pointer;
  min-height: 32px;
  transition: background 0.15s;
}
.chat-action-btn:hover { background: rgba(255,255,255,0.3); }

.chat-close-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 1.125rem;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.chat-close-btn:hover { color: #fff; background: rgba(255,255,255,0.15); }

/* Message list */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-intro {
  font-size: 0.875rem;
  color: #64748b;
  text-align: center;
  padding: 0.5rem 0.25rem;
  line-height: 1.5;
}
.chat-intro em { font-style: italic; color: #2563eb; }

/* Message bubbles */
.chat-msg {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-msg--user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg--assistant {
  align-self: flex-start;
  background: #eef2f7;
  color: #1a202c;
  border-bottom-left-radius: 4px;
}

.chat-msg--typing {
  color: #64748b;
  font-style: italic;
}

/* Input row */
.chat-input-row {
  display: flex;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid #dde3ed;
  background: #fff;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #dde3ed;
  border-radius: 8px;
  background: #fff;
  color: #1a202c;
  min-height: 44px;
}
.chat-input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.chat-send-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.125rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.chat-send-btn:hover    { background: #1d4ed8; }
.chat-send-btn:disabled { opacity: 0.5; cursor: default; }

/* Tablet 600px+: right-side sliding panel */
@media (min-width: 600px) {
  .chat-fab {
    bottom: 1.5rem;
    right: 1.5rem;
  }

  .chat-panel {
    top: 56px;   /* height of .app-header */
    bottom: 0;
    left: auto;
    right: 0;
    width: 360px;
    height: auto;
    border-radius: 0;
    border-left: 1px solid #dde3ed;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    transform: translateX(100%);
  }
  .chat-panel.open { transform: translateX(0); }
}

/* Dark mode */
html.dark .chat-fab {
  background: #1e3a5f;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
html.dark .chat-fab:hover { background: #2563eb; }

html.dark .chat-panel         { background: #1a1d27; border-color: #2a2f3d; box-shadow: -4px 0 20px rgba(0,0,0,0.4); }
html.dark .chat-panel-header  { background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%); }
html.dark .chat-intro         { color: #8b93a7; }
html.dark .chat-intro em      { color: #60a5fa; }
html.dark .chat-msg--assistant { background: #2a2f3d; color: #e8eaf0; }
html.dark .chat-msg--typing   { color: #8b93a7; }
html.dark .chat-input-row     { background: #1a1d27; border-color: #2a2f3d; }
html.dark .chat-input         { background: #0f1117; color: #e8eaf0; border-color: #2a2f3d; }