/* ============================================================================================
   Maestros de tráficos (panel lateral y sus formularios). Fase 27, entrega 1.

   Hoja global y no .razor.css porque el panel y los seis formularios comparten piezas (campo,
   pista, error, pie) y los formularios se pintan dentro de los diálogos de Radzen.
   Prefijo `tm-`. Solo tokens --rs-* (CLAUDE.md, «Theming»).
   ============================================================================================ */

/* El panel lateral y los diálogos modales de Radzen comparten z-index (1001) y gana el que se pinta
   después: el panel. Bajado a 999, la máscara de un modal (1000) lo tapa y el formulario que se abre
   desde él (nueva terminal, confirmar borrado…) queda encima. Igual que .trv-side en trayectos. */
.rz-dialog-side.tm-side { z-index: 999; box-shadow: var(--rs-shadow-lg); }

.tm { display: flex; flex-direction: column; gap: 0.75rem; padding: 0.25rem 0.25rem 1rem; }

.tm-head { display: flex; align-items: flex-start; gap: 0.75rem; }
.tm-head-text { flex: 1; min-width: 0; }
.tm-title { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--rs-on-surface); }
.tm-question { margin: 0.2rem 0 0; font-size: 0.82rem; color: var(--rs-on-surface-variant); }
.tm-close {
    border: 0; background: none; color: var(--rs-on-surface-variant); cursor: pointer;
    border-radius: 8px; padding: 0.25rem; line-height: 0;
}
.tm-close:hover { background: var(--rs-surface-hover); color: var(--rs-on-surface); }

.tm-loading { display: flex; align-items: center; gap: 0.5rem; color: var(--rs-on-surface-variant); padding: 1rem 0; }

/* --- Pestañas como chips con recuento (premisa 3) ------------------------------------------ */
.tm-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tm-tab, .tm-chip {
    border: 1px solid var(--rs-outline); background: var(--rs-surface); color: var(--rs-on-surface-variant);
    border-radius: 999px; padding: 0.3rem 0.75rem; font-size: 0.8rem; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.4rem;
}
.tm-tab b, .tm-chip b { color: var(--rs-on-surface); font-variant-numeric: tabular-nums; }
.tm-tab[aria-pressed="true"], .tm-chip[aria-pressed="true"] {
    background: var(--rs-primary); border-color: var(--rs-primary); color: var(--rs-on-primary);
}
.tm-tab[aria-pressed="true"] b, .tm-chip[aria-pressed="true"] b { color: var(--rs-on-primary); }
.tm-chip--warn { border-color: var(--rs-warning); }

.tm-toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.tm-spacer { flex: 1; }

.tm-search {
    position: relative; display: flex; align-items: center; min-width: 220px;
    border: 1px solid var(--rs-outline); border-radius: 8px; background: var(--rs-surface);
}
.tm-search > .material-icons-round { font-size: 18px; color: var(--rs-on-surface-muted); padding: 0 0.3rem 0 0.5rem; }
.tm-search input {
    flex: 1; border: 0; outline: 0; background: transparent; color: var(--rs-on-surface);
    height: 32px; font: inherit; font-size: 0.85rem; min-width: 0;
}
.tm-search-clear { border: 0; background: none; color: var(--rs-on-surface-muted); cursor: pointer; line-height: 0; padding: 0 0.4rem; }
.tm-search-clear .material-icons-round { font-size: 16px; }

/* --- Tablas ---------------------------------------------------------------------------------- */
.tm-table {
    width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.84rem;
    border: 1px solid var(--rs-outline-variant); border-radius: 10px; overflow: hidden;
}
.tm-table th, .tm-table td { padding: 0.5rem 0.65rem; text-align: left; border-bottom: 1px solid var(--rs-outline-variant); vertical-align: top; }
.tm-table tbody tr:last-child th, .tm-table tbody tr:last-child td { border-bottom: 0; }
.tm-table thead th {
    background: var(--rs-surface-container); color: var(--rs-on-surface-variant);
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.tm-table tbody th { font-weight: 700; color: var(--rs-on-surface); }
.tm-table .n { text-align: right; font-variant-numeric: tabular-nums; }
.tm-table .mono, .tm-pill.mono, .tm-input.mono {
    font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums;
}
.tm-row--off th, .tm-row--off td { color: var(--rs-on-surface-muted); }
.tm-actions { white-space: nowrap; text-align: right; width: 1%; }

.tm-pill {
    display: inline-block; margin: 0 0.25rem 0.2rem 0; padding: 0.08rem 0.45rem; border-radius: 6px;
    background: var(--rs-surface-container); color: var(--rs-on-surface); font-size: 0.75rem; white-space: nowrap;
}
.tm-tag {
    display: inline-block; margin-left: 0.35rem; padding: 0.05rem 0.45rem; border-radius: 999px;
    font-size: 0.66rem; font-weight: 700; vertical-align: middle;
}
.tm-tag--neutral { background: var(--rs-neutral-subtle); color: var(--rs-on-neutral-subtle); }
.tm-muted { color: var(--rs-on-surface-muted); font-size: 0.8rem; }

.tm-link {
    border: 0; background: none; padding: 0; cursor: pointer; font: inherit;
    color: var(--rs-primary-text); text-decoration: underline; font-variant-numeric: tabular-nums;
}

.tm-empty { text-align: center; padding: 2rem 1rem; color: var(--rs-on-surface-variant); }
.tm-empty .material-icons-round { font-size: 2rem; color: var(--rs-on-surface-muted); }
.tm-empty h3 { margin: 0.4rem 0 0.25rem; font-size: 1rem; color: var(--rs-on-surface); }
.tm-empty p { margin: 0 auto 0.75rem; max-width: 460px; font-size: 0.85rem; }

.tm-foot { display: flex; align-items: center; gap: 0.4rem; margin: 0.25rem 0 0; font-size: 0.78rem; color: var(--rs-on-surface-variant); }
.tm-foot .material-icons-round { font-size: 16px; }
.tm-foot a, .tm-form a { color: var(--rs-primary-text); }

/* --- Formularios ------------------------------------------------------------------------------ */
.tm-form { display: flex; flex-direction: column; gap: 0.85rem; }
.tm-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.tm-field { display: flex; flex-direction: column; gap: 0.25rem; }
.tm-field > label, .tm-fieldset > legend { font-size: 0.75rem; font-weight: 700; color: var(--rs-on-surface-variant); }
.tm-input {
    border: 1px solid var(--rs-outline); border-radius: 8px; padding: 0.4rem 0.6rem; font: inherit; font-size: 0.88rem;
    background: var(--rs-surface); color: var(--rs-on-surface); width: 100%; box-sizing: border-box;
}
.tm-input:focus-visible, .tm-search:focus-within { outline: 2px solid var(--rs-primary); outline-offset: 1px; }
.tm-hint { font-size: 0.74rem; font-weight: 400; color: var(--rs-on-surface-variant); }
.tm-error {
    margin: 0; padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.84rem;
    background: var(--rs-danger-subtle); color: var(--rs-on-danger-subtle);
}
.tm-check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; flex-wrap: wrap; }

