/* ============================================================
   Circuit Service - responsive.css
   Breakpoints: 1440 | 1200 | 1024 | 768 | 480 | 360
   ============================================================ */

/* ============================================================
   DESKTOP GRANDE (≥ 1440px)
   ============================================================ */
@media (min-width: 1440px) {
    .grid-4          { grid-template-columns: repeat(4, 1fr); }
    .dashboard-grid  { grid-template-columns: 2fr 1fr; }
}

/* ============================================================
   DESKTOP MEDIO (≤ 1439px)
   ============================================================ */
@media (max-width: 1439px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================================
   DESKTOP PEQUEÑO / LAPTOP (≤ 1200px)
   ============================================================ */
@media (max-width: 1200px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .grid-4         { grid-template-columns: repeat(2, 1fr); }
    .grid-3         { grid-template-columns: repeat(2, 1fr); }
    .stat-value     { font-size: 1.5rem; }
}

/* ============================================================
   TABLET / SMALL DESKTOP (≤ 1024px)
   Sidebar se oculta y se convierte en drawer
   ============================================================ */
@media (max-width: 1024px) {

    /* --- Sidebar como drawer deslizable --- */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        width: 260px !important; /* forzar ancho completo en mobile */
        z-index: 100;
        box-shadow: var(--shadow-lg);
        transition: transform 0.25s ease;
    }

    .sidebar.mobile-open  { transform: translateX(0); }

    /* Al estar collapsed pero abierto en mobile, mostrar completo */
    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
        width: 260px !important;
    }

    /* Siempre mostrar etiquetas de nav en mobile */
    .sidebar.collapsed .logo-text        { opacity: 1; width: auto; }
    .sidebar.collapsed .nav-link span    { opacity: 1; width: auto; }
    .sidebar.collapsed .nav-link         { justify-content: flex-start; padding: 10px 12px; gap: 12px; }
    .sidebar.collapsed .sidebar-version  { display: block; }
    .sidebar.collapsed .sidebar-toggle-btn { display: flex; }

    /* Overlay semitransparente detrás del drawer */


    /* El wrapper principal ocupa todo el ancho */
    .main-wrapper { margin-left: 0 !important; }

    /* --- Header --- */
    .header          { padding: 0 16px; gap: 10px; }
    .header-date     { display: none; }
    .menu-toggle-btn { display: flex; }
    .global-search-wrapper { max-width: none; flex: 1; }

    /* --- Contenido --- */
    .page-content { padding: 16px; }

    /* --- Modales más anchos --- */
    .modal-container,
    .modal-container.modal-lg,
    .modal-container.modal-xl,
    .modal-container.modal-sm { max-width: 96vw; }

    /* --- Grids --- */
    .grid-2 { grid-template-columns: 1fr 1fr; }

    /* --- Orden detalle: tabs fullwidth --- */
    .tabs-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ============================================================
   MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* ---- Layout general ---- */
    :root { --header-height: 60px; }

    .page-content { padding: 12px; }

    /* ---- Header ---- */
    .header { padding: 0 12px; gap: 8px; }
    .header-btn span { display: none; }
    .header-btn      { padding: 8px; }

    /* ---- Búsqueda global más pequeña ---- */
    .global-search { font-size: 0.82rem; }

    /* ---- Page header ---- */
    .page-header             { flex-direction: column; gap: 10px; }
    .page-header-actions     { width: 100%; flex-wrap: wrap; }
    .page-header-actions .btn { flex: 1; min-width: 140px; justify-content: center; }
    .page-header-info h1     { font-size: 1.25rem; }

    /* ---- Filters bar ---- */
    .filters-bar              { flex-direction: column; align-items: stretch; gap: 8px; }
    .search-input-wrapper     { max-width: none; }
    .filter-select            { width: 100%; }
    .results-count            { margin-left: 0; font-size: 0.78rem; }

    /* ---- Grids ---- */
    .grid-2    { grid-template-columns: 1fr; }
    .grid-3    { grid-template-columns: 1fr; }
    .grid-4    { grid-template-columns: repeat(2, 1fr); }
    .grid-auto { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }

    /* ---- Stats (Cuadrícula 2x2 elegante) ---- */
    .stat-card  { 
        padding: 12px; 
        gap: 8px; 
        flex-direction: column; 
        align-items: flex-start;
        text-align: left;
    }
    .stat-icon  { width: 36px; height: 36px; }
    .stat-icon svg { width: 18px; height: 18px; }
    .stat-value { font-size: 1.3rem; margin-top: 4px; line-height: 1; }
    .stat-label { font-size: 0.75rem; line-height: 1.2; white-space: normal; }

    /* ---- Cards ---- */
    .card { padding: 14px; }

    /* ---- Formularios ---- */
    .form-row.cols-2,
    .form-row.cols-3 { grid-template-columns: 1fr; }

    /* Inline grid en el formulario de cliente inline */
    #inlineClienteFormWrap [style*="grid-template-columns:1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
    }

    /* ---- Tablas → tarjetas en mobile ---- */
    .table-wrapper {
        border: none;
        box-shadow: none;
        background: transparent;
        border-radius: 0;
    }

    .table           { display: block; }
    .table thead     { display: none; }
    .table tbody     { display: flex; flex-direction: column; gap: 10px; }

    .table tr {
        display: flex;
        flex-direction: column;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px 14px;
        box-shadow: var(--shadow-sm);
    }

    .table td {
        display: flex;
        align-items: flex-start;
        gap: 8px;
        padding: 4px 0;
        border-top: none;
        font-size: 0.85rem;
        word-break: break-word;
    }

    /* Etiqueta automática desde data-label */
    .table td::before {
        content: attr(data-label);
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        min-width: 90px;
        flex-shrink: 0;
        padding-top: 3px;
    }

    .table td.no-label::before { display: none; }

    .table td.actions {
        justify-content: flex-end;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--border);
    }
    .table td.actions::before { display: none; }

    .table-actions { flex-wrap: wrap; gap: 4px; justify-content: flex-end; }

    /* ---- Modal ---- */
    .modal-header { padding: 14px 16px; }
    .modal-body   { padding: 14px 16px; }
    .modal-footer {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .modal-footer .btn { flex: 1; min-width: 100px; justify-content: center; }

    /* ---- Modal de presupuesto — tabla de ítems ---- */
    .presupuesto-items-table           { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .presupuesto-items-table thead th  { white-space: nowrap; }
    .presupuesto-totales               { align-items: stretch; }
    .presupuesto-total-row             { min-width: 0; width: 100%; }

    /* ---- Pagos summary ---- */
    .pagos-summary { grid-template-columns: 1fr; }

    /* ---- Garantías ---- */
    .garantia-status { font-size: 0.72rem; padding: 3px 8px; }

    /* ---- Seguimiento ---- */
    .seguimiento-info-grid { grid-template-columns: 1fr; }
    .seguimiento-header    { padding: 18px 16px; }
    .seguimiento-header h2 { font-size: 1.1rem; }
    .seguimiento-body      { padding: 16px; }

    /* Fila de búsqueda de seguimiento */
    .seguimiento-search > div { flex-direction: column; }
    .seguimiento-search .btn  { width: 100%; justify-content: center; }

    /* ---- Progress steps (orden detalle) ---- */
    .progress-steps {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 12px;
        gap: 0;
    }
    .progress-step  { min-width: 58px; }
    .step-dot       { width: 24px; height: 24px; font-size: 0.68rem; }
    .step-label     { font-size: 0.6rem; }

    /* ---- Tabs ---- */
    .tabs-nav  { overflow-x: auto; -webkit-overflow-scrolling: touch; border-bottom-width: 1px; }
    .tab-btn   { white-space: nowrap; padding: 10px 12px; font-size: 0.8rem; }

    /* ---- Timeline / historial ---- */
    .timeline-text { font-size: 0.82rem; }
    .timeline-time { font-size: 0.7rem; }

    /* ---- Confirm dialog ---- */
    .confirm-dialog      { width: 92vw; padding: 22px 16px; }
    .confirm-actions     { flex-direction: column; gap: 8px; }
    .confirm-actions .btn { width: 100%; justify-content: center; }

    /* ---- Toast ---- */
    .toast-container { left: 12px; right: 12px; bottom: 12px; }
    .toast           { max-width: none; min-width: 0; }

    /* ---- Cliente dropdown (orden) ---- */
    /* El botón "Nuevo cliente" va debajo del buscador */
    #clienteFormGroup > div:first-of-type {
        flex-direction: column;
    }
    #btnCrearClienteInline { width: 100%; justify-content: center; }

    /* ---- Ficha de cliente ---- */
    .ficha-header { flex-direction: column; align-items: center; text-align: center; }
    .ficha-meta   { justify-content: center; }

    /* ---- Orden detalle: info grid ---- */
    /* Los dos cards laterales se apilan */
    .page-content .grid-2 { grid-template-columns: 1fr; }

    /* ---- Recepción card ---- */
    #btnIniciarRecepcion { padding: 12px; font-size: 0.875rem; }

    /* ---- Inventario: botones de stock ---- */
    .table-actions .btn { padding: 5px 8px; font-size: 0.75rem; }
    /* ---- Recent items (Dashboard lists) ---- */
    .recent-item { flex-wrap: wrap !important; padding: 12px 0; gap: 8px; }
    .recent-item-icon { width: 34px; height: 34px; }
    .recent-item-icon svg { width: 16px; height: 16px; }
    
    .recent-item-info { flex: 1 1 calc(100% - 45px) !important; min-width: 0; }
    .recent-item-info .title { font-size: 0.85rem; }
    .recent-item-info .subtitle { font-size: 0.75rem; }
    
    .recent-item-meta {
        width: 100% !important;
        text-align: left !important;
        display: flex !important;
        align-items: center;
        gap: 8px;
        padding-left: 42px; /* icon width + gap */
        margin-top: -4px;
        justify-content: flex-start;
    }
}

