/* ============================================================
   MODO CELULAR (<= 768 px)
   Todo lo que cambia en el teléfono vive acá, separado de app.css
   para no pisar el escritorio. Se carga DESPUÉS de app.css.
   Ayudas: .m-only (solo celular) / .d-only (solo escritorio).
   ============================================================ */

/* Ayudas de visibilidad (por defecto: escritorio) */
.m-only { display: none !important; }
.bottom-nav,
.m-subtabs,
.m-desktop-notice,
.m-edit-strip,
.m-nav-sheet,
.m-nav-sheet-overlay { display: none; }

/* Bloques personalizables (MBlocks/MBlock): en la PC son transparentes, no cambian el layout */
.m-blocks, .m-block, .m-block-desktop { display: contents; }

@media (max-width: 768px) {
  .m-only { display: revert !important; }
  .d-only { display: none !important; }

  /* --- Base --- */
  html { font-size: 14px; }                       /* legible en 390 px */
  body { overflow-x: hidden; }
  .main-wrapper { min-height: 100vh; min-height: 100dvh; }
  .content {
    padding: 0.875rem 0.75rem;
    /* lugar para la barra inferior (+ notch de abajo en iPhone) */
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .content.m-nav-hidden { padding-bottom: 0.875rem; }

  /* --- Topbar compacta: la hamburguesa la reemplaza "Más" en la barra de abajo --- */
  .topbar { padding: 0 0.75rem; }
  .topbar-menu-btn { display: none !important; }
  .platform-switch { gap: 0.4rem; }
  .platform-btn { padding: 3px 8px; }
  .platform-logo-img { height: 18px; }

  /* Sub-pestañas de Atención al cliente (Preventa / Posventa / Reclamos) */
  .m-subtabs {
    display: flex;
    position: sticky;
    top: var(--topbar-height);
    z-index: 45;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    margin: -0.875rem -0.75rem 0.75rem;
  }
  .m-subtab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
  }
  .m-subtab.active { color: var(--primary); border-bottom-color: var(--primary); }
  .m-subtab-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 999px;
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* --- Barra inferior --- */
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--topbar-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 60;
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 58px;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-secondary);
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-item svg { width: 22px; height: 22px; }
  .bottom-nav-item.active { color: var(--primary); }
  .bottom-nav-item.active::before {
    content: "";
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--primary);
  }
  .bottom-nav-badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 4px);
    background: var(--danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--topbar-bg);
    box-sizing: content-box;
  }

  /* El menú lateral (Más) tapa la barra de abajo */
  .sidebar { z-index: 100; height: 100vh; height: 100dvh; }
  .sidebar-overlay { z-index: 90; }

  /* --- Aviso "pensada para la computadora" --- */
  .m-desktop-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    background: var(--info-bg);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 0.7rem 0.8rem;
    margin-bottom: 0.875rem;
    font-size: 0.82rem;
    line-height: 1.35;
  }
  .m-desktop-notice svg { width: 18px; height: 18px; flex: none; color: var(--info); margin-top: 1px; }
  .m-desktop-notice-close {
    margin-left: auto;
    flex: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.2rem;
  }

  /* --- Ajustes generales para el dedo --- */
  .view-header { flex-wrap: wrap; gap: 0.35rem 0.75rem; margin-bottom: 1rem; }
  .view-header h2 { font-size: 1.3rem; }
  select, input[type="text"], input[type="search"], input[type="date"], input[type="number"], textarea {
    font-size: 16px; /* evita el zoom automático de iOS al enfocar */
  }
  /* Tablas que no se rediseñaron: que al menos se puedan correr con el dedo */
  .table-wrap, .table-container, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Modales: casi todo el ancho y que no queden bajo la barra inferior */
  .modal-card, .modal-panel { max-width: calc(100vw - 1.25rem); width: calc(100vw - 1.25rem); max-height: 86vh; max-height: 86dvh; }
  .modal-card { margin: 0.6rem; }
  .modal-card input, .modal-card select, .modal-card textarea,
  .modal-panel input, .modal-panel select, .modal-panel textarea { max-width: 100%; min-width: 0; }

  /* ============================================================
     PERSONALIZACIÓN (lápiz): bloques, tira de edición, editor de la barra
     ============================================================ */
  /* Lápiz en el topbar: gris; verde cuando está personalizando */
  .m-edit-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; margin-left: 0.5rem; border-radius: 9px;
    background: #eef0f3; color: var(--text-secondary); font-size: 14px;
    border: 1px solid transparent; transition: background .2s, color .2s;
  }
  .m-edit-btn.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(16,185,129,.35); }

  /* Tira "Personalizando" (sticky bajo el topbar) */
  .m-edit-strip {
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: var(--topbar-height); z-index: 44;
    margin: -0.875rem -0.75rem 0.75rem; padding: 8px 12px;
    background: #ecfdf5; border-bottom: 1px solid rgba(16,185,129,.35);
    font-size: 0.78rem; color: var(--text-primary);
  }
  .m-subtabs + .m-edit-strip { margin-top: -0.75rem; }
  .m-edit-strip-txt i { color: var(--primary); margin: 0 1px; }
  .m-edit-strip-actions { display: flex; gap: 8px; }
  .m-edit-strip-btn {
    flex: 1; min-height: 40px; border-radius: 9px; font-weight: 600; font-size: 0.85rem;
    background: #fff; border: 1px solid var(--border); color: var(--text-primary);
  }
  .m-edit-strip-btn:disabled { opacity: .45; }
  .m-edit-strip-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }

  /* Bloques */
  .m-blocks { display: flex; flex-direction: column; }
  .m-block { display: block; min-width: 0; }
  .m-block-desktop { display: contents; }
  .m-block-edit { position: relative; margin: 0 0 10px; border: 1.5px dashed rgba(16,185,129,.55); border-radius: 12px; padding: 0 6px 6px; background: rgba(16,185,129,.03); }
  .m-block-edit > .m-block-body { pointer-events: none; }   /* en modo edición se ordena/oculta, no se opera */
  .m-block-hidden { opacity: .55; }
  .m-block-hidden > .m-block-body { display: none; }
  .m-block-bar {
    display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 4px 2px 4px 8px;
    font-size: 0.8rem; font-weight: 600; color: var(--primary-dark);
  }
  .m-block-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-block-btn {
    width: 38px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
    background: #fff; border: 1px solid var(--border); color: var(--text-secondary); font-size: 13px;
  }
  .m-block-btn:disabled { opacity: .35; }
  .m-block-eye.on { color: var(--primary); border-color: rgba(16,185,129,.5); }
  .m-block-lock { opacity: .5; }

  /* Barra de abajo en modo edición */
  .bottom-nav.editing { outline: 2px dashed rgba(16,185,129,.55); outline-offset: -2px; }
  .bottom-nav-edit-hint {
    position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
    background: var(--primary); color: #fff; font-size: 0.72rem; font-weight: 600;
    padding: 4px 10px; border-radius: 999px; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.15);
    pointer-events: none;
  }

  /* Editor de la barra de abajo (hoja desde abajo) */
  .m-nav-sheet-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 70; }
  .m-nav-sheet {
    display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
    background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
    max-height: calc(var(--app-vh, 1vh) * 100 - 80px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .m-nav-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-weight: 700; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
  .m-nav-sheet-close { width: 36px; height: 36px; font-size: 1.4rem; color: var(--text-secondary); }
  .m-nav-sheet-list { overflow-y: auto; padding: 4px 6px; }
  .m-nav-sheet-row { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 6px; border-bottom: 1px solid #f1f3f5; }
  .m-nav-sheet-row.on .m-nav-sheet-label { color: var(--text-primary); font-weight: 600; }
  .m-nav-sheet-check { width: 40px; height: 40px; font-size: 1.2rem; color: var(--text-muted); }
  .m-nav-sheet-row.on .m-nav-sheet-check { color: var(--primary); }
  .m-nav-sheet-check:disabled { opacity: .35; }
  .m-nav-sheet-ico { width: 24px; display: inline-flex; color: var(--text-secondary); }
  .m-nav-sheet-ico svg { width: 20px; height: 20px; }
  .m-nav-sheet-label { flex: 1; font-size: 0.9rem; color: var(--text-secondary); }
  .m-nav-sheet-arrow { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text-secondary); }
  .m-nav-sheet-arrow:disabled { opacity: .3; }
  .m-nav-sheet-foot { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
}
