/**
 * territorial-selection.css — Estilos do Visualizador e da Régua 2D
 * Subetapa 10.9.9.174 — HDPlanner
 */

/* Somente durante o desenho: cursor crosshair indicando captura de vértices */
.leaflet-container.territorial-selection-drawing {
    cursor: crosshair !important;
}

.territorial-viewer-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.territorial-viewer-dialog {
    width: 95vw;
    height: 94vh;
    max-width: 1700px;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.territorial-viewer-header {
    background: #1e293b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.territorial-viewer-title-box {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.territorial-viewer-tag {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #38bdf8;
    text-transform: uppercase;
}

.territorial-viewer-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #f8fafc;
}

.territorial-viewer-sub {
    font-size: 0.68rem;
    color: #94a3b8;
}

.territorial-viewer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Body (2 Colunas) */
.territorial-viewer-body {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
}

/* Sidebar / Painel de Controle */
.territorial-viewer-sidebar {
    width: 380px;
    min-width: 340px;
    max-width: 420px;
    background: #111827;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Cards do Painel */
.tv-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    overflow: hidden;
}

.tv-card-header {
    background: rgba(30, 41, 59, 0.9);
    padding: 6px 10px;
    font-size: 0.68rem;
    font-weight: 700;
    color: #cbd5e1;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tv-card-body {
    padding: 10px;
}

/* Grid de métricas do snapshot */
.tv-grid-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.tv-metric-item {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
}

.tv-metric-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: #38bdf8;
}

.tv-metric-label {
    font-size: 0.62rem;
    color: #94a3b8;
    text-transform: uppercase;
}

.tv-hash-box {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tv-hash-label {
    font-size: 0.58rem;
    color: #64748b;
    text-transform: uppercase;
}

.tv-hash-code {
    font-family: monospace;
    font-size: 0.62rem;
    color: #34d399;
    word-break: break-all;
    user-select: all;
}

/* Régua 2D Toolbar */
.tv-ruler-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 6px;
}

.tv-ruler-btn {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    padding: 6px 4px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.15s ease;
}

.tv-ruler-btn:hover {
    background: #334155;
    border-color: #38bdf8;
}

.tv-ruler-btn.active {
    background: #0284c7;
    border-color: #38bdf8;
    color: #ffffff;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

.tv-ruler-btn .tv-icon {
    font-size: 0.9rem;
}

/* Painel da Medição Ativa */
.tv-active-meas-panel {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 4px;
    padding: 8px;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tv-ruler-status {
    font-size: 0.68rem;
    color: #38bdf8;
    font-style: italic;
}

.tv-ruler-live-metrics {
    font-size: 0.72rem;
    color: #f1f5f9;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 6px;
    border-radius: 3px;
}

.tv-ruler-save-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.tv-ruler-unit-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.68rem;
    color: #94a3b8;
}

.tv-ruler-unit-row select {
    flex: 1;
    font-size: 0.7rem;
    padding: 2px 4px;
    background: #1e293b;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.tv-ruler-actions-row {
    display: flex;
    gap: 6px;
}

.tv-ruler-actions-row button {
    flex: 1;
    padding: 4px;
    font-size: 0.68rem;
}

/* Lista de Medições Salvas */
.tv-meas-list-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.tv-badge {
    color: #38bdf8;
    font-weight: bold;
}

.tv-meas-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
}

.tv-meas-empty {
    font-size: 0.7rem;
    color: #64748b;
    text-align: center;
    padding: 16px 8px;
    font-style: italic;
}

