/* Admin "why was this word picked" trace dialog, opened from the icon
   column on the session review table. Markup: app/views/child_game_sessions/
   _trace_dialog.html.erb. Behaviour: app/javascript/controllers/
   trace_dialog_controller.js. */

.trace-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: none;
  padding: 0;
  /* Background + rounded corners live on the dialog itself so the backdrop
     doesn't leak through the card's rounded corners. */
  background: #fff;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 40px 80px -20px rgba(0, 0, 0, 0.55),
    0 20px 40px -20px rgba(0, 0, 0, 0.35);
  color: #0F172A;
}

.trace-dialog::backdrop {
  background: rgba(8, 47, 106, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.trace-dialog[open] { animation: trace-in 0.18s ease-out; }

@keyframes trace-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.trace-dialog-card {
  position: relative;
  padding: 24px 24px 20px;
  max-height: inherit;
  overflow-y: auto;
}

.trace-dialog-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #F1F5F9;
  color: #475569;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.trace-dialog-close:hover { background: #E2E8F0; color: #0F172A; }

.trace-dialog-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding-right: 36px;
}

.trace-dialog-eyebrow {
  font-size: 11px;
  font-weight: 800;
  color: #64748B;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.trace-dialog-title {
  font-size: 20px;
  font-weight: 800;
  color: #0F172A;
  margin: 0;
  letter-spacing: -0.01em;
}

.trace-dialog-facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
  padding: 14px 16px;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  margin-bottom: 18px;
  font-size: 13px;
}
.trace-dialog-facts div { display: flex; flex-direction: column; gap: 2px; }
.trace-dialog-facts dt {
  font-size: 10px;
  font-weight: 800;
  color: #64748B;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.trace-dialog-facts dd { color: #0F172A; font-weight: 700; margin: 0; }
/* Spans both columns for long list names that shouldn't squeeze. */
.trace-dialog-facts-wide { grid-column: 1 / -1; }
.trace-dialog-facts-wide dd {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.trace-list-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #F1F5F9;
  color: #334155;
  box-shadow: inset 0 0 0 1px #E2E8F0;
}
.trace-list-chip[data-list-type="statutory"]     { background: #FEF3C7; color: #92400E; box-shadow: inset 0 0 0 1px #FDE68A; }
.trace-list-chip[data-list-type="spelling_rule"] { background: #EDE9FE; color: #5B21B6; box-shadow: inset 0 0 0 1px #DDD6FE; }
.trace-list-chip[data-list-type="topic"]         { background: #DBEAFE; color: #1E40AF; box-shadow: inset 0 0 0 1px #BFDBFE; }
.trace-list-chip[data-list-type="custom"]        { background: #E0F2FE; color: #075985; box-shadow: inset 0 0 0 1px #BAE6FD; }
.trace-list-chip[data-list-type="weekly"]        { background: #D1FAE5; color: #065F46; box-shadow: inset 0 0 0 1px #A7F3D0; }

.trace-section { margin-bottom: 18px; }
.trace-section:last-of-type { margin-bottom: 0; }

.trace-section-title {
  font-size: 13px;
  font-weight: 800;
  color: #0F172A;
  margin: 0 0 4px;
}

.trace-section-sub {
  font-size: 12px;
  color: #64748B;
  margin: 0 0 10px;
}

/* Horizontal source budget bar — matches the public how-it-works page. */
.trace-bar {
  display: flex;
  width: 100%;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #F1F5F9;
}
.trace-bar-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  min-width: 0;
  white-space: nowrap;
  padding: 0 6px;
}
.trace-bar-seg[data-src="statutory"] { background: #FEF3C7; color: #92400E; }
.trace-bar-seg[data-src="assigned"]  { background: #EDE9FE; color: #5B21B6; }
.trace-bar-seg[data-src="weekly"]    { background: #D1FAE5; color: #065F46; }

/* Per-source progress rows */
.trace-source-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trace-source-row {
  display: grid;
  grid-template-columns: 90px 1fr 60px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.trace-source-label { font-weight: 700; color: #0F172A; }

.trace-source-meter {
  position: relative;
  height: 8px;
  background: #F1F5F9;
  border-radius: 999px;
  overflow: hidden;
}
.trace-source-meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: #CBD5E1;
  border-radius: 999px;
  transition: width 0.2s ease;
}
.trace-source-row[data-src="statutory"] .trace-source-meter-fill { background: #F59E0B; }
.trace-source-row[data-src="assigned"]  .trace-source-meter-fill { background: #8B5CF6; }
.trace-source-row[data-src="weekly"]    .trace-source-meter-fill { background: #10B981; }

.trace-source-nums {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #475569;
}

/* Year tier rows use the same meter style but different palette. */
.trace-tier-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trace-tier-row {
  display: grid;
  grid-template-columns: 140px 1fr 60px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.trace-tier-row[data-inscope="false"] { opacity: 0.55; }

.trace-tier-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #0F172A;
}

.trace-tier-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.trace-tier-dot[data-tier="current"] { background: #F59E0B; }
.trace-tier-dot[data-tier="below"]   { background: #3B82F6; }
.trace-tier-dot[data-tier="above"]   { background: #EC4899; }
.trace-tier-row[data-tier="current"] .trace-source-meter-fill { background: #F59E0B; }
.trace-tier-row[data-tier="below"]   .trace-source-meter-fill { background: #3B82F6; }
.trace-tier-row[data-tier="above"]   .trace-source-meter-fill { background: #EC4899; }

/* Assessment per-year list */
.trace-year-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.trace-year-row {
  display: grid;
  grid-template-columns: 90px 80px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #F8FAFC;
}
.trace-year-row[data-verdict="pass"]            { background: #ECFDF5; }
.trace-year-row[data-verdict="borderline_pass"] { background: #FFFBEB; }
.trace-year-row[data-verdict="lenient_pass"]    { background: #F0FDF4; }
.trace-year-row[data-verdict="fail"]            { background: #FEF2F2; }

.trace-year-label   { font-weight: 700; color: #0F172A; }
.trace-year-score   { font-variant-numeric: tabular-nums; color: #0F172A; font-weight: 700; }
.trace-year-verdict {
  color: #64748B;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.trace-year-row[data-verdict="pass"]            .trace-year-verdict { color: #047857; }
.trace-year-row[data-verdict="borderline_pass"] .trace-year-verdict { color: #B45309; }
.trace-year-row[data-verdict="lenient_pass"]    .trace-year-verdict { color: #15803D; }
.trace-year-row[data-verdict="fail"]            .trace-year-verdict { color: #B91C1C; }

/* Raw JSON fallback, collapsed by default */
.trace-raw {
  margin-top: 18px;
  border-top: 1px solid #E2E8F0;
  padding-top: 12px;
}
.trace-raw > summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  color: #64748B;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  list-style: none;
}
.trace-raw > summary::-webkit-details-marker { display: none; }
.trace-raw pre {
  margin-top: 8px;
  padding: 10px 12px;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  font-size: 11px;
  line-height: 1.4;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}

@media (max-width: 520px) {
  .trace-dialog-facts { grid-template-columns: 1fr; }
  .trace-source-row, .trace-tier-row { grid-template-columns: 90px 1fr 50px; }
  .trace-year-row { grid-template-columns: 70px 70px 1fr; }
}