.tm-fieldset { border: 1px solid var(--rs-outline-variant); border-radius: 10px; padding: 0.6rem 0.8rem 0.8rem; margin: 0; }
.tm-limits { display: grid; grid-template-columns: auto 1fr 1fr; gap: 0.45rem 0.6rem; align-items: center; }
.tm-limit-label { font-size: 0.82rem; color: var(--rs-on-surface); }

.tm-seg { display: inline-flex; border: 1px solid var(--rs-outline); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.tm-seg button {
    border: 0; background: var(--rs-surface); color: var(--rs-on-surface-variant);
    font: inherit; font-size: 0.82rem; font-weight: 600; padding: 0.35rem 0.8rem; cursor: pointer;
}
.tm-seg button + button { border-left: 1px solid var(--rs-outline-variant); }
.tm-seg button[aria-pressed="true"] { background: var(--rs-primary); color: var(--rs-on-primary); }

.tm-dlg-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--rs-outline-variant); }

.tm-contacts { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rs-outline-variant); border-radius: 10px; }
.tm-contacts li { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.7rem; border-top: 1px solid var(--rs-outline-variant); }
.tm-contacts li:first-child { border-top: 0; }
.tm-contact-main { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.86rem; color: var(--rs-on-surface); }

/* --- Cuadro de Cargas Máximas de ADIF ------------------------------------------------------- */
.tm-adif-head {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; padding: 0.55rem 0.75rem;
    border: 1px solid var(--rs-outline-variant); border-radius: 10px; background: var(--rs-surface-container-low);
    font-size: 0.82rem; color: var(--rs-on-surface-variant);
}
.tm-adif-head b { color: var(--rs-on-surface); }
.tm-adif-warn {
    margin: 0; padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.82rem;
    background: var(--rs-warning-subtle); color: var(--rs-on-warning-subtle);
}
.tm-scroll { overflow-x: auto; border: 1px solid var(--rs-outline-variant); border-radius: 10px; }
.tm-scroll > .tm-table { border: 0; border-radius: 0; overflow: visible; }
.tm-adif { width: auto; min-width: 100%; }
.tm-adif th, .tm-adif td { padding: 0.3rem 0.45rem; white-space: nowrap; }
.tm-adif td.n { font-size: 0.78rem; }
.tm-adif .tm-sticky {
    position: sticky; left: 0; z-index: 1; background: var(--rs-surface); min-width: 11rem; white-space: normal;
    box-shadow: 1px 0 0 var(--rs-outline-variant);
}
.tm-adif thead .tm-sticky { background: var(--rs-surface-container); }
.tm-adif .tm-sticky small { display: block; font-weight: 400; color: var(--rs-on-surface-variant); }
.tm-sub { display: block; font-weight: 400; }
.tm-tag--flush { margin-left: 0; }
.tm-ico-sm { font-size: 14px; vertical-align: middle; }
.tm-label { font-size: 0.75rem; font-weight: 700; color: var(--rs-on-surface-variant); }
.tm-ramps { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr)); gap: 0.4rem; }
.tm-ramp { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.72rem; font-weight: 600; color: var(--rs-on-surface-variant); }
.tm-ramp .rz-numeric { width: 100%; }

.tm-tab:focus-visible, .tm-chip:focus-visible, .tm-seg button:focus-visible, .tm-link:focus-visible, .tm-close:focus-visible {
    outline: 2px solid var(--rs-primary); outline-offset: 2px;
}

@media (max-width: 720px) {
    .tm-grid2 { grid-template-columns: 1fr; }
    .tm-table thead { display: none; }
    .tm-table tr { display: block; border-bottom: 1px solid var(--rs-outline-variant); padding: 0.4rem 0; }
    .tm-table th, .tm-table td { display: block; border: 0; padding: 0.15rem 0.65rem; }
    .tm-table .n, .tm-actions { text-align: left; }
    /* El cuadro de ADIF sigue siendo una tabla: se desplaza en horizontal dentro de su caja. */
    .tm-table.tm-adif thead { display: table-header-group; }
    .tm-table.tm-adif tr { display: table-row; padding: 0; }
    .tm-table.tm-adif th, .tm-table.tm-adif td { display: table-cell; border-bottom: 1px solid var(--rs-outline-variant); padding: 0.3rem 0.45rem; }
    .tm-table.tm-adif .n { text-align: right; }
}