.tv-meas-item {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 3px solid #38bdf8;
    border-radius: 4px;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tv-meas-item[data-type="line"] { border-left-color: #3b82f6; }
.tv-meas-item[data-type="path"] { border-left-color: #10b981; }
.tv-meas-item[data-type="polygon"] { border-left-color: #f59e0b; }
.tv-meas-item[data-type="circle"] { border-left-color: #8b5cf6; }

.tv-meas-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tv-meas-name {
    font-size: 0.72rem;
    font-weight: 700;
    color: #f1f5f9;
}

.tv-meas-type-badge {
    font-size: 0.58rem;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 2px;
    text-transform: uppercase;
}

.tv-meas-type-badge.line { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.tv-meas-type-badge.path { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.tv-meas-type-badge.polygon { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.tv-meas-type-badge.circle { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }

.tv-meas-details {
    font-size: 0.68rem;
    color: #cbd5e1;
}

.tv-meas-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

/* Área do Mapa */
.territorial-viewer-map-area {
    flex: 1;
    position: relative;
    background: #020617;
}

.territorial-viewer-map-container {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Legenda do Mapa */
.tv-map-legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    padding: 6px 10px;
    display: flex;
    gap: 12px;
    font-size: 0.65rem;
    color: #cbd5e1;
    pointer-events: none;
}

.tv-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.tv-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.tv-legend-dot.ep-dot { background: #38bdf8; }
.tv-legend-dot.gw-orig-dot { background: #10b981; }
.tv-legend-dot.gw-sugg-dot { background: #f97316; }
.tv-legend-dot.poste-dot { background: #eab308; }
.tv-legend-line.poly-border {
    width: 12px;
    height: 2px;
    background: #ec4899;
}

/* Indicadores de cores na legenda para as medições */
.tv-legend-line.meas-line-color {
    width: 12px;
    height: 2px;
    background: #3b82f6;
}
.tv-legend-line.meas-path-color {
    width: 12px;
    height: 2px;
    background: #10b981;
}
.tv-legend-dot.meas-poly-color {
    background: #f59e0b;
}
.tv-legend-dot.meas-circle-color {
    background: #8b5cf6;
}

/* =========================================================================
   ESTILOS DE IMPRESSÃO E EXPORTAÇÃO PDF (Subetapa 10.9.9.175)
   ========================================================================= */

/* Em tela normal, a seção do relatório de impressão permanece oculta */
.tv-print-report-section {
    display: none;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 10mm 12mm 12mm 12mm;
    }

    /* Oculta tudo na página exceto o modal do visualizador */
    body * {
        visibility: hidden !important;
    }

    body > *:not(#modalTerritorialViewer) {
        display: none !important;
    }

    html, body {
        background: #ffffff !important;
        color: #0f172a !important;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Torna o modal e todos os seus filhos visíveis */
    #modalTerritorialViewer,
    #modalTerritorialViewer * {
        visibility: visible !important;
    }

    .territorial-viewer-modal-overlay {
        position: static !important;
        display: block !important;
        width: 100% !important;
        height: auto !important;
        background: transparent !important;
        backdrop-filter: none !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        z-index: auto !important;
    }

    .territorial-viewer-dialog {
        position: static !important;
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        background: #ffffff !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* Cabeçalho para impressão */
    .territorial-viewer-header {
        background: #f8fafc !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 6px !important;
        padding: 10px 14px !important;
        margin-bottom: 6mm !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .territorial-viewer-tag {
        color: #0284c7 !important;
        font-size: 0.65rem !important;
        font-weight: 700 !important;
    }

    .territorial-viewer-title {
        color: #0f172a !important;
        font-size: 1.15rem !important;
        font-weight: 800 !important;
        margin-top: 2px !important;
    }

    .territorial-viewer-sub {
        color: #475569 !important;
        font-size: 0.72rem !important;
    }

    /* Ocultar botões interativos e de ação */
    .territorial-viewer-actions,
    .tv-ruler-buttons,
    #tvActiveMeasurementPanel,
    .tv-meas-actions,
    .btn-tiny {
        display: none !important;
    }

    /* Reorganizar o corpo do modal em fluxo vertical contínuo */
    .territorial-viewer-body {
        display: block !important;
        position: static !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* Em impressão, a sidebar interativa de tela é ocultada para dar lugar à tabela formal */
    .territorial-viewer-sidebar {
        display: none !important;
    }

    /* Área do Mapa: dimensões físicas perfeitas para a folha A4 */
    .territorial-viewer-map-area {
        display: block !important;
        position: relative !important;
        width: 100% !important;
        height: 110mm !important;
        background: #f1f5f9 !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 6px !important;
        margin-bottom: 6mm !important;
        overflow: hidden !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .territorial-viewer-map-container {
        width: 100% !important;
        height: 100% !important;
        position: relative !important;
    }

    /* Controles de zoom do Leaflet não devem ser impressos */
    .leaflet-control-zoom,
    .leaflet-control-attribution {
        display: none !important;
    }

    /* Legenda do Mapa em Impressão */
    .tv-map-legend {
        position: absolute !important;
        bottom: 8px !important;
        left: 8px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 4px !important;
        padding: 5px 10px !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
        font-size: 0.68rem !important;
        color: #0f172a !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
        z-index: 1000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Seção do Relatório de Impressão */
    .tv-print-report-section {
        display: block !important;
        width: 100% !important;
        page-break-before: auto !important;
    }

    .tv-print-card {
        border: 1px solid #cbd5e1 !important;
        border-radius: 6px !important;
        background: #ffffff !important;
        overflow: hidden !important;
        margin-bottom: 6mm !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .tv-print-card-title {
        background: #f1f5f9 !important;
        padding: 7px 12px !important;
        font-size: 0.72rem !important;
        font-weight: 700 !important;
        color: #1e293b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.05em !important;
        border-bottom: 1px solid #cbd5e1 !important;
    }

    .tv-print-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 0.74rem !important;
        text-align: left !important;
    }

    .tv-print-table th {
        background: #f8fafc !important;
        color: #334155 !important;
        font-weight: 600 !important;
        padding: 6px 10px !important;
        border-bottom: 1px solid #cbd5e1 !important;
        font-size: 0.7rem !important;
        text-transform: uppercase !important;
    }

    .tv-print-table td {
        padding: 6px 10px !important;
        border-bottom: 1px solid #e2e8f0 !important;
        vertical-align: middle !important;
        color: #0f172a !important;
    }

    .tv-print-row {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .tv-print-row:nth-child(even) {
        background: #f8fafc !important;
    }

    .tv-print-badge {
        display: inline-block !important;
        padding: 2px 6px !important;
        border-radius: 3px !important;
        font-size: 0.65rem !important;
        font-weight: 600 !important;
        text-transform: uppercase !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .tv-print-badge-line { background: #dbeafe !important; color: #1e40af !important; border: 1px solid #93c5fd !important; }
    .tv-print-badge-path { background: #d1fae5 !important; color: #065f46 !important; border: 1px solid #6ee7b7 !important; }
    .tv-print-badge-polygon { background: #fef3c7 !important; color: #92400e !important; border: 1px solid #fcd34d !important; }
    .tv-print-badge-circle { background: #ede9fe !important; color: #5b21b6 !important; border: 1px solid #c4b5fd !important; }

    /* Rodapé da folha */
    .tv-print-footer {
        display: flex !important;
        justify-content: space-between !important;
        font-size: 0.65rem !important;
        color: #64748b !important;
        border-top: 1px solid #e2e8f0 !important;
        padding-top: 4mm !important;
        margin-top: 4mm !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
}
