/* ========================================
   TRANSPORTE DE PACIENTES VIEW
   ======================================== */

#view-transporte-pacientes {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 1rem;
    overflow: hidden;
    gap: 1rem;
    justify-content: flex-start !important;
    /* Force items to start at top */
}

#view-transporte-pacientes.active {
    display: flex;
}

.tp-view-title {
    color: var(--text-main, #f8fafc);
}

/* --- Metrics Row --- */
.metrics-row {
    display: flex;
    gap: 1rem;
    width: 100%;
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: flex-start;
    /* Ensure cards align to top */
}

.metric-card {
    background: var(--bg-card, rgba(30, 41, 59, 0.7));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    flex: 1;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* --- Balão informativo dos KPIs (hover) --- */
.metric-card[data-tp-tip] {
    position: relative;
    cursor: help;
}

/* .metric-card tem backdrop-filter, que por si só já cria um contexto de empilhamento —
   isso prende o z-index do balão (::after/::before) dentro do próprio card e o card
   inteiro acaba renderizado atrás de elementos posteriores no HTML (ex.: o Kanban),
   já que o card em si não tinha z-index. Elevar o card no hover resolve. */
.metric-card[data-tp-tip]:hover {
    z-index: 100;
}

.metric-card[data-tp-tip]::after {
    content: attr(data-tp-tip);
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: #0f172a;
    color: #f1f5f9;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.45;
    text-transform: none;
    letter-spacing: normal;
    white-space: normal;
    width: max-content;
    max-width: 260px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 60;
}

.metric-card[data-tp-tip]::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(2px);
    border: 6px solid transparent;
    border-bottom-color: #0f172a;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 61;
}

.metric-card[data-tp-tip]:hover::after,
.metric-card[data-tp-tip]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.metric-title {
    font-size: 0.85rem;
    color: var(--text-muted, #94a3b8);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main, #ffffff);
    margin-bottom: 0.25rem;
}

.metric-trend {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 500;
}

.metric-trend.positive {
    color: #10b981;
}

.metric-trend.negative {
    color: #ef4444;
}

.metric-trend.neutral {
    color: #64748b;
}

/* --- Kanban Board Layout --- */
.kanban-board {
    display: flex;
    gap: 1rem;
    flex: 1;
    height: calc(100vh - 210px); /* Altura fixa baseada na viewport para habilitar rolagem interna individual nas colunas */
    /* Ocupa o restante da altura */
    min-height: 0;
    /* Permite scroll interno */
    overflow-x: auto;
    /* Scroll horizontal se necessário */
    padding-bottom: 0.5rem;
}

.kanban-column {
    flex: 1;
    min-width: 280px;
    max-width: 400px;
    background: var(--bg-column, rgba(255, 255, 255, 0.03));
    border-radius: 12px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.05));
    display: flex;
    flex-direction: column;
    height: 100%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.kanban-column .column-header {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

.kanban-column .column-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: white;
}

.kanban-column .column-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* --- Novo Layout do Card de Transporte (Rigoroso 4 Linhas) --- */
.event-card,
.event-card-finished {
    display: flex !important;
    flex-direction: column !important;
    padding: 10px !important;
    gap: 6px !important;
    min-height: unset !important;
}

.card-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

.text-left {
    text-align: left !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
}

.text-right {
    text-align: right !important;
}

.patient-name {
    font-weight: 800 !important;
    font-size: 0.95rem !important;
    color: var(--text-main, #0f172a) !important;
    margin: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.badge-origin {
    background: rgba(59, 130, 246, 0.1) !important;
    color: #1d4ed8 !important;
    padding: 3px 6px !important;
    border-radius: 4px !important;
    font-weight: 800 !important;
    font-size: 0.75rem !important;
    display: inline-flex !important;
    align-items: center !important;
    border: 1px solid rgba(59, 130, 246, 0.2) !important;
}

.badge-destination {
    background: rgba(16, 185, 129, 0.1) !important;
    color: #059669 !important;
    padding: 3px 6px !important;
    border-radius: 4px !important;
    font-weight: 800 !important;
    font-size: 0.75rem !important;
    display: inline-flex !important;
    align-items: center !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
}

.route-arrow {
    color: #64748b !important;
    font-size: 0.7rem !important;
    margin: 0 2px !important;
}

.card-time {
    font-size: 0.9rem !important;
    font-weight: 800 !important;
}

.card-equipment {
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
    font-weight: 600 !important;
}

.card-reason {
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
    font-style: italic !important;
}

.elapsed-time {
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    width: auto !important;
    flex-shrink: 0 !important;
    margin-left: auto !important;
    white-space: nowrap !important;
}

.badge-biohazard {
    background: #dc2626 !important;
    color: #ffffff !important;
    padding: 2px 8px !important;
    border-radius: 4px !important;
    font-size: 0.75rem !important;
    font-weight: 900 !important;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3) !important;
    border: none !important;
    text-transform: uppercase !important;
}

/* Bordas de Urgência */
.border-urgent {
    border-left: 6px solid #f59e0b !important;
}

.border-biohazard {
    outline: 2px solid #ef4444 !important;
    outline-offset: -2px !important;
}

/* Impedimento (Aguardar) — cor diferenciada + contador de espera no card */
.event-card-impediment {
    background: rgba(245, 158, 11, 0.16) !important;
    outline: 2px solid #f59e0b !important;
    outline-offset: -2px !important;
    animation: impedimentPulse 2.2s infinite;
}

@keyframes impedimentPulse {
    0%, 100% { outline-color: rgba(245, 158, 11, 0.9); }
    50% { outline-color: rgba(245, 158, 11, 0.35); }
}

.impediment-badge {
    color: #f59e0b !important;
    font-weight: 700;
    font-size: 0.75rem;
}

.impediment-timer {
    background: #f59e0b !important;
    color: #1e1206 !important;
    padding: 2px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Espera > N min no encaminhamento ao Centro Cirúrgico (Nível 3 de sobrecarga) */
.event-card-cc-wait-alert {
    outline: 2px solid #dc2626 !important;
    outline-offset: -2px !important;
    animation: ccWaitAlertPulse 1.8s infinite;
}

@keyframes ccWaitAlertPulse {
    0%, 100% { outline-color: rgba(220, 38, 38, 0.95); }
    50% { outline-color: rgba(220, 38, 38, 0.3); }
}

.badge-cc-wait {
    background: #dc2626 !important;
    color: #ffffff !important;
    padding: 2px 8px !important;
    border-radius: 4px !important;
    font-size: 0.7rem !important;
    font-weight: 800 !important;
    display: inline-flex !important;
    align-items: center;
    gap: 3px;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.35) !important;
    text-transform: uppercase !important;
    margin-bottom: 4px;
}

/* Adaptação para Light Mode */
.light-mode .metric-card {
    background: #ffffff;
    border-color: #e2e8f0;
}

.light-mode .metric-value {
    color: #0f172a;
}

.light-mode .patient-name {
    color: #0f172a;
}

.light-mode .kanban-column {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.light-mode .kanban-column .column-count {
    color: white;
    /* Mantém contraste com o header colorido */
    background: rgba(0, 0, 0, 0.2);
}

.light-mode .card-bed-badge {
    background: #eff6ff;
    color: #1d4ed8;
}

/* Novo Transporte - Estilos de Cores */
#tpNewUsuario:disabled {
    background: #0f172a !important;
    color: #94a3b8 !important;
}

.light-mode #tpNewUsuario:disabled {
    background: #f1f5f9 !important;
    color: #64748b !important;
}

.light-mode .tp-agents-list-container {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
}

.light-mode .tp-agents-list-container label {
    color: #334155 !important;
}

.light-mode .tp-agents-list-container span {
    color: #94a3b8 !important;
}

.light-mode .tp-agent-select-title {
    color: #475569 !important;
}

/* Ajustes Responsivos */
@media (max-width: 768px) {
    #view-transporte-pacientes {
        padding: 0.5rem;
        overflow: auto;
    }

    .kanban-board {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        gap: 0.75rem;
    }

    .kanban-column {
        min-width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 200px;
    }

    .kanban-column .column-body {
        max-height: 350px;
    }

    .metrics-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .metric-card {
        min-width: 100%;
        padding: 0.75rem 1rem;
    }

    .metric-value {
        font-size: 1.4rem;
    }

    .metric-title {
        font-size: 0.75rem;
    }

    /* Cards de transporte */
    .patient-name {
        font-size: 0.85rem !important;
    }

    .badge-origin,
    .badge-destination {
        font-size: 0.7rem !important;
        padding: 2px 5px !important;
    }

    .card-time {
        font-size: 0.8rem !important;
    }

    .card-equipment,
    .card-reason {
        font-size: 0.7rem !important;
    }

    .elapsed-time {
        font-size: 0.7rem !important;
    }
}

