/* Team History tab — layout wrapper + narrative card + positions chart
   (SVG) + milestones timeline. Trophy cabinet lives in
   `components/trophies.css` as it's reused by the future league-history
   hall-of-fame view. */

@layer components {
  .team-history {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 0 24px;
  }

  /* ---- Positions chart (SVG) ------------------------------------- */

  /* Header = logo liga + nombre. Sustituye el h3 suelto para que el usuario
     sepa a qué competición corresponde la progresión. */
  .team-history__positions-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px;
  }

  .team-history__positions-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
    flex-shrink: 0;
  }

  .team-history__positions-header .card-title {
    margin: 0;
  }

  /* Editions selector trigger — full-width pill inside the card with
     bottom margin to separate it from the year list. Scoped here so it
     overrides the shared `.standings-league-trigger` width-fit pattern
     (which makes sense in the standings header but cramps the editions
     card body). */
  .team-history__editions-selector .select-trigger {
    width: 100%;
    margin-bottom: 12px;
  }

  /* Editions card — pill switcher de competición + lista por edición
     (year grande izquierda · stage + winner flag derecha). Ediciones de
     campeonato destacadas con fondo accent; edición en curso con italic. */

  .team-history__ed-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  .team-history__ed-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition:
      background 120ms,
      color 120ms,
      border-color 120ms;
  }

  .team-history__ed-pill:hover {
    color: var(--color-text);
  }

  .team-history__ed-pill.active {
    background: color-mix(in srgb, var(--color-accent) 16%, transparent);
    color: var(--color-text);
    border-color: var(--color-accent);
  }

  .team-history__ed-pill-logo {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex-shrink: 0;
  }

  .team-history__editions {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .team-history__editions[hidden] {
    display: none;
  }

  .team-history__edition {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--color-surface);
  }

  /* Timeline "Resultado en cada Mundial": emblema de la edición a la
     izquierda; a la derecha, arriba "<País> <año>" y abajo la clasificación. */
  .wc-editions {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .wc-edition {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--color-surface);
  }

  .wc-edition__logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
    /* Badge claro uniforme para que TODOS los emblemas (claros y oscuros)
       lean igual de nítidos. El de Catar (logo oscuro) se vería mejor con su
       variante clara — pendiente. */
    background: rgb(255 255 255 / 92%);
    border-radius: 6px;
    padding: 2px;
  }

  .wc-edition__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }

  .wc-edition__name {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .wc-edition__finish {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
  }

  .wc-edition--champion {
    background: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface));
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
  }

  .wc-edition--champion .wc-edition__finish {
    color: var(--color-accent);
    font-weight: 700;
  }

  .team-history__edition-year {
    font-family: var(--font-title);
    font-weight: 800;
    font-size: 16px;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    flex-shrink: 0;
  }

  .team-history__edition-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }

  .team-history__edition-stage {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
  }

  .team-history__edition-winner {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--color-text-muted);
  }

  .team-history__edition-winner-label {
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-size: 9px;
    font-weight: 700;
    color: var(--color-text-subtle);
  }

  .team-history__edition-winner-flag {
    width: 14px;
    height: 10px;
    border-radius: 2px;
    object-fit: cover;
    box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }

  .team-history__edition-winner-name {
    color: var(--color-text-secondary);
    font-weight: 600;
  }

  .team-history__edition--champion {
    background: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface));
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
  }

  .team-history__edition--champion .team-history__edition-year,
  .team-history__edition--champion .team-history__edition-stage {
    color: var(--color-text);
  }

  .team-history__edition--champion .team-history__edition-winner-name {
    color: var(--color-accent);
    font-weight: 700;
  }

  /* Runner-up dentro de champion row — neutralizar el accent verde (el
     rival batido no debe leer como "highlight positivo"). */
  .team-history__edition--champion
    .team-history__edition-winner--runnerup
    .team-history__edition-winner-name {
    color: var(--color-text-secondary);
    font-weight: 600;
  }

  .team-history__edition--in-progress .team-history__edition-stage em {
    color: var(--color-accent);
    font-style: italic;
    font-weight: 700;
  }

  /* ---- Season chart (player «Rendimiento por partido» carousel) ----
     Markup and base look come from `.player-stats-rating-chart__*`
     (player-stats.css); here only the outcome colours of a season. */
  .team-season-bars__cell--title { --season-c: var(--color-rating-excellent); }
  .team-season-bars__cell--up { --season-c: var(--color-win); }
  .team-season-bars__cell--down { --season-c: var(--color-loss); }
  .team-season-bars__cell--current { --season-c: var(--color-purple); }
  .team-season-bars__cell--rest { --season-c: var(--color-text-muted); }

  /* The cells are <button>s (the player chart's are <div>s): drop the UA
     button chrome so the shared rating-chart look applies unchanged. */
  .team-season-bars__cell {
    background: transparent;
    border: 0;
    padding: 0;
    color: inherit;
    font: inherit;
  }

  /* player-stats.css loads after this file: the season colours need the
     extra class to beat its neutral bar / value colours. */
  .team-season-bars .team-season-bars__bar { background: var(--season-c); }
  .team-season-bars .team-season-bars__cell--current .team-season-bars__bar {
    background: color-mix(in srgb, var(--season-c) 22%, transparent);
    outline: 1.5px dashed var(--season-c);
    outline-offset: -1.5px;
  }
  .team-season-bars .team-season-bars__pos { display: inline-flex; align-items: center; justify-content: center; gap: 1px; }
  .team-season-bars__crown { width: 10px; height: 10px; color: var(--season-c); }
  .team-season-bars .team-season-bars__pos,
  .team-season-bars .team-season-bars__pts { color: var(--season-c); }
  .team-season-bars .team-season-bars__cell--rest .team-season-bars__pos,
  .team-season-bars .team-season-bars__cell--rest .team-season-bars__pts { color: var(--color-text); }

  .team-season-bars__cell[hidden] { display: none; }

  /* 8 seasons a page: thinner bars than the player's 5, smaller figures and
     the season on a diagonal under its bar. */
  .team-season-bars .player-stats-rating-chart__track {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
    min-height: 200px;
  }
  .team-season-bars .player-stats-rating-chart__score,
  .team-season-bars .player-stats-rating-chart__bar-value { font-size: 11px; }
  .team-season-bars .player-stats-rating-chart__opp-logo { width: 14px; height: 14px; }
  .team-season-bars .player-stats-rating-chart__bar-wrap { padding: 2px; border-radius: 5px; min-height: 90px; }
  .team-season-bars .player-stats-rating-chart__round {
    height: 26px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    letter-spacing: 0;
  }
  .team-season-bars .player-stats-rating-chart__round > span {
    display: inline-block;
    transform: translate(-2px, 8px) rotate(-45deg);
    white-space: nowrap;
  }
  /* Rail (phones/tablets, `is-rail` set by season-carousel): every season
     in one row the finger scrolls, 7.5 on screen (the cut one says «there's more»), no arrows or dots. */
  .team-season-bars.is-rail .player-stats-rating-chart__arrow,
  .team-season-bars.is-rail .player-stats-rating-chart__dots { display: none; }
  .team-season-bars.is-rail .player-stats-rating-chart__body { grid-template-columns: minmax(0, 1fr); }
  .team-season-bars.is-rail .player-stats-rating-chart__track {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 7 * 4px) / 7.5);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .team-season-bars.is-rail .player-stats-rating-chart__track::-webkit-scrollbar { display: none; }
  .team-season-bars.is-rail .team-season-bars__cell { scroll-snap-align: end; }

  .team-season-bars__cell[aria-pressed="true"] .player-stats-rating-chart__bar-wrap {
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 30%);
  }

  .team-season-bars__detail {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--color-surface-sunken);
    font-size: 12.5px;
    color: var(--color-text-secondary);
    display: grid;
    gap: 8px;
  }
  .team-season-bars__detail[hidden] { display: none; }

  /* One season's finish (_season_line): chart detail + coach era card. */
  .team-season-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin: 5px 0 0; font-size: 11.5px; color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
  .team-season-line > * { display: inline-flex; align-items: center; gap: 5px; padding: 0 8px; border-left: 1px solid var(--color-border); }
  .team-season-line > :first-child { padding-left: 0; border-left: 0; }
  .team-season-line img { width: 16px; height: 16px; object-fit: contain; }
  .team-season-line b { color: var(--color-text); }
  /* The season badge leading the chart detail, coloured by how it ended. */
  .team-season-line .team-season-line__season { padding: 1px 7px; border-left: 0; font-size: 11px; font-weight: 800; color: var(--color-text-secondary); }
  .team-season-line .team-season-line__season + * { border-left: 0; }
  .team-season-line .team-season-line__season--title { background: color-mix(in srgb, var(--color-rating-excellent) 18%, transparent); color: var(--color-rating-excellent); }
  .team-season-line .team-season-line__season--current { background: color-mix(in srgb, var(--color-purple) 18%, transparent); color: var(--color-purple); }
  .team-season-line .team-season-line__season--up { background: color-mix(in srgb, var(--color-win) 18%, transparent); color: var(--color-win); }
  .team-season-line .team-season-line__season--down { background: color-mix(in srgb, var(--color-loss) 18%, transparent); color: var(--color-loss); }
  .team-season-bars__detail b { color: var(--color-text); }
  .team-season-bars__coaches {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
  }
  .team-season-bars__coaches li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--color-text-muted);
  }

  .team-season-bars__legend {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 10px;
    color: var(--color-text-muted);
  }
  .team-season-bars__legend i {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: -1px;
    background: var(--season-c);
  }

  /* General / Apertura / Clausura toggle — `.pst-per90-toggle` look
     (player-stats.css), spaced under the card header. */
  .team-history__positions-toggle {
    margin: 0 0 8px;
  }

  /* ---- Coaches: the coach in charge + a strip of faces ---------- */
  .team-coaches__head { margin-bottom: 12px; }
  .team-coaches__head .card-title { margin: 0; }
  /* Four pills in the segmented toggle: keep them on one line at 360px. */
  .team-coaches__metrics { margin: 0 0 12px; }
  .team-coaches__metrics .pst-per90-btn { padding-inline: 4px; font-size: 12px; white-space: nowrap; }
  .team-coaches__panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .team-coaches__panel[hidden] { display: none; }
  .team-coaches__panel > * { min-width: 0; }

  .team-coaches__photo {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: none;
    border-radius: 50%;
    overflow: hidden;
    background: var(--color-surface-active);
    color: var(--color-text-secondary);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 800;
  }
  .team-coaches__photo img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
  .team-coaches__tl-photo { position: relative; display: inline-flex; flex: none; }
  .team-coaches__photo-crown {
    position: absolute;
    top: -10px;
    left: 50%;
    width: 18px;
    height: 18px;
    transform: translateX(-50%) rotate(-8deg);
    color: var(--color-rating-elite);
    filter: drop-shadow(0 1px 2px rgb(0 0 0 / 60%));
  }

  .team-coaches__name { display: block; font-weight: 800; font-size: 12.5px; line-height: 1.25; color: var(--color-text); }
  .team-coaches__name--hero { font-size: 16px; }
  .team-coaches__span { display: block; color: var(--color-text-muted); font-size: 11px; }

  .team-coaches__tag {
    justify-self: start;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 2px 7px;
    background: var(--color-surface-active);
    color: var(--color-text-muted);
    white-space: nowrap;
  }
  .team-coaches__tag--now { background: color-mix(in srgb, var(--color-purple) 18%, transparent); color: var(--color-purple); }
  .team-coaches__tag-now::before { content: '•'; margin: 0 4px 0 2px; }

  /* Hero: the coach in charge */
  .team-coaches__hero {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    padding: 14px 12px 12px;
    border-radius: 12px;
    background: var(--color-surface-sunken);
  }
  .team-coaches__hero[hidden] { display: none; }
  /* Number on the big photo: season badge (Temporadas) or rank, opaque over the photo. */
  .team-coaches__season-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 7px 0 0; padding: 0; list-style: none; }
  .team-coaches__season-list .team-coaches__season-badge { font-size: 9.5px; font-weight: 700; color: var(--color-text-muted); }
  .team-coaches__season-list .team-coaches__season-badge.is-title { color: var(--color-rating-excellent); }
  .team-coaches__season-list .team-coaches__season-badge.is-now { color: var(--color-purple); }
  .team-coaches__photo-rank { right: -2px; bottom: 0; min-width: 22px; height: 22px; border-radius: 11px; font-size: 12px; line-height: 22px; box-shadow: 0 0 0 2px var(--color-surface-sunken); }
  .team-coaches__photo-rank.is-leader { background: var(--color-rating-elite); color: #111; }
  .team-coaches__facts { display: flex; flex-wrap: wrap; gap: 2px 12px; margin: 5px 0 0; font-size: 12px; color: var(--color-text-muted); }
  .team-coaches__facts b { font-family: var(--font-title); font-size: 14px; font-weight: 600; color: var(--color-text); font-variant-numeric: tabular-nums; }
  .team-coaches__facts .is-on b,
  .team-coaches__facts .is-on { color: var(--color-rating-excellent); }
  .team-coaches__tag { display: inline-flex; align-items: center; gap: 3px; }
  .team-coaches__tag--title { background: color-mix(in srgb, var(--color-rating-excellent) 18%, transparent); color: var(--color-rating-excellent); }
  .team-coaches__season-badge.is-now { background: color-mix(in srgb, var(--color-purple) 18%, transparent); color: var(--color-purple); }
  .team-coaches__hero .team-coaches__photo { box-shadow: 0 0 0 2px var(--color-surface-active); }
  .team-coaches__hero.is-now .team-coaches__photo { box-shadow: 0 0 0 2px var(--color-purple); }
  .team-coaches__hero + .team-coaches__strip-h,
  .team-coaches__hero[hidden] ~ .team-coaches__strip-h { margin-top: 12px; }
  .team-coaches__hero-body { display: grid; gap: 3px; min-width: 0; }

  .team-coaches__crown { width: 18px; height: 18px; color: var(--color-rating-elite); flex: none; }

  /* Strip of faces */
  .team-coaches__strip-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-subtle); }
  .team-coaches__strip-h small { font-size: 10.5px; letter-spacing: 0; text-transform: none; font-weight: 600; }
  .team-coaches__strip { display: flex; gap: 6px; overflow-x: auto; padding: 12px 2px 6px; scrollbar-width: none; }
  .team-coaches__strip::-webkit-scrollbar { display: none; }
  .team-coaches__chip {
    flex: none;
    width: 68px;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 4px 0 6px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
  }
  .team-coaches__chip.active { background: var(--color-surface-sunken); }
  .team-coaches__chip.active .team-coaches__photo { box-shadow: 0 0 0 2px var(--color-text); }
  .team-coaches__chip.is-leader .team-coaches__photo { box-shadow: 0 0 0 2px var(--color-rating-elite); }
  .team-coaches__chip.is-unranked { opacity: 0.45; }
  .team-coaches__chip-rank {
    position: absolute;
    right: -4px;
    bottom: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--color-surface-active);
    box-shadow: 0 0 0 2px var(--color-surface);
    font-size: 10px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    color: var(--color-text);
  }
  .team-coaches__chip.is-leader .team-coaches__chip-rank { background: var(--color-rating-elite); color: #111; }
  .team-coaches__chip-name { font-size: 10.5px; font-weight: 700; color: var(--color-text-secondary); max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .team-coaches__chip-value { font-family: var(--font-title); font-size: 12.5px; color: var(--color-text); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .team-coaches__chip.is-leader .team-coaches__chip-value { color: var(--color-rating-elite); }
  .team-coaches__chip--wide { width: 78px; }
  .team-coaches__chip-stats { font-size: 10.5px; font-weight: 700; color: var(--color-text); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .team-coaches__chip-stats small { margin-left: 2px; font-size: 9px; font-weight: 600; color: var(--color-text-muted); }
  .team-coaches__season-badge { display: inline-flex; align-items: center; gap: 2px; padding: 1px 6px; border-radius: 999px; background: var(--color-surface-active); }
  .team-coaches__season-badge.is-title { background: color-mix(in srgb, var(--color-rating-excellent) 18%, transparent); color: var(--color-rating-excellent); }
  .team-coaches__season-crown { width: 9px; height: 9px; }
  .team-coaches__chip-value--span { font-family: var(--font-body); font-size: 10px; font-weight: 600; color: var(--color-text-muted); letter-spacing: -0.02em; }

  /* Era card opened from a face */

  .team-coaches__wdl { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: var(--color-surface-active); }
  .team-coaches__wdl span:nth-child(1) { background: var(--color-win); }
  .team-coaches__wdl span:nth-child(2) { background: var(--color-draw); }
  .team-coaches__wdl span:nth-child(3) { background: var(--color-loss); }
  .team-coaches__hero .team-coaches__wdl { margin-top: 4px; height: 4px; }
  .team-coaches__record { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-text); }
  .team-coaches__res { display: inline-flex; align-items: center; gap: 4px; }
  .team-coaches__res i {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    font-size: 10px;
    font-style: normal;
    font-weight: 800;
    color: #fff;
  }
  .team-coaches__res--w i { background: var(--color-win); }
  .team-coaches__res--d i { background: var(--color-draw); }
  .team-coaches__res--l i { background: var(--color-loss); }
  .team-coaches__record-pj { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--color-text-muted); }
  .team-coaches__record-pj.is-on { font-size: 12px; font-weight: 800; color: var(--color-rating-excellent); }

  /* ---- Milestones timeline -------------------------------------- */

  .team-history__milestones {
    position: relative;
    list-style: none;
    padding: 0 0 0 18px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .team-history__milestones::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: linear-gradient(to bottom, var(--color-accent), transparent);
    border-radius: 1px;
  }

  .team-history__milestone {
    display: grid;
    grid-template-columns: 54px 1fr;
    gap: 10px;
    padding: 8px 0;
    position: relative;
  }

  .team-history__milestone::before {
    content: "";
    position: absolute;
    left: -15px;
    top: 13px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    border: 2px solid var(--color-bg);
  }

  .team-history__milestone-year {
    font-family: var(--font-title);
    font-size: 14px;
    font-weight: 800;
    color: var(--color-accent);
    font-variant-numeric: tabular-nums;
  }

  .team-history__milestone-label {
    font-size: 13px;
    color: var(--color-text);
    line-height: 1.4;
  }
}
