/* ══════════════════════════════════════════════════════════════════
   Train Detail Modal CSS — click-through from a Train Station tile.
   .td-* namespace, kept independent of .ts-* so the two modals can
   coexist (Train Station stays visible behind Train Detail).
   Origin: jaunty-chasing-bubble S3 (D3-B).
   ══════════════════════════════════════════════════════════════════ */

.td-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-primary); /* modal-integrity-scan S5: 1450 was anomalously
                                      low (below the 9999 backdrop tier); raised to the
                                      canonical modal tier. Still above Train Station. */
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: tdFadeIn 0.18s ease;
}

@keyframes tdFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.td-modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  animation: tdSlideUp 0.22s ease;
}

@keyframes tdSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.td-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #1f2937 0%, #334155 100%);
  color: #fff;
  flex-shrink: 0;
}

.td-modal-title {
  margin: 0;
  font-size: calc(1.05rem * var(--type-scale, 1));
  font-weight: 700;
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
  letter-spacing: -0.01em;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 0.75rem;
}

.td-close-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: calc(1.3rem * var(--type-scale, 1));
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.td-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.td-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.4rem 1.5rem;
  background: #fff;
  color: #1f2937;
  font-size: calc(0.92rem * var(--type-scale, 1));
  line-height: 1.55;
}

.td-loading,
.td-error {
  text-align: center;
  padding: 2rem 1rem;
  color: #475569;
}

.td-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid #dc2626;
  border-radius: 6px;
  color: #7f1d1d;
  text-align: left;
  padding: 1rem 1.25rem;
}

.td-error pre {
  margin: 0.5rem 0 0;
  font-size: calc(0.78rem * var(--type-scale, 1));
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Banner field grid ────────────────────────────────────────────── */

.td-banner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  background: #f8fafc;
  border-left: 4px solid #0f3057;
  border-radius: 6px;
}

.td-banner-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.5rem;
  align-items: baseline;
}

.td-banner-label {
  font-size: calc(0.7rem * var(--type-scale, 1));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.td-banner-value {
  font-size: calc(0.86rem * var(--type-scale, 1));
  color: #0f172a;
  word-break: break-word;
}

@media (max-width: 580px) {
  .td-banner-row {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }
}

/* ── Sections ─────────────────────────────────────────────────────── */

.td-section {
  margin-bottom: 1.25rem;
}

.td-section-title {
  margin: 0 0 0.6rem;
  font-size: calc(0.82rem * var(--type-scale, 1));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #e2e8f0;
}

/* ── Intro prose ──────────────────────────────────────────────────── */

.td-intro-prose {
  color: #1f2937;
  font-size: calc(0.9rem * var(--type-scale, 1));
  line-height: 1.55;
}

.td-intro-prose p {
  margin: 0 0 0.7rem;
}

.td-intro-prose strong {
  color: #0f172a;
  font-weight: 700;
}

.td-intro-prose em {
  color: #475569;
  font-style: italic;
}

.td-intro-prose code {
  background: #f1f5f9;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: calc(0.82rem * var(--type-scale, 1));
  color: #0f3057;
}

.td-intro-prose a {
  color: #0f3057;
  text-decoration: underline;
}

.td-intro-prose a:hover {
  color: #2c7a9c;
}

/* ── Sessions ─────────────────────────────────────────────────────── */

.td-session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.td-session-item {
  padding: 0.55rem 0.8rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-left: 3px solid #2c7a9c;
  border-radius: 6px;
}

/* Clickable session rows → open that session's full work-plan pop-up. */
.td-session-clickable {
  cursor: pointer;
  transition: box-shadow 0.12s ease, border-left-color 0.12s ease;
}
.td-session-clickable:hover {
  box-shadow: 0 1px 8px rgba(44, 122, 156, 0.18);
  border-left-color: #0f3057;
}
.td-session-arrow {
  color: #2c7a9c;
  font-weight: 400;
}

/* Back link in the per-session pop-up view. */
.td-back-link {
  display: inline-block;
  margin-bottom: 0.6rem;
  font-size: calc(0.82rem * var(--type-scale, 1));
  color: #2c7a9c;
  text-decoration: none;
}
.td-back-link:hover { text-decoration: underline; }

/* Full session work-plan prose — looser line-height for readability. */
.td-session-plan {
  line-height: 1.5;
}

.td-session-title {
  font-size: calc(0.85rem * var(--type-scale, 1));
  font-weight: 700;
  color: #0f172a;
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
  margin-bottom: 0.2rem;
}

.td-session-summary {
  font-size: calc(0.82rem * var(--type-scale, 1));
  color: #475569;
  line-height: 1.45;
}

/* ── Footer ───────────────────────────────────────────────────────── */

.td-modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.7rem 0.85rem;
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: calc(0.74rem * var(--type-scale, 1));
  color: #64748b;
}

.td-plan-path {
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
  font-size: calc(0.72rem * var(--type-scale, 1));
  color: #475569;
  word-break: break-all;
}

.td-mtime {
  font-size: calc(0.72rem * var(--type-scale, 1));
  color: #94a3b8;
}

@media (max-width: 600px) {
  .td-overlay { padding: 0.75rem; }
  .td-modal-body { padding: 1rem; }
  .td-banner { padding: 0.7rem 0.85rem; }
}
