/* Panel del mapa. Global (no scoped) porque los popups y los marcadores los crea
   Leaflet desde JavaScript, fuera del árbol del componente. */

/* --- Barra superior --- */

.tm-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem 1.5rem;
    padding: 0.7rem 1.1rem;
    background: var(--glass);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
    position: relative;
    z-index: 500;
}

/* Filo luminoso: marca el borde activo sin robar atención. */
.tm-bar::after {
    content: "";
    position: absolute;
    inset: auto 0 -1px 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.5;
}

.tm-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tm-name {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.tm-name-accent {
    color: var(--accent);
}

.tm-sub {
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tm-pulse {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.6);
    animation: tm-pulse 2.4s ease-out infinite;
}

@keyframes tm-pulse {
    0% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.55); }
    70% { box-shadow: 0 0 0 9px rgba(12, 163, 12, 0); }
    100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); }
}

/* --- Controles --- */

.tm-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.6rem;
}

.tm-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.tm-field > span {
    color: var(--muted);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tm-field select {
    min-width: 11rem;
}

.tm-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
}

.tm-toggle input {
    accent-color: var(--accent);
    margin: 0;
}

.tm-layers {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.5rem 0.25rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(57, 135, 229, 0.06);
}

.tm-layers-title {
    color: var(--muted);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tm-layers .tm-toggle {
    padding: 0.2rem 0.45rem;
    font-size: 0.8125rem;
}

/* --- Marcas de las capas derivadas (leyenda) --- */

.tm-mark {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.tm-mark-nr {
    background: #9085e9;
    border: 1px solid #9085e9;
}

/* Chincheta de la última posición: halo pulsante para encontrarla de un vistazo. */
.tm-ultima {
    background: none;
    border: none;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}

.tm-ultima-halo {
    position: absolute;
    left: 13px;
    top: 12px;
    width: 0;
    height: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(57, 135, 229, 0.55);
    animation: tm-ping 2.2s ease-out infinite;
}

@keyframes tm-ping {
    0% { box-shadow: 0 0 0 0 rgba(57, 135, 229, 0.5); }
    70% { box-shadow: 0 0 0 22px rgba(57, 135, 229, 0); }
    100% { box-shadow: 0 0 0 0 rgba(57, 135, 229, 0); }
}

/* El ícono de antena necesita separarse de cualquier fondo de tiles. */
.tm-antena {
    background: none;
    border: none;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}

.tm-mark-antenna {
    background: none;
    border: none;
    width: 14px;
    height: 16px;
    position: relative;
}

.tm-mark-antenna::before,
.tm-mark-antenna::after {
    content: "";
    position: absolute;
    background: var(--accent);
}

/* Mástil */
.tm-mark-antenna::before {
    left: 6px;
    top: 5px;
    width: 2px;
    height: 11px;
}

/* Emisor */
.tm-mark-antenna::after {
    left: 4px;
    top: 1px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.tm-mark-hole {
    background: transparent;
    border: 3px solid #d03b3b;
}

.tm-mark-handover {
    background: rgba(250, 178, 25, 0.35);
    border: 2px solid #fab219;
}

.tm-overlays {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line-soft);
}

/* --- Indicadores --- */

.tm-stats {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.tm-stat {
    min-width: 5.5rem;
    padding: 0.35rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
}

.tm-stat-wide {
    min-width: 7.5rem;
}

.tm-stat-value {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.15;
}

.tm-stat-time {
    font-family: var(--mono);
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.tm-stat-label {
    color: var(--muted);
    font-size: 0.6875rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.tm-stat.is-live {
    border-color: rgba(12, 163, 12, 0.5);
    background: rgba(12, 163, 12, 0.1);
}

.tm-stat.is-live .tm-stat-value {
    color: var(--good);
}

/* --- Mapa --- */

.tm-map-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
}

.tm-map {
    position: absolute;
    inset: 0;
}

.leaflet-container {
    background: #0b0b0b;
    font-family: var(--sans);
}

.leaflet-control-zoom a,
.leaflet-bar a {
    background: var(--glass);
    border-color: var(--line) !important;
    color: var(--ink);
}

.leaflet-control-zoom a:hover {
    background: var(--surface-2);
    color: var(--accent);
}

.leaflet-control-attribution {
    background: rgba(13, 13, 13, 0.75) !important;
    color: var(--muted) !important;
    font-size: 0.6875rem;
}

.leaflet-control-attribution a {
    color: var(--ink-2) !important;
}

/* Modo mancha: el desenfoque se aplica al pane completo de mediciones, no a
   cada figura. Un borde nítido sugeriría que la cobertura termina justo ahí. */
.leaflet-pane.tm-blobs {
    filter: blur(9px);
}

@media (max-width: 900px) {
    .leaflet-pane.tm-blobs {
        filter: blur(6px);
    }
}

/* Punto recién llegado: un destello corto que decae al estilo normal. */
.mp-live {
    animation: mp-arrive 1.6s ease-out 1;
}

@keyframes mp-arrive {
    from { stroke-width: 12; stroke-opacity: 0.45; }
    to { stroke-width: 2; stroke-opacity: 1; }
}

/* --- Leyenda --- */

.tm-legend {
    position: absolute;
    left: 1rem;
    bottom: 1.6rem;
    z-index: 500;
    min-width: 13.5rem;
    max-height: calc(100% - 3.5rem);
    overflow-y: auto;
    padding: 0.6rem 0.75rem;
    background: var(--glass);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.tm-legend h2 {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--line-soft);
}

.tm-legend-unit {
    color: var(--muted);
    font-family: var(--mono);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.tm-legend ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tm-ops {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
}

.tm-ops li {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
}

.tm-ops-empty {
    display: block !important;
    color: var(--muted);
    font-size: 0.75rem;
}

/* --- Escala de tamaño --- */

.tm-size {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line-soft);
}

.tm-size-body {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
}

.tm-size-scale {
    width: 64px;
    height: 50px;
    flex: none;
}

.tm-size-scale circle {
    fill: rgba(255, 255, 255, 0.06);
    stroke: var(--ink-2);
    stroke-width: 1;
}

.tm-size-marks {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 50px;
    font-size: 0.6875rem;
    color: var(--muted);
}

.tm-size-marks span {
    color: var(--ink-2);
    font-family: var(--mono);
}

.tm-size-marks em {
    font-style: normal;
    color: var(--ink-2);
    opacity: 0.75;
}

.tm-size-note {
    margin: 0.5rem 0 0;
    font-size: 0.6875rem;
    color: var(--muted);
    line-height: 1.3;
}

/* --- Tooltip de un círculo --- */

.mp-tip.leaflet-tooltip {
    background: #151514;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    color: var(--ink);
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
}

.mp-tip.leaflet-tooltip::before {
    border-top-color: var(--line);
}

.mp-tip-op {
    font-weight: 600;
    margin-right: 0.4rem;
}

.mp-tip-val {
    color: var(--ink-2);
    font-family: var(--mono);
}

.mp-tip-aviso {
    color: var(--warning);
    font-size: 0.6875rem;
}

.tm-band-label {
    color: var(--ink-2);
}

.tm-band-range {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.75rem;
}

.tm-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px #0d0d0d, 0 0 0 3px var(--line-soft);
}

/* --- Overlays de estado --- */

.tm-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1.1rem;
    background: var(--glass);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    backdrop-filter: blur(14px);
    color: var(--ink-2);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.tm-overlay-empty {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    max-width: 26rem;
}

.tm-overlay-empty strong {
    color: var(--ink);
}

.tm-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: tm-spin 700ms linear infinite;
}

@keyframes tm-spin {
    to { transform: rotate(360deg); }
}

/* --- Modal de detalle --- */

.tm-modal {
    width: min(1080px, 94vw);
    max-height: 88vh;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.65);
    overflow: hidden;
}

.tm-modal::backdrop {
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(3px);
}

.tm-modal-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 2.5rem;
    color: var(--ink-2);
}

