/*
 * Coaching plan detail — narrative-first "coach's letter" (P2-1).
 *
 * Scoped to .cl-* so the /coaching dashboard and legacy ?analysis_id view
 * keep their existing layout. Load after coaching.html's local <style>.
 */

.cl-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cl-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  column-gap: 32px;
  align-items: start;
}
.cl-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 18px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.cl-letter {
  min-width: 0;
  max-width: 760px;
}
.cl-rail {
  position: sticky;
  top: 20px;
  min-width: 0;
  padding-left: 24px;
  border-left: 1px solid var(--border);
}

.cl-byline {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.cl-byline-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(94, 200, 255, 0.16);
  border: 1px solid rgba(94, 200, 255, 0.5);
  color: var(--coach);
  font-family: var(--hero);
  font-size: 18px;
  line-height: 1;
}
.cl-byline-name {
  display: block;
  color: var(--text);
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
}
.cl-byline-role {
  display: block;
  margin-top: 1px;
  color: var(--coach);
  font-family: var(--label);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.cl-subject {
  min-width: 180px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.cl-subject-label {
  color: var(--accent);
  margin-right: 5px;
}
.cl-head-chips,
.cl-head-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.cl-head-actions {
  margin-left: auto;
}
.cl-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.cl-chip.is-closing {
  color: var(--green);
  border-color: rgba(0, 200, 100, 0.4);
  background: rgba(0, 200, 100, 0.1);
}
.cl-chip.is-receding {
  color: var(--red);
  border-color: rgba(255, 91, 91, 0.4);
  background: rgba(255, 91, 91, 0.1);
}
.cl-chip.is-flat {
  color: var(--muted);
}

.cl-btn,
.cl-btn-quiet {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
}
.cl-btn.is-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 700;
}
.cl-btn.is-pinned {
  color: var(--green);
  border-color: rgba(0, 200, 100, 0.45);
  background: rgba(0, 200, 100, 0.11);
}
.cl-btn-quiet {
  min-height: 34px;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
}
.cl-btn:hover,
.cl-btn-quiet:hover {
  border-color: rgba(var(--accent-rgb), 0.5);
  color: var(--accent);
}
.cl-btn.is-primary:hover {
  color: var(--bg);
  filter: brightness(1.08);
}

.cl-audio {
  margin-bottom: 22px;
  border: 1px solid rgba(94, 200, 255, 0.35);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(94, 200, 255, 0.1), var(--surface));
  overflow: hidden;
}
.cl-audio-btn {
  width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.cl-audio-btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}
.cl-audio-play {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--coach);
  color: var(--bg);
}
.cl-audio-title {
  display: block;
  font-family: var(--display);
  font-size: 15px;
  font-weight: 700;
}
.cl-audio-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
}
.cl-wave {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 3px;
  opacity: 0.35;
}
.cl-wave span {
  width: 3px;
  height: 24px;
  border-radius: 2px;
  background: var(--coach);
  transform: scaleY(0.35);
}
.cl-audio.is-playing .cl-wave {
  opacity: 1;
}
.cl-audio.is-playing .cl-wave span {
  animation: cl-wave 0.8s ease-in-out infinite alternate;
}
.cl-audio.is-playing .cl-wave span:nth-child(2),
.cl-audio.is-playing .cl-wave span:nth-child(4) {
  animation-delay: 0.18s;
}
.cl-audio.is-playing .cl-wave span:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes cl-wave {
  from { transform: scaleY(0.25); }
  to { transform: scaleY(1); }
}
.cl-audio audio {
  width: calc(100% - 32px);
  margin: 0 16px 14px;
}

.cl-prose {
  max-width: 68ch;
  color: var(--text);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.72;
}
.cl-prose p {
  margin: 0 0 14px;
}
.cl-prose p:first-of-type {
  font-size: 19px;
}
.cl-empty-copy {
  color: var(--muted);
  font-size: 15px;
  font-style: italic;
}

.cl-rule {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 30px 0 13px;
}
.cl-rule h2 {
  margin: 0;
  color: var(--muted);
  font-family: var(--label);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.cl-rule-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.cl-rule-actions {
  display: flex;
  gap: 6px;
}
.lost-sort-btn.is-active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.12);
}

