/* ==========================================
   DASHBOARD TV - Sobrescrituras para Smart TV
   v17.0 - Detección por ALTURA ≤ 800px
   
   Cubre:
   - TV 25" (34x64 cm) → 1366x768
   - TV 32" → 1280x720
   - Zoom 67% en TV 25" → viewport 2040x768
   - Cualquier pantalla baja (≤800px alto)
========================================== */

/* ==========================================
   REGLA MAESTRA: altura ≤ 800px + ancho ≥ 1024px
   = SIEMPRE layout compacto de TV
========================================== */
@media (max-height: 800px) and (min-width: 1024px) {

    :root {
        --tv-toolbar-h: 42px;
        --tv-avatars-h: 145px;
        --tv-kpi-h: 145px;
        --tv-gap: 6px;
        --tv-padding: 6px;
        --card-min: 78px;
        --grid-gap: 6px;
    }

    /* Fijar el body sin scroll */
    html, body {
        height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        margin: 0;
        padding: 0;
        font-size: 11px;
    }

    body {
        display: flex;
        flex-direction: column;
        gap: var(--tv-gap);
        padding: var(--tv-padding) 8px;
        box-sizing: border-box;
        background: var(--md-gray);
    }

    /* ==========================================
       OCULTAR ELEMENTOS NO ESENCIALES
    ========================================== */
    .eficiencia-section,
    .charts-section,
    .empleados-stats,
    .empleados-tabla-search,
    .empleados-tabla-tools,
    .emp-acciones {
        display: none !important;
    }

    /* Botones de acciones rápidas (Nuevo Pedido, etc.) */
    body > div[style*="display:flex"][style*="justify-content:center"] {
        display: none !important;
    }

    /* Columna de acciones en Pedidos Urgentes */
    .urgentes-section .table th:last-child,
    .urgentes-section .table td:last-child {
        display: none !important;
    }

    /* ==========================================
       TOOLBAR (~42px)
    ========================================== */
    .md-toolbar {
        flex: 0 0 var(--tv-toolbar-h);
        height: var(--tv-toolbar-h);
        padding: 4px 12px;
        margin: 0;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .md-toolbar-brand img { height: 24px; }
    .md-toolbar-brand .brand-text { font-size: 15px; letter-spacing: 1.5px; }
    .md-toolbar-actions { gap: 8px; }
    .md-chip { padding: 3px 8px; font-size: 10px; }
    .md-chip i { font-size: 10px; }
    .realtime-indicator { font-size: 9px; padding: 2px 7px; gap: 4px; }
    .realtime-indicator::before { width: 5px; height: 5px; }

    /* ==========================================
       AVATARES (~145px)
    ========================================== */
    .empleados-section {
        flex: 0 0 var(--tv-avatars-h);
        padding: 6px 10px;
        margin: 0;
        border-radius: 8px;
        overflow: hidden;
    }
    .empleados-header {
        margin-bottom: 4px;
        padding-bottom: 3px;
        gap: 6px;
    }
    .empleados-title { font-size: 12px; gap: 5px; }
    .empleados-title i { font-size: 13px; }
    .total-badge {
        min-width: 18px;
        height: 18px;
        padding: 0 6px;
        font-size: 10px;
    }

    .empleados-avatar-grid {
        grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
        gap: 5px;
    }
    .empleado-avatar-card {
        padding: 4px 3px;
        gap: 1px;
        border-radius: 6px;
    }
    .avatar-circle {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    .avatar-name { font-size: 9px; }
    .empleado-cargo { font-size: 7px; }
    .avatar-badge {
        min-width: 15px;
        height: 15px;
        font-size: 8px;
        top: 2px;
        right: 2px;
        border-width: 1px;
    }
    .empleado-progress { height: 2px; margin-top: 1px; }

    /* ==========================================
       KPIs GENERALES (~145px)
    ========================================== */
    .md-grid {
        flex: 0 0 var(--tv-kpi-h);
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        margin: 0;
    }
    .md-card {
        padding: 8px 12px;
        border-radius: 8px;
    }
    .md-card::before { height: 2px; }
    .card-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
        margin-bottom: 4px;
        border-radius: 6px;
    }
    .card-label {
        font-size: 9px;
        letter-spacing: 0.2px;
        margin-bottom: 2px;
    }
    .card-value {
        font-size: 32px;
        margin-bottom: 2px;
    }
    .card-change { font-size: 9px; }

    /* ==========================================
       ZONA INFERIOR: Tabla KPI + Urgentes
    ========================================== */
    .empleados-tabla-section,
    .urgentes-section {
        position: fixed !important;
        bottom: var(--tv-padding);
        height: calc(100vh - var(--tv-toolbar-h) - var(--tv-avatars-h) - var(--tv-kpi-h) - 32px);
        max-height: none;
        padding: 6px 8px;
        margin: 0;
        border-radius: 8px;
        overflow: hidden;
        box-sizing: border-box;
        z-index: 5;
    }
    .empleados-tabla-section {
        left: 8px;
        width: calc(42% - 12px);
    }
    .urgentes-section {
        right: 8px;
        width: calc(58% - 12px);
    }

    /* ==========================================
       TABLA KPI POR EMPLEADO
    ========================================== */
    .empleados-tabla-header {
        margin-bottom: 4px;
        padding-bottom: 4px;
        gap: 5px;
    }
    .empleados-tabla-title { font-size: 11px; gap: 4px; }
    .empleados-tabla-title i { font-size: 12px; }
    .total-badge { font-size: 9px; min-width: 16px; height: 16px; }

    .empleados-tabla-wrapper {
        border-radius: 6px;
    }
    .empleados-tabla {
        font-size: 9px;
        table-layout: fixed;
    }
    .empleados-tabla thead th {
        padding: 3px 3px;
        font-size: 6.5px;
        letter-spacing: 0.2px;
    }
    .empleados-tabla td {
        padding: 3px 3px;
    }
    .empleados-tabla th.col-emp { width: 30%; }
    .empleados-tabla th.col-cargo { width: 18%; }
    .empleados-tabla th.col-num { width: 9%; }
    .empleados-tabla th.col-carga { width: 12%; }
    .empleados-tabla th.col-estado { width: 13%; }

    .emp-avatar {
        width: 16px;
        height: 16px;
        font-size: 7px;
    }
    .emp-cell { gap: 3px; }
    .emp-nombre { font-size: 8.5px; }
    .emp-cargo { font-size: 7px; }
    .emp-num {
        min-width: 14px;
        height: 13px;
        padding: 0 3px;
        font-size: 8px;
    }
    .emp-tasa-bar { width: 16px; height: 3px; }
    .emp-tasa-txt { font-size: 7.5px; min-width: 16px; }
    .emp-carga { width: 26px; height: 4px; }
    .emp-estado { font-size: 6.5px; padding: 1px 3px; }

    /* ==========================================
       PEDIDOS URGENTES
    ========================================== */
    .urgentes-section h3 {
        font-size: 11px;
        margin-bottom: 3px;
        gap: 5px;
    }
    .urgentes-section h3 i { font-size: 12px; }
    .urgentes-section .d-flex.justify-content-between {
        margin-bottom: 3px !important;
    }
    .urgentes-section .d-flex.justify-content-between > div:last-child {
        font-size: 8px;
    }
    #urgentes-count-badge {
        font-size: 8px;
        padding: 1px 5px;
    }

    .urgentes-section .table-responsive {
        border-radius: 6px;
    }
    .urgentes-section .table {
        font-size: 8.5px;
        table-layout: fixed;
        width: 100%;
    }
    .urgentes-section .table th {
        padding: 3px 3px;
        font-size: 6.5px;
        letter-spacing: 0.2px;
    }
    .urgentes-section .table td {
        padding: 3px 3px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .urgentes-section .table th:nth-child(1),
    .urgentes-section .table td:nth-child(1) { width: 5%; }
    .urgentes-section .table th:nth-child(2),
    .urgentes-section .table td:nth-child(2) { width: 12%; }
    .urgentes-section .table th:nth-child(3),
    .urgentes-section .table td:nth-child(3) { width: 22%; }
    .urgentes-section .table th:nth-child(4),
    .urgentes-section .table td:nth-child(4) { width: 15%; }
    .urgentes-section .table th:nth-child(5),
    .urgentes-section .table td:nth-child(5) { width: 10%; }
    .urgentes-section .table th:nth-child(6),
    .urgentes-section .table td:nth-child(6) { width: 9%; }
    .urgentes-section .table th:nth-child(7),
    .urgentes-section .table td:nth-child(7) { width: 9%; }
    .urgentes-section .table th:nth-child(8),
    .urgentes-section .table td:nth-child(8) { width: 9%; }
    .urgentes-section .table th:nth-child(9),
    .urgentes-section .table td:nth-child(9) { width: 9%; }

    .urgentes-section .md-badge {
        font-size: 7px;
        padding: 1px 4px;
    }
    .urgentes-section .d-flex.justify-content-between:last-child {
        font-size: 8px;
        margin-top: 2px;
    }

    /* Ocultar scrollbars en TV */
    .empleados-tabla-wrapper::-webkit-scrollbar,
    .urgentes-section .table-responsive::-webkit-scrollbar {
        display: none;
    }
    .empleados-tabla-wrapper,
    .urgentes-section .table-responsive {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    /* ==========================================
       MODALES COMPACTOS
    ========================================== */
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl { max-width: 600px; }
    .modal-content.md-modal-content { padding: 6px; border-radius: 8px; }
    .modal-header { padding: 5px 8px; }
    .modal-header .modal-title { font-size: 12px; }
    .modal-body { padding: 8px; font-size: 11px; }
    .modal-footer { padding: 5px 8px; gap: 5px; }

    .detail-card { padding: 5px; border-radius: 6px; margin-bottom: 4px; }
    .detail-card .detail-label { font-size: 9px; margin-bottom: 2px; }
    .detail-card .detail-value { font-size: 10px; }

    .md-btn { padding: 4px 10px; font-size: 10px; }
    .md-btn-sm { padding: 3px 6px; font-size: 9px; }

    .md-form-label { font-size: 10px; margin-bottom: 3px; }
    .md-form-control {
        padding: 5px 8px;
        font-size: 11px;
    }
}

/* ==========================================
   TV MUY BAJA (altura ≤ 700px)
========================================== */
@media (max-height: 700px) and (min-width: 1024px) {
    :root {
        --tv-toolbar-h: 38px;
        --tv-avatars-h: 125px;
        --tv-kpi-h: 125px;
        --tv-gap: 4px;
        --tv-padding: 4px;
    }
    .card-value { font-size: 26px !important; }
    .card-icon { width: 24px !important; height: 24px !important; font-size: 10px !important; }
    .avatar-circle { width: 32px !important; height: 32px !important; font-size: 11px !important; }
    .avatar-name { font-size: 8px !important; }
    .empleado-cargo { font-size: 6.5px !important; }
    .empleados-tabla { font-size: 8px !important; }
    .empleados-tabla thead th { font-size: 6px !important; }
    .urgentes-section .table { font-size: 8px !important; }
    .urgentes-section .table th { font-size: 6px !important; }
}

/* ==========================================
   TV EXTRA BAJA (altura ≤ 620px)
========================================== */
@media (max-height: 620px) and (min-width: 1024px) {
    :root {
        --tv-toolbar-h: 34px;
        --tv-avatars-h: 110px;
        --tv-kpi-h: 110px;
    }
    .card-value { font-size: 22px !important; }
    .avatar-circle { width: 28px !important; height: 28px !important; font-size: 10px !important; }
    .empleados-section { padding: 4px 8px !important; }
    .md-card { padding: 6px 8px !important; }
}

/* ==========================================
   REDUCIR MOVIMIENTO
========================================== */
@media (prefers-reduced-motion: reduce) {
    .md-card:hover,
    .empleado-avatar-card:hover,
    .empleado-avatar-card:hover .avatar-circle,
    .panel-highlight {
        animation: none;
        transform: none;
    }
}
