/* print.css — printable timetable page.
 *
 * Every class here is prefixed `pt-`, and that is not cosmetic.
 *
 * The first version used the obvious names — .card, .sheet, .stop, .stop-time,
 * .stop-track — and the printed sheet came out with black bars down the track
 * column and stop lists clipped a third short. styles.css loads first and
 * already defines stop rows for the dashboard's detail panel; those rules
 * matched this page's markup and brought a background and padding with them.
 * The padding made every row taller than budgeted, which is why the lists
 * overflowed. Specificity was no help: the leaked properties were ones this
 * file never declared, and you can't override a declaration you don't make.
 * Defensively resetting background/padding/height would just be guessing at
 * whatever styles.css happens to set today.
 *
 * So: names nothing else in the codebase uses. styles.css is still loaded, for
 * its CSS custom properties (--bg, --text, --muted, …) which the screen chrome
 * below reads. Custom properties are opt-in; rules are not.
 *
 * Layout target: US Letter portrait, 0.4in margins → 7.7in × 10.2in usable.
 * Six cards per sheet in a 2×3 grid, so each cell is ~3.77in × ~3.18in.
 *
 * Budget inside a card (measured, not eyeballed):
 *   card content            2.94in
 *   head + route + date + column labels   0.62in
 *   leaving for stops       2.33in  ≈ 18.6 rows at 7pt/1.2
 *
 * MNR trips run 3–31 stops: median 16, p90 21, max 31 (the long New Haven and
 * Harlem runs). So most cards fit one column and the long tail needs two —
 * two 1.7in columns fit the 3.77in cell and take capacity to ~37.
 *
 * Which cards get two columns is decided by print.js measuring real overflow,
 * not by a stop-count threshold. Card capacity depends on font metrics and
 * whether a long station name wraps, so a hardcoded cutoff is wrong near the
 * boundary — and being wrong means silently clipping stops under
 * `overflow: hidden`, which you'd only discover on paper. For that
 * measurement to mean anything, the screen sheet and the print sheet must be
 * the same size; see the @media screen block.
 *
 * On screen the sheets render as white pages on the app's dark chrome, so
 * what you see is what comes out of the printer.
 */

/* ─── Screen chrome ───────────────────────────────────────────────────────── */

/* The overflow/height declarations here are overrides, not defaults.
   styles.css sets `overflow: hidden` on body because the map is a fixed
   fullscreen app that must never scroll — so every page that isn't the map
   has to opt back out. engines.css opens with `overflow: auto` for exactly
   this reason.

   Note the shorthand. `overflow-y: auto` is not enough: styles.css uses the
   shorthand, so both axes are hidden, and overriding only y leaves x hidden.
   Normally setting one axis non-visible makes the other compute to auto —
   but that only applies when the other is *visible*, and here it's an
   inherited `hidden`. That left anything wider than the viewport
   unreachable. */
html {
  overflow: auto;
  height: auto;
}

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

.pt-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);
}
.pt-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.pt-back {
  color: var(--early);
  text-decoration: none;
  font-size: 13px;
}
.pt-back:hover { text-decoration: underline; }
.pt-headmeta {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

/* ─── Controls ────────────────────────────────────────────────────────────── */

.pt-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(22, 27, 34, 0.6);
}
.pt-ctl { display: flex; flex-direction: column; gap: 6px; }
.pt-ctl label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.pt-ctl-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 6px;
}

#pt-date-select {
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  min-width: 230px;
}
#pt-date-select:focus { border-color: #58a6ff; }

