/* ============================================
   PREMIUM TABLE STYLES (Desktop Tracking)
   ============================================ */
.badge-status-premium {
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 11px;
    display: inline-block;
    background: var(--bg-status, #94a3b8);
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    white-space: nowrap;
}

.badge-type-premium {
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 10px;
    margin-right: 5px;
    display: inline-block;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.badge-type-premium.chip { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.badge-type-premium.fibra { background: linear-gradient(135deg, #e11d48, #be123c); }

.desktop-actions-grid {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
}

.btn-action-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    font-size: 13px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.btn-action-circle.wa { background: #22c55e; color: white; }
.btn-action-circle.call { background: #00549A; color: white; }
.btn-action-circle.edit { background: #ffffff; color: #475569; border: 1px solid #e2e8f0; }
.btn-action-circle.history { background: #ffffff; color: #475569; border: 1px solid #e2e8f0; }
.btn-action-circle.delete { background: #fee2e2; color: #ef4444; border: 1px solid #fecaca; }

.btn-action-circle:hover {
    transform: translateY(-3px) scale(1.1);
    box-shadow: 0 5px 12px rgba(0,0,0,0.15);
}

/* Ocultar elementos móviles en Escritorio */
@media (min-width: 769px) {
    .mob-quick-actions, .mob-edit-actions { display: none !important; }
}

/* Ocultar elementos de escritorio en Móvil */
@media (max-width: 768px) {
    .desktop-actions-grid { display: none !important; }
    .badge-status-premium, .badge-type-premium { font-size: 11px; padding: 4px 10px; }
}

/* ============================================
   BOTÓN REGRESAR MÓVIL (TIPO APP)
   ============================================ */
.mobile-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: #FFFFFF !important;
    cursor: pointer;
    margin-right: 0.5rem;
    padding: 0;
    transition: all 0.2s ease;
    z-index: 1001;
}

.mobile-back-btn:active {
    transform: scale(0.9);
    opacity: 0.7;
}

/* Ajuste para tema claro si la barra superior cambia */
[data-theme="light"] .mobile-back-btn {
    color: #1e293b !important;
}

/* El estado de visualización se controla vía JS showView */

/* ============================================
   MOBILE RESPONSIVE - Admin Dashboard
   Implementación completa de 6 fases
   ============================================ */

/* ============================================
   FASE 1: SIDEBAR MOBILE
   ============================================ */

/* Overlay para cerrar sidebar */
.sidebar-overlay,
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active,
#sidebarOverlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {

    /* Sidebar oculto por defecto en mobile */
    .sidebar {
        position: fixed !important;
        left: -280px !important;
        top: 0 !important;
        height: 100vh !important;
        width: 280px !important;
        transition: left 0.3s ease !important;
        z-index: 999 !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.mobile-active,
    .sidebar.active {
        left: 0 !important;
        transform: translateX(0) !important;
    }

    /* Botón hamburger visible */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: none;
        border: none;
        font-size: 1.5rem;
        color: var(--text-primary, #1f2937);
        cursor: pointer;
        padding: 0;
        margin-right: 1rem;
    }

    /* Main content ocupa todo el ancho */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 0;
    }

    /* Top bar ajustado */
    .top-bar {
        padding-left: 1rem;
    }
}

/* Desktop: ocultar botón hamburger */
@media (min-width: 769px) {
    .mobile-menu-btn {
        display: none !important;
    }
}

/* ============================================
   FASE 2: TABLAS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {

    /* Card layout para tablas */
    .data-table {
        display: block;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody {
        display: block;
    }

    .data-table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border-light, var(--border-light));
        border-radius: 12px;
        padding: 1rem;
        background: var(--bg-card, white);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        height: auto !important;
        min-height: auto !important;
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 0.75rem 0;
        border-bottom: 1px solid var(--border-light, var(--border-light));
        font-size: 14px;
        color: var(--text-primary, #1f2937);
        /* Text overflow control */
        word-break: break-word;
        overflow-wrap: anywhere;
        hyphens: auto;
        max-width: 100%;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        white-space: normal !important;
    }

    /* Value content should wrap properly */
    .data-table td>*:not(:first-child),
    .data-table td:not(:empty)::after {
        flex: 1;
        text-align: right;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .data-table td:last-child {
        border-bottom: none;
    }

    /* Label antes del valor */
    .data-table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted, #6b7280);
        flex: 0 0 40%;
        padding-right: 1rem;
    }

    /* Acciones al final */
    .data-table td.actions {
        justify-content: flex-end;
        gap: 0.5rem;
    }

    .data-table td.actions:before {
        display: none;
    }

    /* Fallback: scroll horizontal */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Para tablas que no usen card layout */
    .table-scroll-mobile {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-scroll-mobile table {
        min-width: 600px;
    }

    /* --- BARRA DE FILTROS DASHBOARD --- */
    .filters-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        background: #f8fafc !important;
        padding: 15px !important;
        border-radius: 12px !important;
        margin-bottom: 25px !important;
    }

    .filters-bar .filter-group {
        width: 100% !important;
        margin: 0 !important;
        position: relative !important;
    }

    .filters-bar .search-box i {
        position: absolute !important;
        left: 12px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        color: #94a3b8 !important;
        z-index: 2 !important;
    }

    .filters-bar .search-box input {
        padding-left: 40px !important;
        height: 48px !important;
        border-radius: 10px !important;
        border: 1px solid #cbd5e1 !important;
        width: 100% !important;
        font-size: 1rem !important;
    }

    .filters-bar select,
    .filters-bar input[type="date"] {
        height: 48px !important;
        border-radius: 10px !important;
        border: 1px solid #cbd5e1 !important;
        width: 100% !important;
        padding: 0 10px !important;
        background: white !important;
        font-size: 1rem !important;
    }

    /* Ocultar filtros extra y botones en Seguimiento (APP/Mobile) */
    #view-seguimiento .section-header div:has(button), 
    #view-seguimiento .section-header .btn-secondary, 
    #view-seguimiento .section-header .btn-refresh,
    #btnPapeleraSeguimiento {
        display: none !important;
    }

    #view-seguimiento .filters-bar .filter-group:not(.search-box) {
        display: none !important;
    }

    /* --- TARJETA DE SEGUIMIENTO DEFINITIVA (ALTA PRIORIDAD) --- */
    body #view-seguimiento .data-table tbody tr {
        display: block !important;
        background: #ffffff !important;
        border-radius: 12px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
        padding: 1.25rem !important;
        margin-bottom: 2rem !important;
        border-left: 10px solid #00549A !important;
        border-top: 1px solid #e2e8f0 !important;
        border-right: 1px solid #e2e8f0 !important;
        border-bottom: 1px solid #e2e8f0 !important;
        position: relative !important;
        width: auto !important;
        max-width: 100% !important;
    }

    body #view-seguimiento .data-table tbody tr td {
        display: block !important;
        width: 100% !important;
        padding: 0.5rem 0 !important;
        border: none !important;
        text-align: left !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        min-height: auto !important;
        margin: 0 !important;
    }

    /* Ocultación de campos irrelevantes */
    body #view-seguimiento .data-table tbody tr td.mob-hide {
        display: none !important;
    }

    /* Eliminar antes/etiquetas por defecto */
    body #view-seguimiento .data-table tbody tr td:before { display: none !important; }

    /* 1. Nombre del Cliente (Cabecera Principal) */
    body #view-seguimiento .data-table tbody tr td.mob-title-row {
        font-size: 1.5rem !important;
        color: #00549A !important;
        font-weight: 950 !important;
        line-height: 1.1 !important;
        margin-top: 0 !important;
        text-transform: uppercase !important;
        display: block !important;
        background: transparent !important;
    }

    /* 2. DNI */
    body #view-seguimiento .data-table tbody tr td.mob-dni-row {
        color: #475569 !important;
        font-size: 1.2rem !important;
        font-weight: 700 !important;
        margin-bottom: 0.5rem !important;
        display: block !important;
    }

    /* 3. Badges */
    body #view-seguimiento .data-table tbody tr td.mob-badges-row {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
        margin: 0.5rem 0 !important;
        padding: 0.75rem 0.5rem !important;
        border-top: 1px solid #f1f5f9 !important;
        border-bottom: 1px solid #f1f5f9 !important;
        background: #f8fafc !important;
        border-radius: 8px !important;
    }

    /* 4. ID / Orden (Caja Destacada) */
    body #view-seguimiento .data-table tbody tr td.mob-id-row {
        background: #f8fafc !important;
        padding: 15px !important;
        border-radius: 12px !important;
        border: 1px solid #e2e8f0 !important;
        margin: 1rem 0 !important;
        display: block !important;
    }
    body #view-seguimiento .data-table tbody tr td.mob-id-row:before {
        display: inline-block !important;
        content: attr(data-label) ": " !important;
        font-weight: 900 !important;
        color: #0f172a !important;
        margin-right: 8px !important;
    }

    /* 5. Comentarios */
    body #view-seguimiento .data-table tbody tr td.mob-comments-row {
        background: #fff !important;
        border: 1px dashed #94a3b8 !important;
        padding: 15px !important;
        border-radius: 12px !important;
        margin-bottom: 1rem !important;
        display: block !important;
    }
    body #view-seguimiento .data-table tbody tr td.mob-comments-row:before {
        content: "Comentarios de Gestión:" !important;
        display: block !important;
        font-weight: 900 !important;
        color: #0f172a !important;
        margin-bottom: 8px !important;
        font-size: 0.9rem !important;
    }

    /* 6. Botones final de tarjeta (Acciones Reales) */
    body #view-seguimiento .data-table tbody tr td.mob-actions-row {
        display: block !important;
        margin-top: 1.5rem !important;
        padding-top: 1.5rem !important;
        border-top: 3px solid #00549A !important;
    }

    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-quick-actions {
        display: flex !important;
        gap: 12px !important;
        width: 100% !important;
        margin-bottom: 1.25rem !important;
    }

    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-btn-wa,
    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-btn-call {
        flex: 1 !important;
        height: 62px !important;
        border-radius: 16px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 12px !important;
        color: #fff !important;
        text-decoration: none !important;
        font-weight: 900 !important;
        font-size: 1.1rem !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
    }

    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-btn-wa { background: #128c7e !important; }
    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-btn-call { background: #00549a !important; }

    body #view-seguimiento .data-table tbody tr td.mob-actions-row .mob-edit-actions {
        display: flex !important;
        justify-content: space-around !important;
        padding: 0 20px !important;
    }
}