.tm-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.tm-modal-head h2 {
    font-size: 1.0625rem;
    font-family: var(--mono);
    letter-spacing: -0.01em;
}

.tm-modal-head p {
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 0.8125rem;
}

.tm-modal-close {
    flex: none;
    padding: 0.25rem 0.55rem;
    line-height: 1;
}

.tm-modal-body {
    padding: 1rem 1.1rem 1.2rem;
    overflow-y: auto;
    max-height: calc(88vh - 4.5rem);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.tm-modal h3 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

/* Dos fichas de datos lado a lado mientras haya ancho. */
.tm-facts {
    break-inside: avoid;
}

.tm-facts dl {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 0.35rem 1.2rem;
}

.tm-facts dl > div {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--line-soft);
    font-size: 0.8125rem;
}

.tm-facts dt {
    color: var(--muted);
}

.tm-facts dd {
    margin: 0;
    color: var(--ink-2);
    text-align: right;
}

.tm-mono {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

.tm-wrap {
    word-break: break-all;
}

.tm-line-slot {
    margin-left: auto;
    color: var(--muted);
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    font-family: var(--mono);
}

.tm-line-state {
    margin: 0 0 0.5rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.tm-line-state strong {
    color: var(--ink-2);
    font-weight: 600;
}

.tm-cells {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

.tm-cells th {
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    padding: 0.25rem 0.5rem 0.25rem 0;
}

.tm-cells td {
    padding: 0.28rem 0.5rem 0.28rem 0;
    border-bottom: 1px solid var(--line-soft);
    color: var(--ink-2);
}

.tm-cells .tm-num {
    text-align: right;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

.tm-cells .tm-serving td {
    color: var(--ink);
    font-weight: 600;
    background: var(--accent-soft);
}

.tm-neighbor {
    color: var(--muted);
}

/* --- Pantallas angostas --- */

@media (max-width: 900px) {
    .tm-stats {
        margin-left: 0;
        width: 100%;
    }

    .tm-field select {
        min-width: 8.5rem;
    }

    .tm-legend {
        left: 0.6rem;
        bottom: 0.9rem;
        min-width: 11rem;
    }

    .tm-modal {
        width: 96vw;
        max-height: 92vh;
    }

    .tm-modal-body {
        max-height: calc(92vh - 4.5rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-pulse,
    .mp-live,
    .tm-spinner,
    .tm-ultima-halo {
        animation: none;
    }
}