@media (max-width: 480px) {
    .kanban-column .column-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .kanban-column .column-count {
        font-size: 0.7rem;
        padding: 2px 6px;
    }

    .kanban-column .column-body {
        padding: 0.5rem;
        gap: 0.5rem;
    }
}

/* --- Modal Trajeto Colors --- */
.tp-trajeto-container {
    background:linear-gradient(135deg, rgba(14,165,233,0.1), rgba(56,189,248,0.02)); 
    border:1px solid rgba(56,189,248,0.15); 
}
.light-mode .tp-trajeto-container {
    background:linear-gradient(135deg, #f0f9ff, #ffffff);
    border:1px solid #bae6fd;
}
.tp-trajeto-content {
    display:flex; align-items:stretch; justify-content:space-between; gap:10px; width:100%;
}
.tp-box-origem, .tp-box-destino {
    flex:1; display:flex; align-items:center; gap:12px; 
    padding:10px 14px; border-radius:8px; box-shadow:inset 0 2px 4px rgba(0,0,0,0.1);
}
.tp-box-origem {
    background:rgba(15,23,42,0.4); 
    border:1px solid rgba(255,255,255,0.05);
}
.tp-box-destino {
    background:rgba(56,189,248,0.1); 
    border:1px solid rgba(56,189,248,0.2);
}
.tp-icon-origem {
    width:34px; height:34px; border-radius:50%; background:rgba(100,116,139,0.3); color:#e2e8f0; display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:1.2rem;
}
.tp-icon-destino {
    width:34px; height:34px; border-radius:50%; background:#0ea5e9; color:#ffffff; display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:1.2rem;
}
.tp-label-origem, .tp-label-destino {
    font-size:0.65rem; text-transform:uppercase; font-weight:600;
}
.tp-label-origem { color:#94a3b8; }
.tp-label-destino { color:#0ea5e9; }
.tp-value-origem, .tp-value-destino {
    font-weight:700; font-size:0.95rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.tp-value-origem { color:#f8fafc; }
.tp-value-destino { color:#0ea5e9; }

/* Light mode adjustments */
.light-mode .tp-box-origem { background:#f1f5f9; border:1px solid #cbd5e1; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.light-mode .tp-box-destino { background:#e0f2fe; border:1px solid #7dd3fc; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.light-mode .tp-icon-origem { background:#94a3b8; color:#ffffff; }
.light-mode .tp-icon-destino { background:#0284c7; color:#ffffff; }
.light-mode .tp-label-origem { color:#64748b; }
.light-mode .tp-value-origem { color:#0f172a; }
.light-mode .tp-label-destino { color:#0369a1; }
.light-mode .tp-value-destino { color:#0c4a6e; }

/* ── Correções Temáticas e Rolagem do Kanban de Transporte ── */

/* Título com ícone de cadeira de rodas - Correção Tema Claro */
#view-transporte-pacientes h2 {
    color: var(--text-main) !important;
}

/* Correção de Rolagem Individual das Colunas do Kanban */
body.view-transporte-active,
body.view-transporte-active .main-layout,
body.view-transporte-active .content-area {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

body.view-transporte-active .view-container {
    height: calc(100vh - 60px) !important;
    max-height: calc(100vh - 60px) !important;
    overflow: hidden !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
}

#view-transporte-pacientes.active {
    height: 100% !important;
    max-height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.tp-content-wrapper {
    display: flex !important;
    gap: 20px !important;
    flex: 1 !important;
    min-height: 0 !important;
    align-items: stretch !important;
    height: 100% !important;
    overflow: hidden !important;
}

.tp-main-content {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important;
    height: 100% !important;
    overflow: hidden !important;
}

.kanban-board {
    display: flex !important;
    gap: 1rem !important;
    flex: 1 !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow-x: auto !important;
    padding-bottom: 0.5rem !important;
}

/* Estética Premium para a Sidebar de Equipe no Tema Claro */
.light-mode .tp-equipe-sidebar {
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important;
}

.light-mode .tp-equipe-header {
    color: #0f172a !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

.light-mode #tpSearchColab {
    background: #f1f5f9 !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
}

.light-mode #tpSearchColab::placeholder {
    color: #94a3b8 !important;
}

/* ═══════════════════════════════════════════════════════════════
   Badge de Nível de Volume de Atendimento (itens 8 e 9)
   ═══════════════════════════════════════════════════════════════ */
.tp-overload-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 2px solid #94a3b8;
    background: rgba(148, 163, 184, 0.12);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.tp-overload-badge:hover {
    background: rgba(148, 163, 184, 0.22);
}

.tp-overload-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.25);
}

.tp-overload-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 300px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    padding: 14px 16px;
    z-index: 50;
}

.tp-overload-panel-title {
    font-weight: 800;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.tp-overload-panel-message {
    font-size: 0.8rem;
    line-height: 1.4;
    color: #94a3b8;
    margin-bottom: 10px;
}

.tp-overload-panel-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: #cbd5e1;
    border-top: 1px solid #334155;
    padding-top: 8px;
}

.tp-overload-panel-stats i {
    margin-right: 4px;
    color: #64748b;
}

.light-mode .tp-overload-badge {
    background: rgba(148, 163, 184, 0.1);
}

.light-mode .tp-overload-panel {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.light-mode .tp-overload-panel-title {
    color: #0f172a;
}

.light-mode .tp-overload-panel-stats {
    color: #334155;
    border-top-color: #e2e8f0;
}