.pt-train-inputs {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
}
.pt-train-input {
  width: 46px;
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 7px 4px;
  font-size: 13px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
}
.pt-train-input:focus { border-color: #58a6ff; }
.pt-train-input::placeholder { color: #3d444d; }

.pt-ctl-actions { flex-direction: row; align-items: center; gap: 8px; }
.pt-btn {
  background: #21262d;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.pt-btn:hover:not(:disabled) { background: #2d333b; }
.pt-btn:disabled { opacity: 0.4; cursor: default; }
.pt-btn-primary {
  background: rgba(88, 166, 255, 0.15);
  border-color: rgba(88, 166, 255, 0.5);
  color: #9ec2eb;
}
.pt-btn-primary:hover:not(:disabled) { background: rgba(88, 166, 255, 0.25); }
.pt-btn-ghost { background: transparent; }

.pt-ctl-status { font-size: 11px; color: var(--muted); margin-left: 4px; }
.pt-ctl-status.ok   { color: var(--early); }
.pt-ctl-status.warn { color: var(--held); }
.pt-ctl-status.err  { color: var(--late); }

.pt-sheets-empty {
  color: var(--muted);
  text-align: center;
  margin-top: 60px;
  font-style: italic;
}

/* ─── Sheets ──────────────────────────────────────────────────────────────── */

.pt-sheets {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px 0 60px;
}

.pt-sheet {
  width: 7.7in;
  background: #fff;
  color: #111;
  padding: 0;
  display: flex;
  flex-direction: column;
  /* Screen only — a paper-ish drop shadow to sell the preview. Removed in
     the print block below so it doesn't render as a grey smudge. */
  box-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}

.pt-sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1.5px solid #111;
  padding-bottom: 3px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.pt-sheet-title {
  font-size: 9pt;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.pt-sheet-page {
  font-size: 7.5pt;
  color: #666;
  font-variant-numeric: tabular-nums;
}

.pt-sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 0.16in;
  flex: 1;
  min-height: 0;
}

/* ─── Card ────────────────────────────────────────────────────────────────── */

.pt-card {
  border: 1px solid #999;
  border-radius: 3px;
  padding: 6px 8px 7px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pt-card-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}
.pt-card-train {
  font-size: 12pt;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.pt-card-branch {
  font-size: 6.5pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.pt-card-branch[data-branch="Hudson"]     { color: #007A2E; }
.pt-card-branch[data-branch="Harlem"]     { color: #0039A6; }
.pt-card-branch[data-branch="New Haven"]  { color: #C1002B; }
.pt-card-branch[data-branch="New Canaan"] { color: #C1002B; }
.pt-card-branch[data-branch="Danbury"]    { color: #C1002B; }
.pt-card-branch[data-branch="Waterbury"]  { color: #C1002B; }
.pt-card-branch[data-branch="Amtrak"]     { color: #00537E; }
.pt-card-peak {
  font-size: 6pt;
  font-weight: 700;
  letter-spacing: 0.3px;
  border: 1px solid #b8860b;
  color: #8a6508;
  border-radius: 2px;
  padding: 0 3px;
  margin-left: auto;
}

.pt-card-route {
  font-size: 7.5pt;
  color: #333;
  margin-top: 1px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pt-card-date {
  font-size: 6.5pt;
  color: #777;
  margin-top: 1px;
  flex-shrink: 0;
}

.pt-card-cols {
  display: grid;
  grid-template-columns: 1fr auto 1.6em;
  gap: 4px;
  font-size: 5.5pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #999;
  border-bottom: 0.5px solid #ccc;
  padding: 3px 0 1px;
  margin-top: 4px;
  flex-shrink: 0;
}
.pt-card-cols span:nth-child(2) { text-align: right; }
.pt-card-cols span:nth-child(3) { text-align: right; }

/* Stop list. Single column by default; JS adds .pt-two-col past ~18 stops.
   column-fill: auto keeps the flow top-to-bottom down column one and then
   into column two, which reads as a continuation of the route rather than
   an interleave. */
.pt-stops {
  list-style: none;
  margin: 0;
  padding: 2px 0 0;
  font-size: 7pt;
  line-height: 1.2;
  flex: 1;
  min-height: 0;
  /* Must clip, not grow: print.js reads scrollHeight against clientHeight to
     detect overflow, which only differ if the box is actually constrained. */
  overflow: hidden;
}
.pt-stops.pt-two-col {
  column-count: 2;
  column-gap: 9px;
  column-fill: auto;
  column-rule: 0.5px solid #eee;
  font-size: 6.5pt;
  line-height: 1.18;
}

.pt-stop {
  display: grid;
  grid-template-columns: 1fr auto 1.6em;
  gap: 4px;
  break-inside: avoid;
  padding: 0.4px 2px;
}

/* Zebra striping. nth-child counts across the whole list rather than per
   column, which is what we want: with column-fill:auto the list flows down
   column one and continues into column two, so a continuous count keeps the
   banding reading as one route rather than restarting halfway.
   No vertical padding is added — rows are already sized to the budget in the
   header comment, and 1px top+bottom would cost ~2 rows of capacity and push
   median-length trains into two columns for nothing. */
.pt-stop:nth-child(even) {
  background: #f0f0f0;
}
.pt-stop-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pt-stop-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}
.pt-stop-dep { color: #888; }
.pt-stop-track {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.pt-card-empty {
  font-size: 7pt;
  color: #999;
  font-style: italic;
  padding-top: 6px;
}

/* ─── Screen sizing ───────────────────────────────────────────────────────── */
/* The sheet on screen is exactly the printable content box — same 7.7in ×
   9.9in, same zero padding as the print rules below. That equality is load
   bearing: print.js decides two-column layout by measuring scrollHeight in
   the browser, and that measurement is only meaningful for the printer if the
   two boxes are identical. The page margin lives in @page, not here. */
@media screen {
  .pt-sheet {
    height: 9.9in;
    padding: 0;
    box-sizing: border-box;
  }
}

/* ─── Phone ───────────────────────────────────────────────────────────────── */
/* A letter sheet is ~740px wide. On a 390px phone that's a 2x reduction —
   7pt stop rows land near 5pt, legible only by pinching and panning. So on a
   narrow screen this stops pretending to be paper: full-width cards, one per
   row, at a size you can actually read. Paper geometry is a print concern,
   and @media print below is untouched by any of this — printing still yields
   6-up letter regardless of the screen it was triggered from. */
@media screen and (max-width: 700px) {
  .pt-header { padding: 10px 12px; gap: 10px; }
  .pt-header h1 { font-size: 13px; }
  .pt-headmeta { display: none; }

  .pt-controls { padding: 12px; gap: 14px; }
  .pt-ctl-date, .pt-ctl-trains { width: 100%; }
  #pt-date-select { width: 100%; min-width: 0; }
  /* Ten 46px boxes need 460px+. Two rows of five fit a phone. */
  .pt-train-inputs { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .pt-train-input { width: 100%; padding: 10px 4px; font-size: 16px; }
  .pt-ctl-actions { width: 100%; }
  .pt-btn { padding: 9px 14px; }

  .pt-sheets { padding: 12px 10px 40px; gap: 14px; align-items: stretch; }

  .pt-sheet {
    width: 100%;
    height: auto;
    padding: 12px;
    border-radius: 8px;
    box-shadow: none;
  }
  .pt-sheet-title { font-size: 12px; }
  .pt-sheet-page  { font-size: 10px; }

  /* One card per row, each as tall as its content needs. */
  .pt-sheet-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    gap: 12px;
  }

  .pt-card { height: auto; overflow: visible; padding: 10px 12px 12px; }
  .pt-card-train  { font-size: 17px; }
  .pt-card-branch { font-size: 9px; }
  .pt-card-peak   { font-size: 8px; }
  .pt-card-route  { font-size: 12px; white-space: normal; }
  .pt-card-date   { font-size: 10px; }
  .pt-card-cols   { font-size: 8px; }

  /* Cards grow, so nothing clips and nothing needs two columns. Two narrow
     columns on a phone would be the opposite of readable. print.js may still
     tag long lists with pt-two-col so a phone-initiated print isn't clipped —
     this keeps that class inert on screen. */
  .pt-stops,
  .pt-stops.pt-two-col {
    font-size: 12px;
    line-height: 1.5;
    overflow: visible;
    column-count: 1;
    column-rule: none;
  }
  .pt-stop { padding: 1px 3px; }
}

/* ─── Print ───────────────────────────────────────────────────────────────── */

@page {
  size: letter portrait;
  margin: 0.4in;
}

@media print {
  .pt-no-print { display: none !important; }

  html, body.pt-page {
    background: #fff !important;
    color: #000 !important;
    margin: 0;
    padding: 0;
    /* Undo the screen scroll container. A scrollable root can make some
       print engines paginate only what was in view rather than the whole
       document. */
    overflow: visible;
    height: auto;
  }

  .pt-sheets {
    display: block;
    padding: 0;
    gap: 0;
  }

  .pt-sheet {
    width: auto;
    height: 9.9in;      /* inside the @page margin box */
    padding: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;   /* legacy alias for older engines */
  }
  .pt-sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  /* Branch colours, the header rule and the zebra striping are meaningful,
     not decoration — ask the browser not to strip them in its ink-saving
     pass, which drops backgrounds by default and would take the striping
     with it. */
  .pt-sheet, .pt-card, .pt-card-branch, .pt-card-peak, .pt-sheet-head, .pt-stop {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pt-card { break-inside: avoid; page-break-inside: avoid; }
}
