/* Wagenanzeige. Farben aus tokens.css (--wagon-*), Spalten setzt FormationStrip.razor. */
.formation-scroll {
    overflow-x: auto;
    padding-bottom: var(--space-1);
}

.formation {
    --wagon-width: 4.6rem;
    --loco-width: 3.25rem;
    --no-passage-width: 0.6rem;
    --wagon-height: 3.6rem;
    --nose: 1.25rem;
    display: grid;
    grid-template-rows: auto auto minmax(var(--wagon-height), auto) auto auto;
    column-gap: 4px;
    width: max-content;
    padding: 0 var(--space-1);
}

.formation.compact {
    --wagon-width: 3.1rem;
    --loco-width: 2.5rem;
    --wagon-height: 3.4rem;
    --nose: 1rem;
}

/* Zeile 1: Sektorband */
.sector {
    grid-row: 1;
    margin-bottom: var(--space-1);
    padding-bottom: 2px;
    border-bottom: 2px solid var(--accent);
    color: var(--accent);
    font-size: var(--fs-sm);
    font-weight: 700;
    text-align: center;
}

/* Zeile 2: Wagennummer */
.wagon-no {
    grid-row: 2;
    min-height: 1.1rem;
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    text-align: center;
}

/* Zeile 3: Wagen */
.wagon {
    grid-row: 3;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 0;
    overflow: hidden;
    border: 1.5px solid var(--wagon-border);
    border-radius: var(--radius-sm);
    background: var(--wagon-surface);
    color: var(--wagon-text);
}

/* Klassenstreifen oben, wie das gelbe Band der 1. Klasse am Zug */
.wagon::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 5px;
}

.wagon.first::before {
    background: var(--wagon-first);
}

.wagon.mixed::before {
    background: linear-gradient(90deg, var(--wagon-first) 50%, transparent 50%);
}

.wagon.restaurant::before {
    background: var(--wagon-restaurant);
}

.wagon.other {
    background: var(--wagon-other);
}

.wagon.loco {
    background: var(--wagon-other);
}

.wagon.nose-left {
    border-top-left-radius: var(--nose);
}

.wagon.nose-right {
    border-top-right-radius: var(--nose);
}

.wagon.closed {
    background: repeating-linear-gradient(-45deg, var(--wagon-surface) 0 5px, var(--wagon-other) 5px 10px);
    color: var(--text-subtle);
}

.cls {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 4px;
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1;
}

.cls .sep {
    width: 1px;
    height: 0.8em;
    background: var(--border-strong);
}

.wagon.restaurant .cls {
    color: var(--wagon-restaurant);
}

.cls .loco {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-muted);
}

.features {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 5px;
    padding: 2px 3px 4px;
    line-height: 1;
}

/* Ausstattung: Fahrplan-Attribute der SBB in Textfarbe, wie in der Wagenreihung der SBB */
.features .icon {
    height: 1.05rem;
    color: var(--wagon-text);
}

.features .icon:not(.fpl) {
    width: 1.05rem;
    color: var(--text-muted);
}

.cls .icon {
    height: 1.4rem;
}

.formation.compact .cls {
    font-size: 1.15rem;
}

/* Kein Durchgang: gestrichelte Linie in der eigenen Spalte */
.no-passage {
    grid-row: 3;
    justify-self: center;
    width: 0;
    border-left: 2px dashed var(--wagon-blocked);
}

/* Zeile 4: Typ */
.wagon-type {
    grid-row: 4;
    margin-top: 2px;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Zeile 5: Klammer pro Fahrzeug mit Link zum Tagesplan */
.unit {
    grid-row: 5;
    position: relative;
    margin-top: var(--space-1);
    padding-top: 9px;
    font-size: var(--fs-xs);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    white-space: nowrap;
}

.unit::before {
    content: "";
    position: absolute;
    inset: 0 2px auto;
    height: 6px;
    border: 1.5px solid var(--border-strong);
    border-top: none;
    border-radius: 0 0 3px 3px;
}

.unit a {
    text-decoration: none;
}

.unit a:hover {
    text-decoration: underline;
}

/* Legende */
.formation-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: var(--space-3) 0 0;
    padding: var(--space-2) 0 0;
    border-top: 1px solid var(--border);
    list-style: none;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.formation-legend li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.swatch {
    display: inline-block;
    width: 1rem;
    height: 5px;
}

.swatch.first {
    background: var(--wagon-first);
}

.swatch.restaurant {
    background: var(--wagon-restaurant);
}

.swatch.no-passage {
    width: 0;
    height: 0.9rem;
    border-left: 2px dashed var(--wagon-blocked);
    margin: 0 0.45rem;
}

.formation-legend .icon {
    height: 0.95rem;
    color: var(--text);
}

.formation-legend .icon:not(.fpl) {
    width: 0.95rem;
}

/* Der Klassenstreifen folgt der Rundung der Nase (Innenkante = Radius minus Rand), auch wo das Clipping versagt */
.wagon.nose-left::before {
    border-top-left-radius: calc(var(--nose) - 1.5px);
}

.wagon.nose-right::before {
    border-top-right-radius: calc(var(--nose) - 1.5px);
}