.cl-goals {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cl-goal {
  display: grid;
  grid-template-columns: 22px 9px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.cl-goal:first-child {
  border-top: 0;
}
.cl-goal-rank,
.cl-goal-meta,
.cl-goal-state {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}
.cl-goal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}
.cl-goal[data-status="met"] .cl-goal-dot {
  background: var(--green);
}
.cl-goal[data-status="met"] .cl-goal-state {
  color: var(--green);
}
.cl-goal[data-status="partial"] .cl-goal-dot {
  background: var(--amber);
}
.cl-goal[data-status="partial"] .cl-goal-state {
  color: var(--amber);
}
.cl-goal-text {
  font-size: 15px;
  line-height: 1.5;
}
.cl-goal-meta {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}
.cl-goal-target {
  color: var(--accent);
}
.cl-goal-state {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cl-turn-lede {
  max-width: 68ch;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.cl-letter .corner-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cl-letter .corner-card {
  padding: 15px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.cl-letter .corner-card-name {
  color: var(--accent);
  font-family: var(--hero);
  font-size: 23px;
  letter-spacing: 0.02em;
}
.cl-letter .corner-card-loss {
  color: var(--red);
}
.cl-letter .corner-card-loss.faster {
  color: var(--green);
}
.cl-turn-passage {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 16.5px;
  line-height: 1.65;
}
.cl-turn-passage-only {
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.cl-turn-passage-only h3 {
  margin: 0 0 7px;
  color: var(--accent);
  font-family: var(--hero);
  font-size: 22px;
  letter-spacing: 0.02em;
}
.cl-turn-passage-only p {
  margin: 0;
}
.cl-letter .phase-row.is-empty {
  display: none;
}
.cl-letter .corner-actions button {
  min-height: 36px;
}

.cl-convo-lede {
  max-width: 68ch;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.cl-compose {
  width: min(82%, 620px);
  margin-left: auto;
  padding: 12px;
  border: 1px solid var(--border-2);
  border-radius: 12px 12px 4px 12px;
  background: var(--surface-2);
}
.cl-compose textarea {
  width: 100%;
  min-height: 92px;
  padding: 0;
  border: 0;
  outline: 0;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.55;
}
.cl-compose-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.cl-compose-status {
  min-height: 1em;
  color: var(--muted);
  font-size: 11px;
}
.cl-reply {
  width: min(82%, 620px);
  margin: 14px auto 0 0;
  padding: 13px 15px;
  border: 1px solid rgba(94, 200, 255, 0.28);
  border-radius: 4px 12px 12px 12px;
  background: rgba(94, 200, 255, 0.08);
}
.cl-reply-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.cl-reply-head .cl-btn-quiet {
  margin-left: auto;
}
.cl-reply-body {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.58;
}
.cl-reply audio {
  width: 100%;
  margin-top: 10px;
}

.cl-data {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.cl-data-summary {
  min-height: 52px;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}
.cl-data-summary::-webkit-details-marker {
  display: none;
}
.cl-data-title {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
}
.cl-data-sub {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-align: right;
}
.cl-data-frame {
  width: calc(100% - 24px);
  height: min(720px, 78vh);
  display: block;
  margin: 0 12px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.cl-data-link {
  display: inline-block;
  margin: 0 14px 14px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.cl-history {
  display: flex;
  flex-direction: column;
}
.cl-history-row {
  display: grid;
  grid-template-columns: 28px minmax(130px, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.cl-history-row:first-child {
  border-top: 0;
}
.cl-history-row > span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.cl-history-row .cl-history-avg {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.cl-rail-rule {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: var(--label);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.cl-progress-count {
  color: var(--accent);
  font-family: var(--hero);
  font-size: 42px;
  line-height: 1;
}
.cl-progress-count small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.cl-progress {
  height: 6px;
  margin: 10px 0 14px;
  border-radius: 100px;
  background: var(--surface-2);
  overflow: hidden;
}
.cl-progress > span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: var(--accent);
}
.cl-rail-block {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.cl-rail-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
}
.cl-rail-stat span {
  color: var(--muted);
  font-family: var(--label);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.cl-rail-stat strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.cl-rail-stat strong.is-loss {
  color: var(--red);
}
.cl-rail-stat strong.is-gain {
  color: var(--green);
}
.cl-rail .cl-btn {
  width: 100%;
}

@media (max-width: 1139px) {
  .cl-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .cl-rail {
    position: static;
    margin-top: 28px;
    padding: 20px 0 0;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .cl-rail-block {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
  .cl-rail-stat {
    display: block;
  }
  .cl-rail-stat span,
  .cl-rail-stat strong {
    display: block;
  }
  .cl-rail-stat strong {
    margin-top: 4px;
  }
}

@media (max-width: 720px) {
  .cl-head {
    align-items: flex-start;
    margin-bottom: 18px;
  }
  .cl-subject {
    flex: 1 1 calc(100% - 55px);
  }
  .cl-head-chips,
  .cl-head-actions {
    width: 100%;
  }
  .cl-head-actions {
    margin-left: 0;
  }
  .cl-head-actions .cl-btn {
    flex: 1;
    min-height: 44px;
  }
  .cl-audio-btn {
    grid-template-columns: 40px minmax(0, 1fr);
    min-height: 72px;
  }
  .cl-audio-play {
    width: 40px;
    height: 40px;
  }
  .cl-wave {
    display: none;
  }
  .cl-prose {
    font-size: 16px;
  }
  .cl-prose p:first-of-type {
    font-size: 18px;
  }
  .cl-goal {
    grid-template-columns: 22px 9px minmax(0, 1fr);
  }
  .cl-goal-meta,
  .cl-goal-state {
    grid-column: 3 / 4;
  }
  .cl-goal-state {
    justify-self: start;
  }
  .cl-compose,
  .cl-reply {
    width: 100%;
  }
  .cl-compose-actions .cl-btn,
  .cl-compose-actions .cl-btn-quiet {
    min-height: 44px;
  }
  .cl-data-frame {
    height: 520px;
  }
  .cl-history-row {
    grid-template-columns: 26px minmax(0, 1fr) auto;
  }
  .cl-history-goals,
  .cl-history-traj {
    grid-column: 2 / 4;
  }
  .cl-rail-block {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cl-audio.is-playing .cl-wave span {
    animation: none;
    transform: scaleY(0.55);
  }
}
