/* ==========================================================================
   COTIZAPY — MOBILE-FIRST UX OVERHAUL (<= 768px ONLY)
   100% aislado del escritorio (> 768px). Soporta Modo Claro y Modo Oscuro.
   ========================================================================== */

/* Helpers ocultos en escritorio */
.mobile-sheet-hdr,
.bab-mobile-launcher,
.os-mobile-backdrop,
.abcb-label-short {
  display: none;
}

.os-mm-section,
.os-mm-section-label,
.os-mm-prefs-grid,
.os-mm-pref-btn,
.os-mm-currency {
  box-sizing: border-box;
}

@keyframes mobFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes mobSheetUp {
  from {
    opacity: 0;
    transform: translateY(28px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   EXPERIENCIA MÓVIL COMPLETA (<= 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {
  :root {
    --os-mobile-strip-h: calc(54px + env(safe-area-inset-top, 0px));
    --os-mobile-tb-h: calc(62px + env(safe-area-inset-bottom, 0px));
  }

  /* ------------------------------------------------------------------------
     1. SHELL MÓVIL LIMPIO (SIN DOBLE CABECERA NI WALLPAPER DE ESCRITORIO)
     ------------------------------------------------------------------------ */
  #osDesktop,
  .os-desktop,
  .os-win-titlebar {
    display: none !important;
  }

  html,
  body.os-body {
    background: var(--bg-page) !important;
    overflow: hidden !important;
  }

  .os-window-stage.main-content {
    position: fixed !important;
    inset: var(--os-mobile-strip-h) 0 var(--os-mobile-tb-h) 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: auto !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }

  .os-window.tab-panel {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: auto !important;
    background: var(--bg-page) !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: none !important;
    will-change: auto !important;
  }

  .os-win-body {
    padding: 0.65rem 0.7rem 1.5rem !important;
    overflow-y: auto !important;
    overflow-x: clip !important;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-page) !important;
  }

  /* Evitar auto-zoom en iOS al enfocar campos principales */
  .input-control,
  .select-control,
  .input-search,
  .btf-search-input,
  .btf-chapter-select,
  .obras-select,
  .obras-field input,
  .obras-field select,
  .obras-field textarea,
  .explosion-order-bar select,
  .os-start-search-input {
    font-size: 16px !important;
  }

  /* ------------------------------------------------------------------------
     2. BARRA SUPERIOR ÚNICA (RESUMEN EN VIVO + 2 BOTONES CÓMODOS PDF / WA)
     ------------------------------------------------------------------------ */
  .os-mobile-status-strip {
    height: var(--os-mobile-strip-h) !important;
    padding: env(safe-area-inset-top, 0px) 10px 0 !important;
    gap: 8px !important;
    z-index: 480 !important;
    background: var(--os-acrylic-strong) !important;
    border-bottom: 1px solid var(--os-border) !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06) !important;
  }

  .os-mob-brand-pill {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    gap: 8px !important;
    padding: 4px 2px !important;
    border-radius: 10px;
  }

  .os-mob-brand-dot {
    width: 26px !important;
    height: 26px !important;
  }

  .os-mob-brand-dot svg {
    width: 26px !important;
    height: 26px !important;
  }

  .os-mob-budget-meta {
    min-width: 0 !important;
    overflow: hidden;
  }

  .os-mob-m2 {
    font-size: 0.62rem !important;
    letter-spacing: 0.06em !important;
    line-height: 1.15 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .os-mob-total {
    font-size: clamp(0.86rem, 3.9vw, 0.98rem) !important;
    font-weight: 700 !important;
    line-height: 1.2 !important;
    color: var(--os-accent) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .os-mob-quick-btns {
    gap: 6px !important;
    flex-shrink: 0 !important;
  }

  .os-mob-pill-btn {
    min-height: 36px !important;
    min-width: 50px !important;
    padding: 0 12px !important;
    border-radius: 9px !important;
    font-size: 0.78rem !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    transition: transform 0.1s ease, background-color 0.15s ease;
  }

  .os-mob-pill-btn:active {
    transform: scale(0.95);
  }

  .os-mob-pill-btn.os-mob-pill-wa {
    background: rgba(16, 185, 129, 0.1) !important;
    border-color: rgba(5, 150, 105, 0.35) !important;
    color: #047857 !important;
  }

  html[data-os-theme="dark"] .os-mob-pill-btn.os-mob-pill-wa {
    background: rgba(16, 185, 129, 0.16) !important;
    border-color: rgba(52, 211, 153, 0.4) !important;
    color: #6ee7b7 !important;
  }

  /* ------------------------------------------------------------------------
     3. BARRA INFERIOR NATIVA (CORRIGE COLISIÓN .nav-tab + SAFE-AREA)
     ------------------------------------------------------------------------ */
  .os-taskbar {
    height: var(--os-mobile-tb-h) !important;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px)) !important;
    display: flex !important;
    align-items: stretch !important;
    background: var(--os-acrylic-strong) !important;
    border-top: 1px solid var(--os-border) !important;
    box-shadow: 0 -2px 14px rgba(15, 23, 42, 0.08) !important;
    z-index: 500 !important;
  }

  .os-tb-center {
    display: flex !important;
    align-items: stretch !important;
    justify-content: space-between !important;
    gap: 2px !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Mantener estrictamente ocultos los botones solo-escritorio y Admin cuando está bloqueado */
  .os-taskbar .os-tb-desktop-only,
  .os-taskbar .os-tb-app.os-tb-desktop-only,
  .os-taskbar #navTabAdmin[style*="display: none"],
  .os-taskbar #navTabAdmin[style*="display:none"] {
    display: none !important;
  }

  /* Resetear por completo herencia de .nav-tab de styles.css solo en tabs móviles visibles */
  .os-taskbar .os-tb-app:not(.os-tb-desktop-only):not([style*="display: none"]):not([style*="display:none"]),
  .os-taskbar .os-tb-app.nav-tab:not(.os-tb-desktop-only):not([style*="display: none"]):not([style*="display:none"]) {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    width: auto !important;
    height: 52px !important;
    min-height: 52px !important;
    padding: 3px 2px !important;
    margin: 0 !important;
    border: none !important;
    border-bottom: none !important;
    border-radius: 10px !important;
    background: transparent !important;
    color: var(--os-text-muted) !important;
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    position: relative !important;
    anchor-name: none !important;
    box-shadow: none !important;
  }

  .os-taskbar .os-tb-app:hover,
  .os-taskbar .os-tb-app.nav-tab:hover {
    background: transparent !important;
    border: none !important;
  }

  .os-taskbar .os-tb-app.active,
  .os-taskbar .os-tb-app.nav-tab.active,
  .os-taskbar .os-tb-app.os-app-focused,
  .os-taskbar .os-tb-app[aria-expanded="true"] {
    background: transparent !important;
    border: none !important;
    border-bottom: none !important;
    color: var(--os-accent) !important;
  }

  .os-taskbar .os-tb-app-icon {
    width: 46px !important;
    height: 28px !important;
    border-radius: 999px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background-color 0.16s ease, transform 0.14s ease !important;
  }

  .os-taskbar .os-tb-app-icon svg {
    width: 21px !important;
    height: 21px !important;
  }

  .os-taskbar .os-tb-app.active .os-tb-app-icon,
  .os-taskbar .os-tb-app.nav-tab.active .os-tb-app-icon,
  .os-taskbar .os-tb-app.os-app-focused .os-tb-app-icon,
  .os-taskbar .os-tb-app[aria-expanded="true"] .os-tb-app-icon {
    background: var(--os-accent-soft) !important;
  }

  .os-taskbar .os-tb-indicator {
    display: none !important;
  }

  .os-taskbar .os-tb-app-label {
    display: block !important;
    font-size: 0.65rem !important;
    font-weight: 600 !important;
    line-height: 1.1 !important;
    color: inherit !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .os-taskbar .os-tb-notif-badge {
    top: 2px !important;
    right: calc(50% - 24px) !important;
    min-width: 16px !important;
    height: 16px !important;
    font-size: 0.6rem !important;
  }

  /* ------------------------------------------------------------------------
     4. BACKDROP Y BOTTOM SHEETS NATIVOS (MÁS, BUSCADOR, ⋯ Y HERRAMIENTAS)
     ------------------------------------------------------------------------ */
  .os-mobile-backdrop {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 580 !important;
    background: rgba(2, 6, 23, 0.52) !important;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: mobFadeIn 0.16s ease;
  }

  .os-mobile-backdrop[hidden] {
    display: none !important;
  }

  .mobile-sheet-grabber {
    display: block !important;
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--border-strong);
    opacity: 0.25;
    margin: 0 auto 8px;
    flex-shrink: 0;
  }

  .mobile-sheet-hdr {
    display: flex !important;
    flex-direction: column;
    padding-bottom: 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
  }

  .mobile-sheet-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-sheet-title-row strong {
    font-size: 0.94rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  /* Todos los flyouts y dropdowns contextuales se vuelven Bottom Sheets limpios */
  .os-flyout,
  .os-mobile-more-sheet,
  .os-start-menu,
  .os-widgets-panel,
  .os-control-center,
  .budget-more-dropdown,
  .planilla-tools-dropdown {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    transform: none !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    border: 1px solid var(--os-border-strong) !important;
    border-bottom: none !important;
    background: var(--bg-surface) !important;
    z-index: 620 !important;
    max-height: 84dvh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 10px 14px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    box-shadow: 0 -12px 40px rgba(2, 6, 23, 0.3) !important;
    animation: mobSheetUp 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  .os-flyout[hidden],
  .budget-more-dropdown[hidden],
  .planilla-tools-dropdown[hidden] {
    display: none !important;
  }

  /* Filas táctiles cómodas en menús contextuales (respetando ítems ocultos por estado) */
  .budget-more-dropdown .bmd-item:not([style*="display:none"]):not([style*="display: none"]),
  .planilla-tools-dropdown .bmd-item:not([style*="display:none"]):not([style*="display: none"]) {
    min-height: 44px !important;
    padding: 10px 12px !important;
    font-size: 0.88rem !important;
    border-radius: 10px !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .budget-more-dropdown .bmd-item[style*="display:none"],
  .budget-more-dropdown .bmd-item[style*="display: none"],
  .planilla-tools-dropdown .bmd-item[style*="display:none"],
  .planilla-tools-dropdown .bmd-item[style*="display: none"] {
    display: none !important;
  }

  .budget-more-dropdown .bmd-sep,
  .planilla-tools-dropdown .bmd-sep {
    margin: 6px 4px !important;
  }

  /* Menú Más organizado por secciones */
  .os-mobile-more-sheet {
    display: flex !important;
    flex-direction: column;
    gap: 12px !important;
  }

  .os-mm-hdr strong {
    font-size: 0.96rem !important;
  }

  .os-mm-search-btn {
    min-height: 42px !important;
    border-radius: 11px !important;
    font-size: 0.84rem !important;
    background: var(--bg-subtle) !important;
    border-color: var(--border-light) !important;
  }

  .os-mm-section {
    display: flex;
    flex-direction: column;
    gap: 7px;
  }

  .os-mm-section-label {
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-left: 2px;
  }

  .os-mm-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }

  .os-mm-tile {
    min-height: 64px !important;
    padding: 9px 6px !important;
    border-radius: 12px !important;
    background: var(--bg-subtle) !important;
    border: 1px solid var(--border-light) !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    gap: 5px !important;
  }

  .os-mm-currency {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .os-mm-currency .os-cc-curr-btn {
    min-height: 38px !important;
    border-radius: 9px !important;
    font-size: 0.78rem !important;
  }

  .os-mm-prefs-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .os-mm-pref-btn {
    appearance: none;
    min-height: 42px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    text-align: center;
  }

  .os-mm-pref-btn.os-mm-pref-pro {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.42);
    color: #92400e;
  }

  html[data-os-theme="dark"] .os-mm-pref-btn.os-mm-pref-pro {
    color: #fde68a;
  }

  .os-mm-pref-btn.os-mm-pref-pwa {
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.42);
    color: #047857;
  }

  html[data-os-theme="dark"] .os-mm-pref-btn.os-mm-pref-pwa {
    color: #6ee7b7;
  }

  .os-mm-pref-btn.os-mm-pref-danger {
    background: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.35);
    color: #b91c1c;
  }

  html[data-os-theme="dark"] .os-mm-pref-btn.os-mm-pref-danger {
    color: #fca5a5;
  }

  /* Ocultar opciones exclusivas de escritorio en el Centro de Control */
  #osControlCenter #btnOsTileWindows,
  #osControlCenter .os-cc-section:has(.os-wp-picker) {
    display: none !important;
  }

  /* ------------------------------------------------------------------------
     5. PRESUPUESTADOR: TARJETA HERO LIMPIA (SIN RECORTES) + PLANILLA COMPACTA
     ------------------------------------------------------------------------ */
  .os-win-body .active-budget-command-bar,
  .os-win-body .active-budget-command-bar.abcb-minimal {
    padding: 0.78rem 0.85rem !important;
    gap: 0.6rem !important;
    margin-bottom: 0.55rem !important;
    border-radius: 14px !important;
    border-left: 3.5px solid var(--os-accent) !important;
    overflow: visible !important;
  }

  .abcb-top-row {
    gap: 0.55rem !important;
  }

  .abcb-title-group {
    width: 100%;
  }

  .abcb-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
    flex-wrap: wrap;
  }

  .os-win-body .active-budget-command-bar h2 {
    font-size: 1.15rem !important;
    line-height: 1.2 !important;
    margin: 0 !important;
  }

  /* Fila de acciones limpia: 2 botones principales + botón ⋯ (cero duplicados, cero recorte) */
  #btnConvertBudgetToObraTop,
  .abcb-compact-actions #btnPreviewClientDoc,
  .abcb-label-full {
    display: none !important;
  }

  .abcb-label-short {
    display: inline !important;
  }

  /* Evitar colisión de texto con el botón ✕ y ▾ del combobox buscable */
  .searchable-combobox .scb-input {
    padding-left: 2.05rem !important;
    padding-right: 3.9rem !important;
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
  }

  .abcb-compact-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 0.45rem !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .abcb-compact-actions > .btn:not(.budget-more-btn) {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    height: 40px !important;
    padding: 0 0.65rem !important;
    font-size: 0.79rem !important;
    border-radius: 10px !important;
    justify-content: center !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .abcb-compact-actions #btnOpenPropuestaOnlineTop {
    border-color: var(--os-accent) !important;
    color: var(--os-accent) !important;
    background: var(--os-accent-soft) !important;
  }

  .abcb-compact-actions .budget-more-menu-wrap {
    flex: 0 0 42px !important;
  }

  .abcb-compact-actions .budget-more-btn {
    width: 42px !important;
    height: 40px !important;
    border-radius: 10px !important;
  }

  /* Franja KPI compacta: Superficie arriba + Costo/m² y Total lado a lado */
  .abcb-live-strip-clean {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) !important;
    gap: 0.45rem !important;
    padding-top: 0.55rem !important;
  }

  .abcb-live-strip-clean .abcb-m2-widget {
    grid-column: 1 / -1 !important;
    padding: 0.38rem 0.6rem !important;
    border-radius: 10px !important;
  }

  .abcb-live-strip-clean .pc-step-btn {
    min-width: 36px !important;
    min-height: 34px !important;
    border-radius: 8px !important;
    font-size: 0.78rem !important;
  }

  .abcb-live-strip-clean .abcb-kpi-box {
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: center !important;
    gap: 0.14rem !important;
    padding: 0.48rem 0.62rem !important;
    border-radius: 10px !important;
    min-width: 0 !important;
  }

  .abcb-live-strip-clean .abcb-kpi-box .abcb-widget-label {
    font-size: 0.6rem !important;
    letter-spacing: 0.06em !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .abcb-live-strip-clean .abcb-kpi-box .abcb-kpi-val {
    font-size: clamp(0.82rem, 3.6vw, 0.94rem) !important;
    margin-left: 0 !important;
    text-align: left !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .abcb-live-strip-clean .abcb-kpi-box.abcb-kpi-total {
    padding: 0.48rem 0.65rem !important;
  }

  .abcb-live-strip-clean .abcb-kpi-box.abcb-kpi-total .abcb-kpi-val {
    font-size: clamp(0.86rem, 3.9vw, 1rem) !important;
    color: #ffffff !important;
  }

  /* 3 Pestañas (Planilla | Cronograma | Entregables) equitativas */
  .os-win-body .budget-workflow-nav.bwn-minimal {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0 !important;
    padding: 0 !important;
    margin-bottom: 0.6rem !important;
  }

  .os-win-body .budget-workflow-nav.bwn-minimal .bwn-tab {
    width: 100% !important;
    text-align: center !important;
    padding: 0.58rem 0.25rem !important;
    font-size: 0.84rem !important;
  }

  /* Bloque Proyecto ultra-compacto */
  .os-win-body .project-details-accordion.pda-compact {
    margin-bottom: 0.55rem !important;
    border-radius: 11px !important;
  }

  .pda-summary-compact {
    padding: 0.58rem 0.75rem !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 0.55rem !important;
  }

  .pda-summary-compact .pda-summary-left {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.1rem !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  .pda-compact-summary {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    white-space: normal !important;
    font-size: 0.78rem !important;
    line-height: 1.32 !important;
  }

  .pda-compact-link {
    font-size: 0.72rem !important;
    padding: 0.3rem 0.55rem !important;
    border-radius: 8px !important;
    background: var(--os-accent-soft) !important;
    white-space: nowrap !important;
  }

  .pda-body .form-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .pda-body .form-group.span-2 {
    grid-column: span 1 !important;
  }

  .logo-upload-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.55rem !important;
  }

  .logo-upload-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
  }

  .logo-upload-actions > * {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Barra colapsable "Agregar rubro" en móvil (ahorra ~170px antes de la planilla) */
  #budgetAddBar.budget-add-bar {
    padding: 0.55rem 0.65rem !important;
    margin-bottom: 0.6rem !important;
    border-radius: 11px !important;
    gap: 0.55rem !important;
  }

  #budgetAddBar .bab-mobile-launcher {
    display: flex !important;
    align-items: center !important;
    gap: 0.42rem !important;
    width: 100% !important;
  }

  #budgetAddBar .bab-mobile-toggle {
    flex: 1.25 1 0 !important;
    height: 38px !important;
    border-radius: 9px !important;
    font-size: 0.79rem !important;
    justify-content: center !important;
    padding: 0 0.6rem !important;
  }

  #budgetAddBar #btnMobQuickBulkProxy {
    flex: 1 1 0 !important;
    height: 38px !important;
    border-radius: 9px !important;
    font-size: 0.77rem !important;
    justify-content: center !important;
    padding: 0 0.55rem !important;
  }

  #budgetAddBar .bab-mobile-tools-btn {
    flex: 0 0 38px !important;
    width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    border-radius: 9px !important;
    font-size: 1.05rem !important;
    display: inline-grid !important;
    place-items: center !important;
  }

  #budgetAddBar:not(.is-mobile-expanded) .bab-primary-row {
    display: none !important;
  }

  /* Mantener el contenedor visible con altura 0 para no ocultar el Bottom Sheet #planillaToolsDropdown */
  #budgetAddBar:not(.is-mobile-expanded) .bab-custom-actions {
    display: block !important;
    height: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    overflow: visible !important;
  }

  #budgetAddBar:not(.is-mobile-expanded) .bab-custom-actions > .btn,
  #budgetAddBar:not(.is-mobile-expanded) #btnPlanillaToolsMenu {
    display: none !important;
  }

  #budgetAddBar.is-mobile-expanded .bab-primary-row {
    padding-top: 0.45rem;
    border-top: 1px solid var(--border-light);
  }

  #budgetAddBar.is-mobile-expanded .bab-custom-actions {
    display: flex !important;
    padding-top: 0.4rem !important;
    border-top: 1px solid var(--border-light) !important;
  }

  /* En móvil los proxies del launcher ya lanzan Carga múltiple y Herramientas */
  #budgetAddBar.is-mobile-expanded #btnOpenQuickBulkRubros,
  #budgetAddBar.is-mobile-expanded #btnPlanillaToolsMenu {
    display: none !important;
  }

  #budgetAddBar.is-mobile-expanded #btnNewCustomApuItem {
    width: 100% !important;
    min-height: 38px !important;
    border-radius: 9px !important;
    font-size: 0.8rem !important;
  }

  /* Encabezado y filtros de la Planilla */
  #budgetViewModeHint {
    display: none !important;
  }

  .budget-table-card .card-section-header-clean {
    padding: 0.65rem 0.75rem !important;
    gap: 0.5rem !important;
  }

  .budget-table-filter-bar {
    padding: 0.55rem 0.65rem !important;
    gap: 0.45rem !important;
  }

  .btf-search-wrap,
  .btf-chapter-select {
    flex: 1 1 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .btf-btn-group {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100% !important;
    gap: 0.35rem !important;
    padding: 2px 0 !important;
  }

  .btf-btn-group::-webkit-scrollbar {
    display: none;
  }

  .btf-btn {
    flex: 0 0 auto !important;
    min-height: 34px !important;
    padding: 0.35rem 0.65rem !important;
    font-size: 0.74rem !important;
    border-radius: 8px !important;
  }

  .btf-summary {
    margin-left: 0 !important;
    width: 100% !important;
    font-size: 0.72rem !important;
  }

  /* Filas de capítulo y tarjetas de rubros en Planilla */
  #tablePresupuesto tbody tr.chapter-row td {
    padding: 0.55rem 0.65rem !important;
  }

  .chapter-row-right {
    gap: 0.35rem !important;
  }

  .budget-indirects-card .indirects-grid {
    grid-template-columns: 1fr !important;
    gap: 0.65rem !important;
  }

  .btc-footer-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.42rem !important;
  }

  .btc-footer-actions #btnEmitPDFBottom {
    grid-column: 1 / -1 !important;
    min-height: 42px !important;
  }

  .btc-footer-actions .btn {
    min-height: 38px !important;
    border-radius: 9px !important;
  }

  /* ------------------------------------------------------------------------
     6. PANTALLAS SECUNDARIAS ULTRA-COMPACTAS (OBRAS, COMPRAS, CATÁLOGOS, PROV.)
     ------------------------------------------------------------------------ */
  .os-win-body .editorial-banner.section-header-clean {
    padding: 0.68rem 0.8rem !important;
    margin-bottom: 0.6rem !important;
    border-radius: 12px !important;
    gap: 0.55rem !important;
  }

  .os-win-body .editorial-banner.section-header-clean .eb-desc {
    display: none !important;
  }

  .os-win-body .editorial-banner.section-header-clean h2 {
    font-size: 1.12rem !important;
    line-height: 1.2 !important;
  }

  .os-win-body .editorial-banner.section-header-clean .eb-right {
    width: 100%;
  }

  .quick-actions-clean {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.4rem !important;
    width: 100% !important;
  }

  .quick-actions-clean .btn {
    width: 100% !important;
    min-height: 38px !important;
    height: auto !important;
    padding: 0.42rem 0.5rem !important;
    font-size: 0.76rem !important;
    justify-content: center !important;
    border-radius: 9px !important;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* --- CONTROL DE OBRAS (#tab-obras) --- */
  .obras-app-root {
    padding: 0.05rem 0 1.4rem !important;
    gap: 0.7rem !important;
  }

  .obras-topbar {
    padding: 0.65rem 0.7rem !important;
    gap: 0.5rem !important;
    border-radius: 12px !important;
  }

  .obras-topbar-left {
    flex: 1 1 100% !important;
    gap: 0.45rem !important;
  }

  .obras-selector-wrap {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }

  .obras-select {
    max-width: none !important;
    width: 100% !important;
    height: 42px !important;
    min-height: 42px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .obras-topbar-left > .btn,
  .obras-topbar-right > .obras-google-pill {
    flex: 1 1 auto !important;
    min-height: 36px !important;
    justify-content: center !important;
  }

  .obras-topbar-right {
    width: 100% !important;
    gap: 0.45rem !important;
  }

  .obras-topbar-right .obras-tier-pill {
    display: none !important;
  }

  .obras-demo-banner {
    padding: 0.6rem 0.75rem !important;
    font-size: 0.78rem !important;
    gap: 0.5rem !important;
  }

  .obras-demo-banner .btn {
    width: 100% !important;
    min-height: 36px !important;
    justify-content: center !important;
  }

  .obras-hero-card {
    padding: 0.85rem 0.9rem !important;
    gap: 0.75rem !important;
    border-radius: 14px !important;
  }

  .obras-hero-info {
    width: 100%;
    min-width: 0;
  }

  .obras-hero-info h2 {
    font-size: 1.08rem !important;
    line-height: 1.25 !important;
  }

  .obras-hero-meta {
    gap: 0.35rem 0.65rem !important;
    font-size: 0.75rem !important;
  }

  .obras-health-pill {
    margin-left: 0.25rem !important;
    margin-top: 0.25rem !important;
  }

  .obras-hero-right-cluster {
    width: 100% !important;
    gap: 0.7rem !important;
    align-items: center !important;
  }

  .obras-hero-progress {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .obras-hero-pct-val {
    font-size: 1.3rem !important;
  }

  .obras-quick-strip,
  .obras-subnav {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    padding: 0.4rem 0.5rem !important;
    border-radius: 11px !important;
  }

  .obras-quick-strip::-webkit-scrollbar,
  .obras-subnav::-webkit-scrollbar {
    display: none;
  }

  .obras-qa-btn,
  .obras-subtab-btn {
    scroll-snap-align: start;
    min-height: 36px !important;
    font-size: 0.78rem !important;
  }

  .obras-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  .obras-kpi-card {
    padding: 0.7rem 0.75rem !important;
    min-width: 0 !important;
  }

  .obras-kpi-value {
    font-size: clamp(0.95rem, 4vw, 1.12rem) !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .obras-two-col,
  .obras-portfolio-grid,
  .obras-form-grid,
  .obras-switch-list {
    grid-template-columns: 1fr !important;
    gap: 0.7rem !important;
  }

  .obras-panel {
    padding: 0.8rem 0.85rem !important;
    border-radius: 12px !important;
  }

  .obras-cap-bar-row {
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }

  .obras-photo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.55rem !important;
  }

  .obras-link-box {
    flex-wrap: wrap !important;
  }

  .obras-link-input {
    flex: 1 1 100% !important;
    padding: 0.25rem 0;
  }

  /* --- COMPRAS (#tab-listados) --- */
  .kpi-strip.kpi-strip-slim {
    gap: 0.45rem !important;
    margin-bottom: 0.6rem !important;
  }

  .kpi-strip.kpi-strip-slim .kpi-box {
    padding: 0.58rem 0.68rem !important;
    border-radius: 10px !important;
  }

  .kpi-strip.kpi-strip-slim .kpi-value {
    font-size: clamp(0.88rem, 3.8vw, 1.02rem) !important;
  }

  .explosion-order-bar {
    padding: 0.55rem 0.65rem !important;
    gap: 0.45rem !important;
  }

  .explosion-order-bar select {
    flex: 1 1 100% !important;
    max-width: none !important;
  }

  .explosion-order-count {
    width: 100%;
    margin-right: 0 !important;
  }

  .explosion-order-bar .btn {
    flex: 1 1 0 !important;
    min-height: 36px !important;
    justify-content: center !important;
    border-radius: 8px !important;
  }

  /* --- CATÁLOGOS (APU, MATERIALES, MANO DE OBRA) Y PROVEEDORES --- */
  .os-win-body .filter-bar.filter-bar-clean {
    display: flex !important;
    flex-wrap: wrap !important;
    padding: 0.55rem 0.65rem !important;
    gap: 0.45rem !important;
    border-radius: 11px !important;
  }

  .filter-bar-clean .search-input-wrap,
  .filter-bar-clean .filter-select-wrap {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .category-pills.category-pills-scroll {
    scrollbar-width: none;
    padding: 0.1rem 0 0.35rem !important;
  }

  .category-pills.category-pills-scroll::-webkit-scrollbar {
    display: none;
  }

  .category-pills.category-pills-scroll .cat-pill,
  .category-pills.category-pills-scroll .category-pill {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.8rem !important;
  }

  .quote-dispatch-layout {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  .quote-dispatch-card .form-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .quote-dispatch-card .form-group.span-2 {
    grid-column: span 1 !important;
  }

  /* ------------------------------------------------------------------------
     7. FIX MODO OSCURO EN TARJETAS DE TABLAS MÓVILES Y PILLS
     ------------------------------------------------------------------------ */
  #tablePresupuesto tbody tr.budget-item-row,
  #tableMateriales tbody tr,
  #tableManoObra tbody tr,
  #tableExplosionMateriales tbody tr,
  #tableExplosionManoObra tbody tr,
  #tableProjectGantt tbody tr,
  #adm-precios .tech-table tbody tr,
  #adm-rubros .tech-table tbody tr,
  #adm-proveedores .tech-table tbody tr,
  #adm-suscriptores .tech-table tbody tr,
  #modalQuickBulkRubros .tech-table tbody tr,
  #modalBlueprintAnalyzer .tech-table tbody tr,
  #modalPdfComputoImport .tech-table tbody tr,
  #modalRubroComposer .tech-table tbody tr,
  #mrdBody .tech-table tbody tr {
    background: var(--bg-surface) !important;
    border-color: var(--border-light) !important;
    color: var(--text-primary) !important;
    border-radius: 11px !important;
  }

  html[data-os-theme="dark"] #tableExplosionMateriales tbody td:nth-child(6),
  html[data-os-theme="dark"] #tableExplosionManoObra tbody td:nth-child(5) {
    background: rgba(59, 130, 246, 0.18) !important;
    border-color: rgba(96, 165, 250, 0.35) !important;
    color: #dbeafe !important;
  }

  html[data-os-theme="dark"] .tech-dialog[open]:not(#modalAdminPin) .dialog-footer,
  html[data-os-theme="dark"] #modalConstructionContract .contract-editor-tabs-bar {
    background: var(--bg-subtle) !important;
    border-color: var(--border-light) !important;
  }

  /* ------------------------------------------------------------------------
     8. MODALES HÍBRIDOS NATIVOS: BOTTOM SHEET (RÁPIDOS) vs 100dvh (COMPLEJOS)
     ------------------------------------------------------------------------ */
  /* 8A. Bottom Sheets para modales rápidos y medianos */
  #modalBudgetGlobalAdjust[open],
  #modalSiteCalculator[open],
  #obrasModalDialog[open],
  #modalConfirmAction[open],
  #modalPromptValue[open],
  #modalNewCategory[open],
  #modalInsumoForm[open],
  #modalAdminRecordPayment[open],
  #modalSubscriberCredentials[open],
  #modalSmartWelcome[open] {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto !important;
    max-height: 90dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    border: 1px solid var(--border-light) !important;
    border-bottom: none !important;
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    box-shadow: 0 -16px 48px rgba(2, 6, 23, 0.36) !important;
    animation: mobSheetUp 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  #modalBudgetGlobalAdjust[open] .obras-dialog-hdr,
  #modalSiteCalculator[open] .obras-dialog-hdr,
  #obrasModalDialog[open] .obras-dialog-hdr {
    flex-shrink: 0;
    padding: 0.85rem 1rem !important;
    gap: 0.5rem;
  }

  #modalBudgetGlobalAdjust[open] .obras-dialog-body,
  #modalSiteCalculator[open] .obras-dialog-body,
  #obrasModalDialog[open] .obras-dialog-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 1rem calc(1.1rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  #modalSmartWelcome[open] .sw-shell {
    display: flex;
    flex-direction: column;
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #modalSmartWelcome[open] .sw-hero {
    padding: 1.1rem 1.15rem 0.95rem !important;
  }

  #modalSmartWelcome[open] .sw-hero h2 {
    font-size: 1.2rem !important;
  }

  #modalSmartWelcome[open] .sw-cards {
    padding: 0.85rem 1rem !important;
    gap: 0.5rem !important;
  }

  #modalSmartWelcome[open] .sw-card {
    padding: 0.72rem 0.8rem !important;
    gap: 0.7rem !important;
  }

  #modalSmartWelcome[open] .sw-footer {
    padding: 0.7rem 1rem calc(0.9rem + env(safe-area-inset-bottom, 0px)) !important;
    justify-content: center !important;
    gap: 0.65rem !important;
  }

  /* 8B. Pantalla completa 100dvh para flujos complejos (incluyendo .obras-dialog complejos) */
  #modalPropuestasInteractivas[open],
  #modalBudgetComparator[open] {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  #modalPropuestasInteractivas[open] .obras-dialog-hdr,
  #modalBudgetComparator[open] .obras-dialog-hdr {
    flex-shrink: 0;
    padding: calc(0.7rem + env(safe-area-inset-top, 0px)) 0.9rem 0.7rem !important;
    gap: 0.5rem;
  }

  #modalPropuestasInteractivas[open] .obras-dialog-body,
  #modalBudgetComparator[open] .obras-dialog-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 0.9rem calc(1.2rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Safe-area en header y footer de .tech-dialog fullscreen */
  .tech-dialog[open]:not(#modalAdminPin):not(#modalConfirmAction):not(#modalPromptValue):not(#modalNewCategory):not(#modalInsumoForm):not(#modalAdminRecordPayment):not(#modalSubscriberCredentials) .dialog-header {
    padding-top: calc(0.65rem + env(safe-area-inset-top, 0px)) !important;
  }

  .tech-dialog[open] .dialog-footer .btn {
    flex: 1 1 auto;
    min-height: 40px;
    justify-content: center;
  }

  /* Formularios dentro de modales en 1 sola columna */
  dialog .form-grid-2 {
    grid-template-columns: 1fr !important;
  }

  dialog .form-group.span-2 {
    grid-column: span 1 !important;
  }

  /* Toast encima de la barra inferior nueva */
  .toast-container {
    bottom: calc(var(--os-mobile-tb-h) + 10px) !important;
    left: 10px !important;
    right: 10px !important;
    z-index: 650 !important;
  }

  /* ------------------------------------------------------------------------
     9. SELECTOR DE OBRA EN COMPRAS Y EXPLORADOR DE ARCHIVOS EN MÓVIL
     ------------------------------------------------------------------------ */
  .os-mm-tile.os-mm-tile-folder {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.34) !important;
  }

  .explosion-source-bar {
    padding: 0.68rem 0.75rem !important;
    margin-bottom: 0.6rem !important;
    border-radius: 12px !important;
    gap: 0.5rem !important;
  }

  .esb-main-row {
    gap: 0.5rem !important;
  }

  .esb-select-group,
  .esb-mode-group {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  .esb-mode-switch {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
  }

  .esb-mode-btn {
    min-height: 36px !important;
    text-align: center !important;
    justify-content: center !important;
    font-size: 0.76rem !important;
    padding: 0.35rem 0.4rem !important;
  }

  .esb-meta-row {
    gap: 0.4rem !important;
  }

  .esb-meta-actions {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .esb-meta-actions .btn {
    flex: 1 1 auto !important;
    min-height: 34px !important;
    justify-content: center !important;
  }

  .cotizar-source-banner {
    padding: 0.58rem 0.72rem !important;
    margin-bottom: 0.6rem !important;
    font-size: 0.78rem !important;
  }

  .cotizar-source-banner .btn {
    width: 100% !important;
    min-height: 34px !important;
    justify-content: center !important;
  }

  /* Explorador de Archivos Windows 11 adaptado a móvil (1 toque para abrir) */
  .os-win-body.wfe-win-body {
    padding: 0 !important;
  }

  .wfe-toolbar {
    flex-wrap: wrap !important;
    padding: 0.5rem 0.65rem !important;
    gap: 0.42rem !important;
  }

  .wfe-nav-btns {
    order: 1;
  }

  .wfe-address-bar {
    order: 2;
    flex: 1 1 150px !important;
    height: 34px !important;
    padding: 0 0.5rem !important;
  }

  .wfe-search-wrap {
    order: 3;
    flex: 1 1 160px !important;
    min-width: 0 !important;
  }

  .wfe-search-input {
    font-size: 16px !important;
    height: 36px !important;
  }

  .wfe-toolbar-actions {
    order: 4;
    flex-shrink: 0;
  }

  .wfe-new-btn {
    height: 36px !important;
  }

  .wfe-main {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
  }

  .wfe-sidebar {
    border-right: none !important;
    border-bottom: 1px solid var(--border-light) !important;
    padding: 0.45rem 0.6rem !important;
    flex-shrink: 0 !important;
    overflow: visible !important;
  }

  .wfe-sidebar-title {
    display: none !important;
  }

  .wfe-sidebar-list {
    flex-direction: row !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.35rem !important;
  }

  .wfe-sidebar-list::-webkit-scrollbar {
    display: none;
  }

  .wfe-nav-item {
    flex: 0 0 auto !important;
    width: auto !important;
    padding: 0.38rem 0.65rem !important;
    border-radius: 999px !important;
    border: 1px solid var(--border-light) !important;
    background: var(--bg-surface) !important;
    font-size: 0.76rem !important;
    white-space: nowrap !important;
  }

  .wfe-canvas {
    flex: 1 1 auto !important;
    padding: 0.65rem !important;
  }

  .wfe-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.55rem !important;
  }

  .wfe-tile {
    padding: 0.75rem 0.5rem 0.65rem !important;
  }

  .wfe-mob-info-btn {
    display: inline-grid !important;
    place-items: center;
    appearance: none;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
  }

  .wfe-tile-more {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
  }

  .wfe-details-table th:nth-child(2),
  .wfe-details-table td:nth-child(2),
  .wfe-details-table th:nth-child(3),
  .wfe-details-table td:nth-child(3) {
    display: none !important;
  }

  .wfe-col-mob-act {
    display: table-cell !important;
    width: 38px;
    text-align: right;
  }

  .wfe-preview-pane {
    display: none !important;
  }

  .wfe-statusbar {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.7rem !important;
  }

  /* Hoja interna de vista previa y acciones en Explorador móvil */
  .wfe-mob-sheet-backdrop {
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 25 !important;
    background: rgba(2, 6, 23, 0.45);
    backdrop-filter: blur(2px);
  }

  .wfe-mob-preview-sheet {
    display: flex !important;
    flex-direction: column;
    position: absolute !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30 !important;
    max-height: 80%;
    overflow-y: auto;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    border-radius: 18px 18px 0 0;
    padding: 0.85rem 1rem 1.1rem;
    box-shadow: 0 -10px 32px rgba(2, 6, 23, 0.28);
    animation: mobSheetUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .wfe-mob-sheet-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.6rem;
    margin-bottom: 0.65rem;
    border-bottom: 1px solid var(--border-light);
  }

  .wfe-mob-sheet-hdr strong {
    font-size: 0.9rem;
    color: var(--text-primary);
  }
}