/* ============================================================
   MOBILE PEQUEÑO (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
    :root { --header-height: 54px; }

    .page-content { padding: 10px; }

    /* ---- Header mínimo ---- */
    .header { padding: 0 10px; }
    .menu-toggle-btn { width: 32px; height: 32px; }
    .global-search   { padding-left: 30px; font-size: 0.8rem; }

    /* ---- Stat cards en grid de 2 ---- */
    .grid-4    { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 10px; gap: 6px; }
    .stat-value { font-size: 1.15rem; }

    /* ---- Cards ---- */
    .card { padding: 12px; }

    /* ---- Botones más compactos ---- */
    .btn      { padding: 8px 12px; font-size: 0.82rem; }
    .btn-sm   { padding: 5px 10px; font-size: 0.75rem; }

    /* ---- Modal: más compacto ---- */
    .modal-header { padding: 12px 14px; }
    .modal-body   { padding: 12px 14px; }
    .modal-footer { padding: 10px 14px; }
    .modal-title  { font-size: 1rem; }

    /* ---- Confirm ---- */
    .confirm-dialog { width: 98vw; padding: 18px 14px; }
    .confirm-icon   { width: 46px; height: 46px; }
    .confirm-title  { font-size: 1rem; }

    /* ---- Formularios ---- */
    .form-control   { padding: 8px 10px; font-size: 0.85rem; }
    .form-label     { font-size: 0.75rem; }
    .form-section-title { font-size: 0.72rem; }

    /* ---- Tabs aún más compactos ---- */
    .tab-btn { padding: 8px 10px; font-size: 0.75rem; }

    /* ---- Dropdown cliente ---- */
    .cliente-dropdown { max-height: 200px; }
    .cd-item          { padding: 8px 12px; }
    .cd-item-name     { font-size: 0.82rem; }
    .cd-item-meta     { font-size: 0.7rem; }

    /* ---- Toast chico ---- */
    .toast        { padding: 10px 12px; }
    .toast-title  { font-size: 0.82rem; }
    .toast-message { font-size: 0.75rem; }

    /* ---- Presupuesto totales ---- */
    .presupuesto-total-row { gap: 16px; }
    .presupuesto-total-row.total-final strong { font-size: 1rem; }

    /* ---- Pagos summary ---- */
    .pago-summary-card .amount { font-size: 1rem; }

    /* ---- Progress steps muy pequeños ---- */
    .progress-step  { min-width: 50px; }
    .step-dot       { width: 20px; height: 20px; font-size: 0.6rem; }
    .step-label     { font-size: 0.55rem; }



    /* ---- Sidebar ajuste ---- */
    .sidebar { width: 240px !important; }
}

