/* engines.css — styles specific to the locomotive history page */

body.engines-page {
  overflow: auto;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: 0;
}

.engines-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(22, 27, 34, 0.95);
  flex-shrink: 0;
}
.engines-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.engines-meta { margin-left: auto; color: var(--muted); font-size: 11px; }

.engines-main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.engines-list-pane {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  background: rgba(22, 27, 34, 0.6);
}
.engines-search-wrap {
  padding: 12px;
  border-bottom: 1px solid var(--panel-border);
}
.engines-search-wrap input {
  width: 100%;
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.engines-search-wrap input:focus { border-color: #58a6ff; }
.engines-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.engines-list .engine-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  font-variant-numeric: tabular-nums;
}
.engines-list .engine-row:hover { background: rgba(255, 255, 255, 0.04); }
.engines-list .engine-row.active {
  background: rgba(88, 166, 255, 0.1);
  border-left-color: var(--early);
}
.engines-list .engine-row.heritage {
  border-left-color: #f5c842;
}
.engine-num {
  font-weight: 600;
  font-size: 14px;
  min-width: 50px;
}
/* Heritage badge inline next to the engine number — occupies the meta column,
   pushing the actual "last seen" meta to the right side via flex */
.engine-heritage {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(245, 200, 66, 0.12);
  border: 1px solid rgba(245, 200, 66, 0.35);
  color: #f5c842;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  white-space: nowrap;
  grid-column: 2;
  justify-self: start;
}
/* When heritage badge is present, push the "last seen" meta into a fourth row position */
.engine-row.heritage { grid-template-columns: auto auto 1fr auto; }
.engine-row.heritage .engine-meta { grid-column: 3; }
.engine-meta {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.engine-trips {
  background: #21262d;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.engines-detail-pane {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
  min-width: 0;
}
.engines-empty {
  color: var(--muted);
  text-align: center;
  margin-top: 80px;
  font-style: italic;
}

.engines-detail h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.engines-detail .detail-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}
.trips-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 16px;
  border-radius: 6px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.25);
  color: #9ec2eb;
  font-size: 11px;
}
.trips-tip::before {
  content: "💡";
  font-size: 12px;
  filter: grayscale(0.2);
}

