/*
 * Popup do histórico (.leaflet-popup-history)
 *
 * A marcação já existe no bundle (public/assets/js/app.js) e é montada assim:
 *
 *   .history-popup-card
 *     ├─ a.history-popup-close
 *     ├─ .history-popup-header
 *     │    ├─ .history-popup-header-icon
 *     │    └─ div > .history-popup-title + .history-popup-subtitle
 *     └─ .history-popup-body
 *          └─ .history-popup-row
 *               ├─ .history-popup-row-icon
 *               └─ .history-popup-row-content
 *                    ├─ .history-popup-row-label
 *                    └─ .history-popup-row-value
 *
 * Só faltava o estilo: sem ele o popup renderiza sem hierarquia visual.
 * Os valores espelham o popup do veículo (map/marker-popup.css), a referência
 * visual do tema. Nada aqui toca .leaflet-popup-event, que compartilha o CSS
 * legado gerado.
 */

body.ui-new-nav .leaflet-popup-history .leaflet-popup-content-wrapper {
    padding: 0;
    overflow: hidden;
    border-radius: 10px;
    background: var(--color-white);
    box-shadow: 0 6px 24px var(--color-overlay-shadow-18);
}

body.ui-new-nav .leaflet-popup-history .leaflet-popup-content {
    width: auto !important;
    min-width: 268px;
    max-width: 340px;
    margin: 0;
    line-height: 1.45;
}

body.ui-new-nav .leaflet-popup-history .leaflet-popup-tip {
    background: var(--color-white);
    box-shadow: 0 6px 24px var(--color-overlay-shadow-18);
}

body.ui-new-nav .leaflet-popup-history .leaflet-popup-close-button {
    display: none;
}

body.ui-new-nav .leaflet-popup-history .history-popup-card {
    position: relative;
    color: var(--color-text-emphasis);
    font-size: 11px;
    font-family: inherit;
}

/* ----------------------------- cabeçalho ----------------------------- */

body.ui-new-nav .leaflet-popup-history .history-popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 40px 8px 12px; /* espaço à direita para o fechar */
    background: var(--color-primary-map);
}

body.ui-new-nav .leaflet-popup-history .history-popup-header-icon {
    flex-shrink: 0;
    width: 22px;
    min-width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--color-overlay-white-12);
    color: var(--color-text-on-primary);
    font-size: 11px;
    line-height: 1;
}

body.ui-new-nav .leaflet-popup-history .history-popup-title {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.02em;
    color: var(--color-text-on-primary);
    word-break: break-word;
}

body.ui-new-nav .leaflet-popup-history .history-popup-subtitle {
    margin: 1px 0 0;
    font-size: 9px;
    font-weight: 400;
    line-height: 1.35;
    color: var(--color-map-header-text-muted);
    word-break: break-word;
}

body.ui-new-nav .leaflet-popup-history .history-popup-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--color-map-header-text-muted);
    font-size: 14px;
    line-height: 1;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

body.ui-new-nav .leaflet-popup-history .history-popup-close:hover,
body.ui-new-nav .leaflet-popup-history .history-popup-close:focus {
    color: var(--color-text-on-primary);
    background: var(--color-overlay-white-12);
    text-decoration: none;
}

/* ------------------------------- corpo ------------------------------- */

body.ui-new-nav .leaflet-popup-history .history-popup-body {
    max-height: 320px;
    padding: 9px 12px;
    overflow-y: auto;
    background: var(--color-white);
}

body.ui-new-nav .leaflet-popup-history .history-popup-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 7px;
}

body.ui-new-nav .leaflet-popup-history .history-popup-row:last-child {
    margin-bottom: 0;
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-icon {
    flex-shrink: 0;
    width: 20px;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border-input);
    border-radius: 5px;
    color: var(--color-text-secondary);
    font-size: 10px;
    line-height: 1;
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-content {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 11px;
    line-height: 1.35;
    word-break: break-word;
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-label {
    font-weight: 700;
    color: var(--color-text-body-secondary);
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-value {
    font-weight: 400;
    color: var(--color-text-emphasis);
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-value a {
    color: var(--color-primary);
    text-decoration: none;
}

body.ui-new-nav .leaflet-popup-history .history-popup-row-value a:hover {
    text-decoration: underline;
}

/* O endereço chega por requisição; evita a linha "pular" enquanto carrega. */
body.ui-new-nav .leaflet-popup-history .history-popup-row-value [data-device="address"]:empty::before {
    content: "…";
    color: var(--color-text-disabled);
}

/* Bloco extra de parâmetros (colapsável) que alguns pontos trazem. */
body.ui-new-nav .leaflet-popup-history .history-popup-body #history-point-params .table > tbody > tr > th,
body.ui-new-nav .leaflet-popup-history .history-popup-body #history-point-params .table > tbody > tr > td {
    padding: 4px 0;
    border: 0;
    font-size: 10px;
    color: var(--color-text-body-secondary);
    word-break: break-word;
}