/* ============================================================
   MOBILE MUY PEQUEÑO (≤ 360px)
   ============================================================ */
@media (max-width: 360px) {
    :root { --header-height: 50px; }

    .page-content { padding: 8px; }
    .card         { padding: 10px; }

    .stat-value   { font-size: 1.1rem; }
    .stat-icon    { width: 36px; height: 36px; }

    .btn          { padding: 7px 10px; font-size: 0.8rem; }
    .btn-sm       { padding: 4px 8px;  font-size: 0.72rem; }

    .modal-header { padding: 10px 12px; }
    .modal-body   { padding: 10px 12px; }
    .modal-footer { padding: 8px 12px; }

    .sidebar { width: 220px !important; }
    .global-search { font-size: 0.78rem; }

    .table td { font-size: 0.8rem; }
    .table td::before { min-width: 78px; font-size: 0.65rem; }
}

/* ============================================================
   RETINA / HIGH DPI
   ============================================================ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .sidebar { border-right-width: 0.5px; }
    .header  { border-bottom-width: 0.5px; }
    .border  { border-width: 0.5px; }
}

/* ============================================================
   LANDSCAPE MOBILE (altura < 500px, horizontal)
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar { overflow-y: auto; }

    /* Modal más compacto en landscape */
    .modal-container {
        max-height: 96dvh;
        width: 96vw;
    }
    .modal-body { max-height: 55vh; }

    /* Confirm dialog más pequeño */
    .confirm-dialog { padding: 16px; }
    .confirm-icon   { display: none; }

    .page-content { padding: 10px; }
}