.trips-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.trips-table th {
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.02);
  position: sticky;
  top: 0;
}
.trips-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #21262d;
}
.trips-table tr:hover td { background: rgba(255, 255, 255, 0.03); }
.trips-table .trip-train {
  font-weight: 600;
  color: var(--text);
}
.trips-table .trip-branch {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: #21262d;
  margin-right: 6px;
}
.trips-table .trip-branch[data-branch="Hudson"]     { color: #009B3A; }
.trips-table .trip-branch[data-branch="Harlem"]     { color: #0039A6; }
.trips-table .trip-branch[data-branch="New Haven"]  { color: #EE0034; }
.trips-table .trip-branch[data-branch="New Canaan"] { color: #EE0034; }
.trips-table .trip-branch[data-branch="Danbury"]    { color: #EE0034; }
.trips-table .trip-branch[data-branch="Waterbury"]  { color: #EE0034; }
.trips-table .trip-branch[data-branch="Amtrak"]     { color: #00537E; }
.trips-table .trip-route { color: var(--muted); }
.trips-table .trip-peak {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 9px;
  background: rgba(210, 153, 34, 0.2);
  color: var(--held);
  font-weight: 600;
}
.trips-table .open-link {
  color: var(--early);
  text-decoration: none;
  font-size: 11px;
}
.trips-table .open-link:hover { text-decoration: underline; }
.trips-table .trip-time { color: var(--muted); font-size: 11px; }

/* Drilldown back button — visible on mobile, hidden on desktop */
.engines-back-to-list {
  display: none;
  background: transparent;
  border: 0;
  color: var(--early);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 0 0 8px 0;
  margin-bottom: 4px;
}
.engines-back-to-list:hover { color: var(--text); }

/* Mobile drilldown layout */
@media (max-width: 768px) {
  /* Header tightens up */
  .engines-header {
    padding: 10px 14px;
    gap: 10px;
  }
  .engines-header h1 { font-size: 13px; }
  .engines-meta {
    display: none;        /* archive range takes too much room; show in list instead */
  }

  .engines-main {
    flex-direction: column;
  }

  /* Both panes are full width; visibility is toggled by body.view-* class */
  .engines-list-pane,
  .engines-detail-pane {
    width: 100%;
    min-width: 0;
    max-height: none;
    border: 0;
  }

  /* Default: show list, hide detail */
  body.engines-page .engines-list-pane { display: flex; }
  body.engines-page .engines-detail-pane { display: none; }

  /* When viewing detail: hide list, show detail with a back button */
  body.engines-page.view-detail .engines-list-pane { display: none; }
  body.engines-page.view-detail .engines-detail-pane { display: block; }
  body.engines-page.view-detail .engines-back-to-list { display: block; }

  /* Make the detail-pane scroll naturally with the body, not as a nested
     scroll region — fixes the dual-scroll awkwardness */
  .engines-detail-pane {
    padding: 14px 16px;
    overflow-y: visible;
  }

  /* List takes its natural height, scrolls with the body */
  .engines-list-pane {
    flex: 1;
    overflow-y: visible;
  }
  .engines-list {
    overflow-y: visible;
    max-height: none;
  }

  /* Body itself scrolls */
  body.engines-page {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .engines-main { flex: none; min-height: 0; }

  /* Bigger tap targets */
  .engines-list .engine-row { padding: 12px 16px; }
  .engine-num { font-size: 16px; }

  /* Smaller detail heading */
  .engines-detail h2 { font-size: 18px; }
  .trips-table { font-size: 11px; }
  .trips-table th, .trips-table td { padding: 6px 6px; }

  /* The trips table has 7 columns; on a narrow screen drop the date column
     (it's already encoded in "Active") and the peak column (less interesting
     than route) so the rest can breathe */
  .trips-table th:nth-child(3),
  .trips-table td:nth-child(3),
  .trips-table th:nth-child(4),
  .trips-table td:nth-child(4) {
    display: none;
  }
}

/* Heritage banner shown above the trip table on heritage-unit detail pages */
.engine-heritage-banner {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(245, 200, 66, 0.12) 0%, rgba(245, 200, 66, 0.04) 100%);
  border: 1px solid rgba(245, 200, 66, 0.4);
}
.engine-heritage-swatches {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}
.engine-heritage-swatches .swatch {
  display: block;
  width: 36px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.engine-heritage-text { flex: 1; min-width: 0; }
.engine-heritage-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #f5c842;
}
.engine-heritage-scheme {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-top: 3px;
}
.engine-heritage-desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}
.engine-heritage-debut {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-style: italic;
}
h2 .heritage-star {
  color: #f5c842;
  font-size: 0.8em;
  vertical-align: middle;
  margin-left: 4px;
}

/* Trip rows are clickable to expand showing the consist diagram */
.trips-table tr.trip-row { cursor: pointer; }
.trips-table tr.trip-row:hover { background: rgba(255, 255, 255, 0.03); }
.trips-table tr.trip-row.expanded { background: rgba(88, 166, 255, 0.06); }
.trip-expand-icon {
  display: inline-block;
  width: 10px;
  color: var(--muted);
  font-size: 10px;
  transition: transform 0.15s;
}
.trip-row.expanded .trip-expand-icon { color: var(--text); }

.trips-table tr.trip-consist-row td {
  padding: 0;
  border-bottom: 1px solid var(--panel-border);
}
.trip-consist {
  padding: 10px 14px 14px 28px;
  background: rgba(0, 0, 0, 0.15);
}
.consist-header {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.consist-strip {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 600px;
}
.consist-loading,
.consist-error,
.consist-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}
.consist-error { color: var(--late); }