/* Fix Filters Bar mobile */
@media (max-width: 768px) {
    .filters-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }
    .filters-bar .filter-group {
        width: 100% !important;
        margin: 0 !important;
    }
    .filters-bar .search-box i {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
    }
    .filters-bar .search-box input {
        padding-left: 35px !important;
    }
}

/* ============================================
   FASE 3: MODALES FULLSCREEN
   ============================================ */

@media (max-width: 768px) {

    /* Modal fullscreen en mobile */
    .modal {
        padding: 0;
    }

    .modal-card {
        width: 100vw;
        height: 100vh;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        flex-shrink: 0;
        padding: 1.25rem 1rem;
        border-bottom: 1px solid var(--border-light);
    }

    .modal-header h3 {
        font-size: 1.125rem;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        padding: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer,
    .modal-actions {
        flex-shrink: 0;
        padding: 1rem;
        border-top: 1px solid var(--border-light);
    }

    /* Botones en modal fullwidth */
    .modal-footer button,
    .modal-actions button {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .modal-footer button:last-child,
    .modal-actions button:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   FASE 4: KPI GRID RESPONSIVE
   ============================================ */

.kpi-grid,
.stats-grid,
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

/* Tablet: 2 columnas */
@media (max-width: 1024px) and (min-width: 641px) {

    .kpi-grid,
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: 1 columna */
@media (max-width: 640px) {

    .kpi-grid,
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    /* KPI Cards más compactos */
    .kpi-card,
    .stat-card {
        padding: 1rem;
    }

    .kpi-card h3,
    .stat-card h3 {
        font-size: 0.875rem;
    }

    .kpi-card .value,
    .stat-card .value {
        font-size: 1.5rem;
    }
}

/* ============================================
   FASE 5: TOUCH TARGETS & TYPOGRAPHY
   ============================================ */

@media (max-width: 768px) {

    /* Aumentar font-size base (previene zoom en iOS) */
    body {
        font-size: 16px;
    }

    /* Touch targets mínimo 44x44px */
    button,
    .btn,
    a.clickable,
    .action-icon,
    .icon-button {
        min-width: 44px;
        min-height: 44px;
        padding: 12px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Inputs táctiles */
    input,
    select,
    textarea,
    .form-control {
        font-size: 16px;
        min-height: 44px;
        padding: 12px;
    }

    /* Botones en formularios */
    .form-actions button,
    .btn-primary,
    .btn-secondary {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
        margin-bottom: 0.75rem;
    }

    /* Aumentar espaciado entre elementos */
    .form-group {
        margin-bottom: 1.25rem;
    }

    /* Labels más grandes */
    label {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Checkboxes y radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 0.75rem;
    }

    /* Tabs más grandes */
    .tabs button,
    .tab-button {
        min-height: 48px;
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* ============================================
   FASE 6: CHAT MOBILE
   ============================================ */

/* ============================================
   FASE 6: CHAT MOBILE
   ============================================ */

@media (max-width: 768px) {
    /* Chat styles handled by chat_v2.css now */
}

/* ============================================
   MEJORAS ADICIONALES
   ============================================ */

@media (max-width: 768px) {

    /* Padding general reducido */
    .container,
    .main-container {
        padding: 1rem;
    }

    /* Headers más compactos */
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.125rem;
    }

    /* Top bar más compacto */
    .top-bar {
        padding: 0.75rem 1rem;
        min-height: 60px;
    }

    /* User info oculto en mobile muy pequeño */
    @media (max-width: 480px) {
        .user-info .user-details {
            display: none;
        }
    }

    /* Action columns en tablas */
    .table-actions {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .table-actions button {
        flex: 1;
        min-width: 80px;
    }

    /* Filtros stack vertical */
    .filters,
    .filter-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-group>* {
        width: 100%;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .pagination button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Dropdowns fullwidth */
    select,
    .select-container {
        width: 100%;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {

    /* Chat más bajo en landscape */
    .chat-sidebar,
    #chatSidebar {
        height: 50vh;
        max-height: 50vh;
    }

    /* Modales scroll más eficiente */
    .modal-body {
        max-height: calc(100vh - 120px);
    }
}

/* ============================================
   SAFE AREAS (iOS notch, etc)
   ============================================ */

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .sidebar {
            padding-top: max(1rem, env(safe-area-inset-top));
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }

        .chat-sidebar,
        #chatSidebar {
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }

        .modal-card {
            padding-top: max(0px, env(safe-area-inset-top));
            padding-bottom: max(0px, env(safe-area-inset-bottom));
        }
    }
}

/* ============================================
   ANIMATIONS & TRANSITIONS
   ============================================ */

/* Smooth transitions */
.sidebar,
.chat-sidebar,
.mobile-overlay,
.modal-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reducir motion para accesibilidad */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   TEXT OVERFLOW FIX FOR MOBILE
   ============================================ */
@media (max-width: 768px) {

    /* Fix text overflow in table cells */
    .data-table td,
    .data-table th {
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        hyphens: auto !important;
        max-width: 100% !important;
    }

    /* Fix long names/text in cards */
    .kpi-card,
    .chart-card,
    .profile-content-card {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Ensure container doesn't overflow */
    .table-container,
    .view-section,
    .main-content {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Fix select dropdowns */
    select,
    .status-select {
        max-width: 100% !important;
        text-overflow: ellipsis;
    }
}

/* ============================================
   FIX FOOTER SPACING (User Request)
   ============================================ */
@media (max-width: 768px) {

    /* 1. Container Padding: Moves EVERYTHING (text + box) away from edge */
    .footer-col {
        padding: 0 1.5rem !important;
    }

    /* 2. Box Alignment: Remove horizontal margin so it aligns with text */
    .capture-box {
        margin: 1.5rem 0 !important;
        /* Vertical spacing only */
        width: 100% !important;
        /* Fill the container */
    }

    /* 3. Form Layout: Stack Input and Button vertically for better UX */
    .footer-form {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .footer-form input,
    .footer-form button {
        width: 100% !important;
        height: 48px;
        /* Better touch target */
    }
}