/* ============================================================
   MOVIMIENTO REDUCIDO
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   MODO OSCURO (preparado para futuro)
   ============================================================ */
/*
@media (prefers-color-scheme: dark) {
    :root {
        --primary:        #3b82f6;
        --primary-dark:   #2563eb;
        --primary-light:  #1e3a5f;
        --background:     #0f172a;
        --surface:        #1e293b;
        --surface-2:      #162032;
        --border:         #334155;
        --border-strong:  #475569;
        --text:           #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted:     #64748b;
        --success-light:  #14532d;
        --warning-light:  #78350f;
        --danger-light:   #7f1d1d;
        --info-light:     #164e63;
        --primary-light:  #1e3a5f;
        --purple-light:   #2e1065;
        --orange-light:   #431407;
    }
}
*/

/* ============================================================
   IMPRESIÓN
   ============================================================ */
@media print {
    @page { margin: 0; size: auto; }

    body { background: white; margin: 0; padding: 0; }

    /* Ocultar toda la UI — solo dejar los tickets */
    #sidebar,
    #sidebarOverlay,
    #mainWrapper,
    #modalContainer,
    #confirmBackdrop,
    .toast-container { display: none !important; }

    /* Mostrar solo los tickets */
    #printTemplate { display: block !important; }
}
